langchain-ai / langgraph

Build resilient language agents as graphs.
https://langchain-ai.github.io/langgraph/
MIT License
4.26k stars 639 forks source link

Parallel tool calls causing errors in human-in-the-loop breakpoint example #874

Closed hannah-schiebener closed 1 week ago

hannah-schiebener commented 1 week ago

Checked other resources

Example Code

inputs = [HumanMessage(content="search for the weather in sf and in nyc now")]

Error Message and Stack Trace (if applicable)

BadRequestError
Cell In[96], line 1
----> 1 for event in app.stream(None, thread, stream_mode="values"):
      2     event["messages"][-1].pretty_print()

File /workspaces/waiv/backend/.venv/lib/python3.12/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 /workspaces/waiv/backend/.venv/lib/python3.12/site-packages/langgraph/pregel/__init__.py:1639, in _panic_or_proceed(done, inflight, step)
   1637             inflight.pop().cancel()
   1638         # raise the exception
-> 1639         raise exc
   1641 if inflight:
   1642     # if we got here means we timed out
   1643     while inflight:
   1644         # cancel all pending tasks

File /usr/local/lib/python3.12/concurrent/futures/thread.py:58, in _WorkItem.run(self)
     55     return
     57 try:
...
   (...)
   1036     stream_cls=stream_cls,
   1037 )

BadRequestError: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': "messages.2: the following `tool_use` ids were not found in `tool_result` blocks: {'toolu_01CWAWQdMDnYjrNBSneJfr3Z'}"}}

Description

I am running the breakpoints.ipynb notebook from the Human-in-the-Loop documentation and have modified the inputs variable (see above). This is the output when interacting with the agent with the modified input where it stops before calling the tool:

================================ Human Message =================================

search for the weather in sf and in nyc now
================================== Ai Message ==================================

[{'text': "Certainly! I'll search for the current weather in both San Francisco (SF) and New York City (NYC) for you. To do this, I'll need to make two separate search queries using the available search function. Let me do that for you now.", 'type': 'text'}, {'id': 'toolu_0134753sWzLXRGrbERPw7h8A', 'input': {'query': 'current weather in San Francisco'}, 'name': 'search', 'type': 'tool_use'}, {'id': 'toolu_01CWAWQdMDnYjrNBSneJfr3Z', 'input': {'query': 'current weather in New York City'}, 'name': 'search', 'type': 'tool_use'}]
Tool Calls:
  search (toolu_0134753sWzLXRGrbERPw7h8A)
 Call ID: toolu_0134753sWzLXRGrbERPw7h8A
  Args:
    query: current weather in San Francisco
  search (toolu_01CWAWQdMDnYjrNBSneJfr3Z)
 Call ID: toolu_01CWAWQdMDnYjrNBSneJfr3Z
  Args:
    query: current weather in New York City

This throws the above error after the first tool is run. Sometimes the tools are called one after the other, which seems to work fine.

System Info

System Information

OS: Linux OS Version: #1 SMP Thu May 23 08:36:57 UTC 2024 Python Version: 3.12.1 (main, Feb 1 2024, 03:58:05) [GCC 12.2.0]

Package Information

langchain_core: 0.2.10 langchain: 0.2.1 langchain_community: 0.2.1 langsmith: 0.1.82 langchain_anthropic: 0.1.16 langchain_mistralai: 0.1.7 langchain_openai: 0.1.7 langchain_text_splitters: 0.2.0 langgraph: 0.1.3

vbarda commented 1 week ago

Thanks for reporting @hannah-schiebener . Just updated the notebooks, this should be fixed now. The issue in the example was that it was using only the first tool (now should handle arbitrary number of tool calls).