Skip to content

ValueError: Found AIMessages with tool_calls that do not have a corresponding ToolMessage #94

@hyb91

Description

@hyb91

Through Langchain official case, case address: https://langchain-ai.github.io/langgraph/agents/multi-agent/#swarm

The error report is as follows:
Traceback (most recent call last):
File "D:\Langchain.venv\test\graph28.py", line 52, in
for chunk in swarm.stream(
~~~~~~~~~~~~^
{
^
...<6 lines>...
},config
^^^^^^^^
):
^
File "D:\Langchain.venv\Lib\site-packages\langgraph\pregel\main.py", line 2642, in stream
for _ in runner.tick(
~~~~~~~~~~~^
[t for t in loop.tasks.values() if not t.writes],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<2 lines>...
schedule_task=loop.accept_push,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
):
^
File "D:\Langchain.venv\Lib\site-packages\langgraph\pregel_runner.py", line 162, in tick
run_with_retry(
~~~~~~~~~~~~~~^
t,
^^
...<10 lines>...
},
^^
)
^
File "D:\Langchain.venv\Lib\site-packages\langgraph\pregel_retry.py", line 42, in run_with_retry
return task.proc.invoke(task.input, config)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
File "D:\Langchain.venvLib\site-packages\langgraph_internal_runnable.py", line 657, in invoke
input = context.run(step.invoke, input, config, **kwargs)
File "D:\Langchain.venv\Lib\site-packages\langgraph\pregel\main.py", line 3015, in invoke
for chunk in self.stream(
~~~~~~~~~~~^
input,
^^^^^^
...<10 lines>...
**kwargs,
^^^^^^^^^
):
^
File "D:\Langchain.venv\Lib\site-packages\langgraph\pregel\main.py", line 2642, in stream
for _ in runner.tick(
~~~~~~~~~~~^
[t for t in loop.tasks.values() if not t.writes],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<2 lines>...
schedule_task=loop.accept_push,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
):
^
File "D:\Langchain.venv\Lib\site-packages\langgraph\pregel_runner.py", line 162, in tick
run_with_retry(
~~~~~~~~~~~~~~^
t,
^^
...<10 lines>...
},
^^
)
^
File "D:\Langchain.venv\Lib\site-packages\langgraph\pregel_retry.py", line 42, in run_with_retry
return task.proc.invoke(task.input, config)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
File "D:\Langchain.venv\Lib\site-packages\langgraph_internal_runnable.py", line 657, in invoke
input = context.run(step.invoke, input, config, **kwargs)
File "D:\Langchain.venv\Lib\site-packages\langgraph_internal_runnable.py", line 394, in invoke
ret = context.run(self.func, *args, **kwargs)
File "D:\Langchain.venv\Lib\site-packages\langgraph\prebuilt\chat_agent_executor.py", line 616, in call_model
model_input = _get_model_input_state(state)
File "D:\Langchain.venv\Lib\site-packages\langgraph\prebuilt\chat_agent_executor.py", line 595, in _get_model_input_state
_validate_chat_history(messages)
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
File "D:\Langchain.venv\Lib\site-packages\langgraph\prebuilt\chat_agent_executor.py", line 246, in _validate_chat_history
raise ValueError(error_message)
ValueError: Found AIMessages with tool_calls that do not have a corresponding ToolMessage. Here are the first few of those tool calls: [{'name': 'book_flight', 'args': {'from_airport': 'BOS', 'to_airport': 'JFK'}, 'id': 'call_KUbGSv8HoAu5XIvfHWo7yjhM', 'type': 'tool_call'}].

Every tool call (LLM requesting to call a tool) in the message history MUST have a corresponding ToolMessage (result of a tool invocation to return to the LLM) - this is required by most LLM providers.
For troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/errors/INVALID_CHAT_HISTORY
During task with name 'agent' and id 'a0da7fde-e414-8f88-4962-70c5740dad23'
During task with name 'hotel_assistant' and id '2a301e57-a7c6-36a5-de74-bbf23c1b743e'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions