pandas agent not working with langgraph #134

Closed
opened 2026-02-20 17:28:23 -05:00 by yindo · 3 comments
Owner

Originally created by @azharmajeed-cml on GitHub (Jul 3, 2024).

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangGraph/LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangGraph/LangChain rather than my code.
  • I am sure this is better as an issue rather than a GitHub discussion, since this is a LangGraph bug and not a design question.

Example Code

pandas_agent = create_pandas_dataframe_agent(
    llm,
    df,
    verbose=True,
    agent_type=AgentType.OPENAI_FUNCTIONS,
    # agent_type="openai-tools",
    allow_dangerous_code=True
)
pandas_node = functools.partial(agent_node, agent=pandas_agent, name="Analyst")


workflow = StateGraph(AgentState)
workflow.add_node("Analyst", pandas_node)

for member in members:
    # We want our workers to ALWAYS "report back" to the supervisor when done
    workflow.add_edge(member, "supervisor")
# The supervisor populates the "next" field in the graph state
# which routes to a node or finishes
conditional_map = {k: k for k in members}
conditional_map["FINISH"] = END
workflow.add_conditional_edges("supervisor", lambda x: x["next"], conditional_map)
# Finally, add entrypoint
workflow.set_entry_point("supervisor")

graph = workflow.compile()

for s in graph.stream(
    {
        "messages": [
            HumanMessage(content="summarize the columns in the dataframe provided to you")
        ]
    }
):
    if "__end__" not in s:
        print(s)
        print("----")

Error Message and Stack Trace (if applicable)

ValueError                                Traceback (most recent call last)
Cell In[63], line 1
----> 1 for s in graph.stream(
      2     {
      3         "messages": [
      4             HumanMessage(content="summarize the columns in the dataframe provided to you")
      5         ]
      6     }
      7 ):
      8     if "__end__" not in s:
      9         print(s)

File c:\Users\AzharMajeed\Documents\.venv\Lib\site-packages\langgraph\pregel\__init__.py:1073, in Pregel.stream(self, input, config, stream_mode, output_keys, input_keys, interrupt_before, interrupt_after, debug)
   1070         del fut, task
   1072 # panic on failure or timeout
-> 1073 _panic_or_proceed(done, inflight, step)
   1074 # don't keep futures around in memory longer than needed
   1075 del done, inflight, futures

File c:\Users\AzharMajeed\Documents\.venv\Lib\site-packages\langgraph\pregel\__init__.py:1643, in _panic_or_proceed(done, inflight, step)
   1641             inflight.pop().cancel()
   1642         # raise the exception
-> 1643         raise exc
   1645 if inflight:
   1646     # if we got here means we timed out
   1647     while inflight:
   1648         # cancel all pending tasks

File ~\.pyenv\pyenv-win\versions\3.11.2\Lib\concurrent\futures\thread.py:58, in _WorkItem.run(self)
     55     return
     57 try:
---> 58     result = self.fn(*self.args, **self.kwargs)
     59 except BaseException as exc:
     60     self.future.set_exception(exc)

File c:\Users\AzharMajeed\Documents\.venv\Lib\site-packages\langgraph\pregel\retry.py:72, in run_with_retry(task, retry_policy)
     70 task.writes.clear()
     71 # run the task
---> 72 task.proc.invoke(task.input, task.config)
     73 # if successful, end
     74 break

File c:\Users\AzharMajeed\Documents\.venv\Lib\site-packages\langchain_core\runnables\base.py:2499, in invoke(self, input, config)
   2497 # invoke all steps in sequence
   2498 try:
-> 2499     for i, step in enumerate(self.steps):
   2500         # mark each step as a child run
   2501         config = patch_config(
   2502             config, callbacks=run_manager.get_child(f"seq:step:{i+1}")
   2503         )
   2504         if i == 0:

File c:\Users\AzharMajeed\Documents\.venv\Lib\site-packages\langgraph\utils.py:95, in RunnableCallable.invoke(self, input, config, **kwargs)
     93     if accepts_config(self.func):
     94         kwargs["config"] = config
---> 95     ret = context.run(self.func, input, **kwargs)
     96 if isinstance(ret, Runnable) and self.recurse:
     97     return ret.invoke(input, config)

Cell In[24], line 2
      1 def agent_node(state, agent, name):
----> 2     result = agent.invoke(state)
      3     return {"messages": [HumanMessage(content=result["output"], name=name)]}

File c:\Users\AzharMajeed\Documents\.venv\Lib\site-packages\langchain\chains\base.py:163, in invoke(self, input, config, **kwargs)
    154     self._validate_inputs(inputs)
    155     outputs = (
    156         self._call(inputs, run_manager=run_manager)
    157         if new_arg_supported
    158         else self._call(inputs)
    159     )
    161     final_outputs: Dict[str, Any] = self.prep_outputs(
    162         inputs, outputs, return_only_outputs
--> 163     )
    164 except BaseException as e:
    165     run_manager.on_chain_error(e)

File c:\Users\AzharMajeed\Documents\.venv\Lib\site-packages\langchain\chains\base.py:151, in invoke(self, input, config, **kwargs)
    136 callback_manager = CallbackManager.configure(
    137     callbacks,
    138     self.callbacks,
   (...)
    143     self.metadata,
    144 )
    145 new_arg_supported = inspect.signature(self._call).parameters.get("run_manager")
    147 run_manager = callback_manager.on_chain_start(
    148     dumpd(self),
    149     inputs,
    150     run_id,
--> 151     name=run_name,
    152 )
    153 try:
    154     self._validate_inputs(inputs)

File c:\Users\AzharMajeed\Documents\.venv\Lib\site-packages\langchain\chains\base.py:279, in _validate_inputs(self, inputs)
    273         _input_keys = _input_keys.difference(self.memory.memory_variables)
    274     if len(_input_keys) != 1:
    275         raise ValueError(
    276             f"A single string input was passed in, but this chain expects "
    277             f"multiple inputs ({_input_keys}). When a chain expects "
    278             f"multiple inputs, please call it by passing in a dictionary, "
--> 279             "eg `chain({'foo': 1, 'bar': 2})`"
    280         )
    282 missing_keys = set(self.input_keys).difference(inputs)
    283 if missing_keys:

ValueError: Missing some input keys: {'input'}

Description

I am trying to add a pandas agent in a mutli agent setup, similar to how it is shown in this notebook. https://github.com/langchainai/langgraph/blob/main/examples/multi_agent/agent_supervisor.ipynb

I imported the pandas agent: from langchain_experimental.agents import create_pandas_dataframe_agent. Please let me know if this is the right way to add the pandas agent as a node in the graph. When I run the pandas agent separately it works fine, but when I add it do the graph I am getting this ValueError saying "Missing some input keys: {'input'}".

Please let me know if I need to provide any further details.

System Info

System Information

OS: Windows
OS Version: 10.0.22631
Python Version: 3.11.2 (tags/v3.11.2:878ead1, Feb 7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)]

Package Information

langchain_core: 0.2.10
langchain: 0.2.6
langchain_community: 0.2.6
langsmith: 0.1.82
langchain_experimental: 0.0.62
langchain_openai: 0.1.7
langchain_text_splitters: 0.2.2
langchainhub: 0.1.14
langgraph: 0.1.5

