Trouble using the Conversational Agent: Missing some input keys: {'input'} and Agent.plan() got multiple values for argument 'intermediate_steps'
Labels: name: area: memory, name: area: agent, name: auto:bug, name: auto:question

### Issue you'd like to raise.

Im trying to use an agent as a router for two retrievals. I also want it to have memory so im using the conversational agent with two RetrievalQA chains and ConversationBufferWindowMemory.

Heres the code after creating the retrievals and chatTemplates:

```
chat = ChatVertexAI(
    model_name = "chat-bison-32k",
    temperature = 0.5,
    top_p = 0.8,
    top_k = 40,
    max_output_tokens = 300
)

prompt1 = PromptTemplate(
    input_variables=["context", "input"],
    template=chatTemplate1
)
chain_type_kwargs1 = {"prompt": prompt1}

prompt2 = PromptTemplate(
    input_variables=["context", "input"],
    template=chatTemplate2
)
chain_type_kwargs2 = {"prompt": prompt2}

faq = RetrievalQA.from_chain_type(
    llm = llm,
    retriever = chroma_retriever,
    chain_type="stuff",
    chain_type_kwargs=chain_type_kwargs1
)

complex_products = RetrievalQA.from_chain_type(
    llm = llm,
    retriever = ensemble_retriever,
    chain_type="stuff",
    chain_type_kwargs=chain_type_kwargs2
)

tools = [
    Tool(
        name="FAQ about the store",
        func= faq.run,
        description="useful for when you need to answer questions about related to  frequently asked questions. This tool provides information on business hours and store location. To use, input a well-formulated question.",
    ),

    Tool(
        name="Product information",
        func=complex_products.run,
        description="useful for when you need to answer questions about certain products that the costumer needs. Input should be a fully formed question.",
    ),
]

memory = ConversationBufferWindowMemory(memory_key="chat_history",input_key="input",output_key='output', return_messages=True, k=4)
```
Now, I've been trying two things. The first one is to call my agent with the memory directly. I tried it with and without using .run():

```
agent = initialize_agent(
    tools = tools,
    llm = chat,
    agent = AgentType.CONVERSATIONAL_REACT_DESCRIPTION,
    verbose=True,
    handle_parsing_errors=True,
    max_iterations = 3, 
    early_stopping_method = 'generate',
    memory = memory
    
)

result = agent("What are the closing hours?")
result["output"]

```
but with some questions, not all, i get the following error:

```
> Entering new AgentExecutor chain...
 Thought: Do I need to use a tool? Yes
Action: FAQ about the store
Action Input: What are the closing hours?
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[45], line 1
----> 1 result = agent("What are the closing hours?")
      2 result["output"]

File /opt/conda/lib/python3.10/site-packages/langchain/chains/base.py:310, in Chain.__call__(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)
    308 except BaseException as e:
    309     run_manager.on_chain_error(e)
--> 310     raise e
    311 run_manager.on_chain_end(outputs)
    312 final_outputs: Dict[str, Any] = self.prep_outputs(
    313     inputs, outputs, return_only_outputs
    314 )

File /opt/conda/lib/python3.10/site-packages/langchain/chains/base.py:304, in Chain.__call__(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)
    297 run_manager = callback_manager.on_chain_start(
    298     dumpd(self),
    299     inputs,
    300     name=run_name,
    301 )
    302 try:
    303     outputs = (
--> 304         self._call(inputs, run_manager=run_manager)
    305         if new_arg_supported
    306         else self._call(inputs)
    307     )
    308 except BaseException as e:
    309     run_manager.on_chain_error(e)

File /opt/conda/lib/python3.10/site-packages/langchain/agents/agent.py:1146, in AgentExecutor._call(self, inputs, run_manager)
   1144 # We now enter the agent loop (until it returns something).
   1145 while self._should_continue(iterations, time_elapsed):
-> 1146     next_step_output = self._take_next_step(
   1147         name_to_tool_map,
   1148         color_mapping,
   1149         inputs,
   1150         intermediate_steps,
   1151         run_manager=run_manager,
   1152     )
   1153     if isinstance(next_step_output, AgentFinish):
   1154         return self._return(
   1155             next_step_output, intermediate_steps, run_manager=run_manager
   1156         )

File /opt/conda/lib/python3.10/site-packages/langchain/agents/agent.py:996, in AgentExecutor._take_next_step(self, name_to_tool_map, color_mapping, inputs, intermediate_steps, run_manager)
    994         tool_run_kwargs["llm_prefix"] = ""
    995     # We then call the tool on the tool input to get an observation
--> 996     observation = tool.run(
    997         agent_action.tool_input,
    998         verbose=self.verbose,
    999         color=color,
   1000         callbacks=run_manager.get_child() if run_manager else None,
   1001         **tool_run_kwargs,
   1002     )
   1003 else:
   1004     tool_run_kwargs = self.agent.tool_run_logging_kwargs()

File /opt/conda/lib/python3.10/site-packages/langchain/tools/base.py:365, in BaseTool.run(self, tool_input, verbose, start_color, color, callbacks, tags, metadata, run_name, **kwargs)
    363 except (Exception, KeyboardInterrupt) as e:
    364     run_manager.on_tool_error(e)
--> 365     raise e
    366 else:
    367     run_manager.on_tool_end(
    368         str(observation), color=color, name=self.name, **kwargs
    369     )

File /opt/conda/lib/python3.10/site-packages/langchain/tools/base.py:337, in BaseTool.run(self, tool_input, verbose, start_color, color, callbacks, tags, metadata, run_name, **kwargs)
    334 try:
    335     tool_args, tool_kwargs = self._to_args_and_kwargs(parsed_input)
    336     observation = (
--> 337         self._run(*tool_args, run_manager=run_manager, **tool_kwargs)
    338         if new_arg_supported
    339         else self._run(*tool_args, **tool_kwargs)
    340     )
    341 except ToolException as e:
    342     if not self.handle_tool_error:

File /opt/conda/lib/python3.10/site-packages/langchain/tools/base.py:510, in Tool._run(self, run_manager, *args, **kwargs)
    507 if self.func:
    508     new_argument_supported = signature(self.func).parameters.get("callbacks")
    509     return (
--> 510         self.func(
    511             *args,
    512             callbacks=run_manager.get_child() if run_manager else None,
    513             **kwargs,
    514         )
    515         if new_argument_supported
    516         else self.func(*args, **kwargs)
    517     )
    518 raise NotImplementedError("Tool does not support sync")

File /opt/conda/lib/python3.10/site-packages/langchain/chains/base.py:505, in Chain.run(self, callbacks, tags, metadata, *args, **kwargs)
    503     if len(args) != 1:
    504         raise ValueError("`run` supports only one positional argument.")
--> 505     return self(args[0], callbacks=callbacks, tags=tags, metadata=metadata)[
    506         _output_key
    507     ]
    509 if kwargs and not args:
    510     return self(kwargs, callbacks=callbacks, tags=tags, metadata=metadata)[
    511         _output_key
    512     ]

File /opt/conda/lib/python3.10/site-packages/langchain/chains/base.py:310, in Chain.__call__(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)
    308 except BaseException as e:
    309     run_manager.on_chain_error(e)
--> 310     raise e
    311 run_manager.on_chain_end(outputs)
    312 final_outputs: Dict[str, Any] = self.prep_outputs(
    313     inputs, outputs, return_only_outputs
    314 )

File /opt/conda/lib/python3.10/site-packages/langchain/chains/base.py:304, in Chain.__call__(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)
    297 run_manager = callback_manager.on_chain_start(
    298     dumpd(self),
    299     inputs,
    300     name=run_name,
    301 )
    302 try:
    303     outputs = (
--> 304         self._call(inputs, run_manager=run_manager)
    305         if new_arg_supported
    306         else self._call(inputs)
    307     )
    308 except BaseException as e:
    309     run_manager.on_chain_error(e)

File /opt/conda/lib/python3.10/site-packages/langchain/chains/retrieval_qa/base.py:139, in BaseRetrievalQA._call(self, inputs, run_manager)
    137 else:
    138     docs = self._get_docs(question)  # type: ignore[call-arg]
--> 139 answer = self.combine_documents_chain.run(
    140     input_documents=docs, question=question, callbacks=_run_manager.get_child()
    141 )
    143 if self.return_source_documents:
    144     return {self.output_key: answer, "source_documents": docs}

File /opt/conda/lib/python3.10/site-packages/langchain/chains/base.py:510, in Chain.run(self, callbacks, tags, metadata, *args, **kwargs)
    505     return self(args[0], callbacks=callbacks, tags=tags, metadata=metadata)[
    506         _output_key
    507     ]
    509 if kwargs and not args:
--> 510     return self(kwargs, callbacks=callbacks, tags=tags, metadata=metadata)[
    511         _output_key
    512     ]
    514 if not kwargs and not args:
    515     raise ValueError(
    516         "`run` supported with either positional arguments or keyword arguments,"
    517         " but none were provided."
    518     )

File /opt/conda/lib/python3.10/site-packages/langchain/chains/base.py:286, in Chain.__call__(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)
    250 def __call__(
    251     self,
    252     inputs: Union[Dict[str, Any], Any],
   (...)
    259     include_run_info: bool = False,
    260 ) -> Dict[str, Any]:
    261     """Execute the chain.
    262 
    263     Args:
   (...)
    284             `Chain.output_keys`.
    285     """
--> 286     inputs = self.prep_inputs(inputs)
    287     callback_manager = CallbackManager.configure(
    288         callbacks,
    289         self.callbacks,
   (...)
    294         self.metadata,
    295     )
    296     new_arg_supported = inspect.signature(self._call).parameters.get("run_manager")

File /opt/conda/lib/python3.10/site-packages/langchain/chains/base.py:443, in Chain.prep_inputs(self, inputs)
    441     external_context = self.memory.load_memory_variables(inputs)
    442     inputs = dict(inputs, **external_context)
--> 443 self._validate_inputs(inputs)
    444 return inputs

File /opt/conda/lib/python3.10/site-packages/langchain/chains/base.py:195, in Chain._validate_inputs(self, inputs)
    193 missing_keys = set(self.input_keys).difference(inputs)
    194 if missing_keys:
--> 195     raise ValueError(f"Missing some input keys: {missing_keys}")

ValueError: Missing some input keys: {'input'}
```
I also tried calling the agent like this:

```
chat_history = []
question = "What are the closing hours?"
agent({"input": question, "chat_history": chat_history})
```

and got the same error.

I tried to use an agent executor, moving the memory from the agent to the executor but I get the following error:

```
agent_executor = AgentExecutor(agent=agent,
                               tools=tools,
                               memory=memory,
                               verbose=True)

agent_executor.invoke({"input": "What are the closing hours?"})['output']

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[61], line 1
----> 1 agent_executor.invoke({"input": "What are the closing hours?"})['output']

File /opt/conda/lib/python3.10/site-packages/langchain/chains/base.py:87, in Chain.invoke(self, input, config, **kwargs)
     80 def invoke(
     81     self,
     82     input: Dict[str, Any],
     83     config: Optional[RunnableConfig] = None,
     84     **kwargs: Any,
     85 ) -> Dict[str, Any]:
     86     config = config or {}
---> 87     return self(
     88         input,
     89         callbacks=config.get("callbacks"),
     90         tags=config.get("tags"),
     91         metadata=config.get("metadata"),
     92         run_name=config.get("run_name"),
     93         **kwargs,
     94     )

File /opt/conda/lib/python3.10/site-packages/langchain/chains/base.py:310, in Chain.__call__(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)
    308 except BaseException as e:
    309     run_manager.on_chain_error(e)
--> 310     raise e
    311 run_manager.on_chain_end(outputs)
    312 final_outputs: Dict[str, Any] = self.prep_outputs(
    313     inputs, outputs, return_only_outputs
    314 )

File /opt/conda/lib/python3.10/site-packages/langchain/chains/base.py:304, in Chain.__call__(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)
    297 run_manager = callback_manager.on_chain_start(
    298     dumpd(self),
    299     inputs,
    300     name=run_name,
    301 )
    302 try:
    303     outputs = (
--> 304         self._call(inputs, run_manager=run_manager)
    305         if new_arg_supported
    306         else self._call(inputs)
    307     )
    308 except BaseException as e:
    309     run_manager.on_chain_error(e)

File /opt/conda/lib/python3.10/site-packages/langchain/agents/agent.py:1146, in AgentExecutor._call(self, inputs, run_manager)
   1144 # We now enter the agent loop (until it returns something).
   1145 while self._should_continue(iterations, time_elapsed):
-> 1146     next_step_output = self._take_next_step(
   1147         name_to_tool_map,
   1148         color_mapping,
   1149         inputs,
   1150         intermediate_steps,
   1151         run_manager=run_manager,
   1152     )
   1153     if isinstance(next_step_output, AgentFinish):
   1154         return self._return(
   1155             next_step_output, intermediate_steps, run_manager=run_manager
   1156         )

File /opt/conda/lib/python3.10/site-packages/langchain/agents/agent.py:933, in AgentExecutor._take_next_step(self, name_to_tool_map, color_mapping, inputs, intermediate_steps, run_manager)
    930     intermediate_steps = self._prepare_intermediate_steps(intermediate_steps)
    932     # Call the LLM to see what to do.
--> 933     output = self.agent.plan(
    934         intermediate_steps,
    935         callbacks=run_manager.get_child() if run_manager else None,
    936         **inputs,
    937     )
    938 except OutputParserException as e:
    939     if isinstance(self.handle_parsing_errors, bool):

File /opt/conda/lib/python3.10/site-packages/langchain/agents/agent.py:375, in RunnableAgent.plan(self, intermediate_steps, callbacks, **kwargs)
    363 """Given input, decided what to do.
    364 
    365 Args:
   (...)
    372     Action specifying what tool to use.
    373 """
    374 inputs = {**kwargs, **{"intermediate_steps": intermediate_steps}}
--> 375 output = self.runnable.invoke(inputs, config={"callbacks": callbacks})
    376 return output

File /opt/conda/lib/python3.10/site-packages/langchain/chains/base.py:87, in Chain.invoke(self, input, config, **kwargs)
     80 def invoke(
     81     self,
     82     input: Dict[str, Any],
     83     config: Optional[RunnableConfig] = None,
     84     **kwargs: Any,
     85 ) -> Dict[str, Any]:
     86     config = config or {}
---> 87     return self(
     88         input,
     89         callbacks=config.get("callbacks"),
     90         tags=config.get("tags"),
     91         metadata=config.get("metadata"),
     92         run_name=config.get("run_name"),
     93         **kwargs,
     94     )

File /opt/conda/lib/python3.10/site-packages/langchain/chains/base.py:310, in Chain.__call__(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)
    308 except BaseException as e:
    309     run_manager.on_chain_error(e)
--> 310     raise e
    311 run_manager.on_chain_end(outputs)
    312 final_outputs: Dict[str, Any] = self.prep_outputs(
    313     inputs, outputs, return_only_outputs
    314 )

File /opt/conda/lib/python3.10/site-packages/langchain/chains/base.py:304, in Chain.__call__(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)
    297 run_manager = callback_manager.on_chain_start(
    298     dumpd(self),
    299     inputs,
    300     name=run_name,
    301 )
    302 try:
    303     outputs = (
--> 304         self._call(inputs, run_manager=run_manager)
    305         if new_arg_supported
    306         else self._call(inputs)
    307     )
    308 except BaseException as e:
    309     run_manager.on_chain_error(e)

File /opt/conda/lib/python3.10/site-packages/langchain/agents/agent.py:1146, in AgentExecutor._call(self, inputs, run_manager)
   1144 # We now enter the agent loop (until it returns something).
   1145 while self._should_continue(iterations, time_elapsed):
-> 1146     next_step_output = self._take_next_step(
   1147         name_to_tool_map,
   1148         color_mapping,
   1149         inputs,
   1150         intermediate_steps,
   1151         run_manager=run_manager,
   1152     )
   1153     if isinstance(next_step_output, AgentFinish):
   1154         return self._return(
   1155             next_step_output, intermediate_steps, run_manager=run_manager
   1156         )

File /opt/conda/lib/python3.10/site-packages/langchain/agents/agent.py:933, in AgentExecutor._take_next_step(self, name_to_tool_map, color_mapping, inputs, intermediate_steps, run_manager)
    930     intermediate_steps = self._prepare_intermediate_steps(intermediate_steps)
    932     # Call the LLM to see what to do.
--> 933     output = self.agent.plan(
    934         intermediate_steps,
    935         callbacks=run_manager.get_child() if run_manager else None,
    936         **inputs,
    937     )
    938 except OutputParserException as e:
    939     if isinstance(self.handle_parsing_errors, bool):

TypeError: Agent.plan() got multiple values for argument 'intermediate_steps'
```
Im not sure what im doing wrong.
@dosu-bot

### Suggestion:

- Maybe using a template for the agent can work? I dont know if its possible, but im also having trouble forcing it to use only the tools to search the info or else answer that it doesnt know.
- Using LCEL to add a parser but im not familiar with LCEL.
- Change the aproach creating a custom tool/agent/chain.