Common langgraph errors and how to solve them.
Understand what each of these errors and learn how to fix it. This is a summary of all the error messages I get in langgrapgh and track how it's been solved to avoid doing the error again
"Invalid parameter: messages with role \'tool\' must be a response to a preceeding message with \'tool_calls\'."
Pretty self explanatory, an AI decides which tool will be called, and this happens by adding to the message list a new entry with x tool_calls, then the url is called and the results are added to the message list. If the message list doesn’t have something like add_messages, it can be that the tool response overwrites the original message with tool_calls which causes this error.Solution: Have a message list with [AI( with tool_calls X ), ToolOutput ( Response from Tool Call X ) ]
An assistant message with \'tool_calls\' must be followed by tool messages responding to each \'tool_call_id\'. The following tool_call_ids did not have response messages:
Similar as before but a bit different. This happens when there is an AI message with a tool call, and then there is no other message of the ToolOutput
Related Posts
4 Context Engineering Principles for building AI Agents
Context Engineer is taking over the AI Engineering space. Learn how to offload, implement one shot prompting, isolate and reduce context in this guide
Create a chatbot: Part 4 - Adding memory
In this part we'll see how to make the chatbot to remember things in our langgraph chatbot, this will be useful so our chatbot can remember a conversation
Create a chatbot: Part 2 - Creating the FastApi endpoints
How to use langgraph to create a chatbot that is wrapped around by a fastapi istance and displayed in the frontend with React. This second part explains how to use fastapi to create the endpoints that will be accessed from the frontend
Let's connect !!
Get in touch if you want updates, examples, and insights on how AI agents, Langchain and more are evolving and where they’re going next.