Originally created by @azharmajeed-cml on GitHub (Jul 3, 2024). ### Checked other resources - [X] I added a very descriptive title to this issue. - [X] I searched the [LangGraph](https://langchain-ai.github.io/langgraph/)/LangChain documentation with the integrated search. - [X] I used the GitHub search to find a similar question and didn't find it. - [X] I am sure that this is a bug in LangGraph/LangChain rather than my code. - [X] I am sure this is better as an issue [rather than a GitHub discussion](https://github.com/langchain-ai/langgraph/discussions/new/choose), since this is a LangGraph bug and not a design question. ### Example Code ```python pandas_agent = create_pandas_dataframe_agent( llm, df, verbose=True, agent_type=AgentType.OPENAI_FUNCTIONS, # agent_type="openai-tools", allow_dangerous_code=True ) pandas_node = functools.partial(agent_node, agent=pandas_agent, name="Analyst") workflow = StateGraph(AgentState) workflow.add_node("Analyst", pandas_node) for member in members: # We want our workers to ALWAYS "report back" to the supervisor when done workflow.add_edge(member, "supervisor") # The supervisor populates the "next" field in the graph state # which routes to a node or finishes conditional_map = {k: k for k in members} conditional_map["FINISH"] = END workflow.add_conditional_edges("supervisor", lambda x: x["next"], conditional_map) # Finally, add entrypoint workflow.set_entry_point("supervisor") graph = workflow.compile() for s in graph.stream( { "messages": [ HumanMessage(content="summarize the columns in the dataframe provided to you") ] } ): if "__end__" not in s: print(s) print("----") ``` ### Error Message and Stack Trace (if applicable) ```shell ValueError Traceback (most recent call last) Cell In[63], line 1 ----> 1 for s in graph.stream( 2 { 3 "messages": [ 4 HumanMessage(content="summarize the columns in the dataframe provided to you") 5 ] 6 } 7 ): 8 if "__end__" not in s: 9 print(s) File c:\Users\AzharMajeed\Documents\.venv\Lib\site-packages\langgraph\pregel\__init__.py:1073, in Pregel.stream(self, input, config, stream_mode, output_keys, input_keys, interrupt_before, interrupt_after, debug) 1070 del fut, task 1072 # panic on failure or timeout -> 1073 _panic_or_proceed(done, inflight, step) 1074 # don't keep futures around in memory longer than needed 1075 del done, inflight, futures File c:\Users\AzharMajeed\Documents\.venv\Lib\site-packages\langgraph\pregel\__init__.py:1643, in _panic_or_proceed(done, inflight, step) 1641 inflight.pop().cancel() 1642 # raise the exception -> 1643 raise exc 1645 if inflight: 1646 # if we got here means we timed out 1647 while inflight: 1648 # cancel all pending tasks File ~\.pyenv\pyenv-win\versions\3.11.2\Lib\concurrent\futures\thread.py:58, in _WorkItem.run(self) 55 return 57 try: ---> 58 result = self.fn(*self.args, **self.kwargs) 59 except BaseException as exc: 60 self.future.set_exception(exc) File c:\Users\AzharMajeed\Documents\.venv\Lib\site-packages\langgraph\pregel\retry.py:72, in run_with_retry(task, retry_policy) 70 task.writes.clear() 71 # run the task ---> 72 task.proc.invoke(task.input, task.config) 73 # if successful, end 74 break File c:\Users\AzharMajeed\Documents\.venv\Lib\site-packages\langchain_core\runnables\base.py:2499, in invoke(self, input, config) 2497 # invoke all steps in sequence 2498 try: -> 2499 for i, step in enumerate(self.steps): 2500 # mark each step as a child run 2501 config = patch_config( 2502 config, callbacks=run_manager.get_child(f"seq:step:{i+1}") 2503 ) 2504 if i == 0: File c:\Users\AzharMajeed\Documents\.venv\Lib\site-packages\langgraph\utils.py:95, in RunnableCallable.invoke(self, input, config, **kwargs) 93 if accepts_config(self.func): 94 kwargs["config"] = config ---> 95 ret = context.run(self.func, input, **kwargs) 96 if isinstance(ret, Runnable) and self.recurse: 97 return ret.invoke(input, config) Cell In[24], line 2 1 def agent_node(state, agent, name): ----> 2 result = agent.invoke(state) 3 return {"messages": [HumanMessage(content=result["output"], name=name)]} File c:\Users\AzharMajeed\Documents\.venv\Lib\site-packages\langchain\chains\base.py:163, in invoke(self, input, config, **kwargs) 154 self._validate_inputs(inputs) 155 outputs = ( 156 self._call(inputs, run_manager=run_manager) 157 if new_arg_supported 158 else self._call(inputs) 159 ) 161 final_outputs: Dict[str, Any] = self.prep_outputs( 162 inputs, outputs, return_only_outputs --> 163 ) 164 except BaseException as e: 165 run_manager.on_chain_error(e) File c:\Users\AzharMajeed\Documents\.venv\Lib\site-packages\langchain\chains\base.py:151, in invoke(self, input, config, **kwargs) 136 callback_manager = CallbackManager.configure( 137 callbacks, 138 self.callbacks, (...) 143 self.metadata, 144 ) 145 new_arg_supported = inspect.signature(self._call).parameters.get("run_manager") 147 run_manager = callback_manager.on_chain_start( 148 dumpd(self), 149 inputs, 150 run_id, --> 151 name=run_name, 152 ) 153 try: 154 self._validate_inputs(inputs) File c:\Users\AzharMajeed\Documents\.venv\Lib\site-packages\langchain\chains\base.py:279, in _validate_inputs(self, inputs) 273 _input_keys = _input_keys.difference(self.memory.memory_variables) 274 if len(_input_keys) != 1: 275 raise ValueError( 276 f"A single string input was passed in, but this chain expects " 277 f"multiple inputs ({_input_keys}). When a chain expects " 278 f"multiple inputs, please call it by passing in a dictionary, " --> 279 "eg `chain({'foo': 1, 'bar': 2})`" 280 ) 282 missing_keys = set(self.input_keys).difference(inputs) 283 if missing_keys: ValueError: Missing some input keys: {'input'} ``` ### Description I am trying to add a pandas agent in a mutli agent setup, similar to how it is shown in this notebook. https://github.com/langchainai/langgraph/blob/main/examples/multi_agent/agent_supervisor.ipynb I imported the pandas agent: from langchain_experimental.agents import create_pandas_dataframe_agent. Please let me know if this is the right way to add the pandas agent as a node in the graph. When I run the pandas agent separately it works fine, but when I add it do the graph I am getting this ValueError saying "Missing some input keys: {'input'}". Please let me know if I need to provide any further details. ### System Info System Information ------------------ > OS: Windows > OS Version: 10.0.22631 > Python Version: 3.11.2 (tags/v3.11.2:878ead1, Feb 7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)] Package Information ------------------- > langchain_core: 0.2.10 > langchain: 0.2.6 > langchain_community: 0.2.6 > langsmith: 0.1.82 > langchain_experimental: 0.0.62 > langchain_openai: 0.1.7 > langchain_text_splitters: 0.2.2 > langchainhub: 0.1.14 > langgraph: 0.1.5
yindo closed this issue 2026-02-20 17:28:23 -05:00
Author
Owner

@vbarda commented on GitHub (Jul 3, 2024):

hi @azharmajeed-cml

The issue is likely due to passing graph state to the pandas dataframe agent, but the agent expects the input key which is not in the graph state. you would need to wrap it in a separate helper in the following way:

def pandas_node(state):
    # or whichever message in the state you need
    result = pandas_agent.invoke(state["messages"][-1].content)
    return {"messages": [HumanMessage(content=result["output"], name=name)]}

we'll also update these guides as for tool-calling agents we now recommend using langgraph prebuilt implementation (like from langgraph.prebuilt import create_react_agent

@vbarda commented on GitHub (Jul 3, 2024): hi @azharmajeed-cml The issue is likely due to passing graph state to the pandas dataframe agent, but the agent expects the `input` key which is not in the graph state. you would need to wrap it in a separate helper in the following way: ```python def pandas_node(state): # or whichever message in the state you need result = pandas_agent.invoke(state["messages"][-1].content) return {"messages": [HumanMessage(content=result["output"], name=name)]} ``` we'll also update these guides as for tool-calling agents we now recommend using langgraph prebuilt implementation (like `from langgraph.prebuilt import create_react_agent`
Author
Owner

@azharmajeed-cml commented on GitHub (Jul 5, 2024):

Hi @vbarda your solution above fixes the issue I had. Thanks for the suggestion to use prebuilt react agents from langgraph, will try it out.

@azharmajeed-cml commented on GitHub (Jul 5, 2024): Hi @vbarda your solution above fixes the issue I had. Thanks for the suggestion to use prebuilt react agents from langgraph, will try it out.
Author
Owner

@CrasCris commented on GitHub (Jul 22, 2024):

@azharmajeed-cml Can you show the example code of how you create a LangGraph to handle pandas agent ? , i got a bunch of errors , and i dont find any docs or examples about it

@CrasCris commented on GitHub (Jul 22, 2024): @azharmajeed-cml Can you show the example code of how you create a LangGraph to handle pandas agent ? , i got a bunch of errors , and i dont find any docs or examples about it
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#134