Resolving INVALID_TOOL_RESULTS in LangChain Tool Calling Chains for ai agent skills LangChain's tool-calling protocol requires exactly one ToolMessage per tool_call_id in a preceding AIMessage with tool_calls, and violating that one-to-one correspondence triggers the INVALID_TOOL_RESULTS error, which the source notes is currently used only in langchainjs (JavaScript/TypeScript). The error arises from three patterns: too few ToolMessage objects for multiple requested tool executions, duplicate or unmatched tool call IDs, and orphaned ToolMessages sent without a preceding AIMessage containing tool calls. The prescribed fix is to audit message history before model invocation, confirming tool call counts in AIMessages equal ToolMessage responses and that no duplicate or stray IDs exist in the chain. Resolving INVALID TOOL RESULTS in LangChain Tool Calling Chains for ai agent skills When a model returns an AIMessage with tool calls, the LangChain https://promptcube3.com/en/tags/langchain/ protocol requires exactly one corresponding ToolMessage for each tool call, with matching tool call id values. This error occurs when passing mismatched, insufficient, or excessive ToolMessage objects to a model during tool calling operations. For practitioners applying ai agent skills at work, understanding this protocol requirement is essential for reliable agent workflows. Error Mechanism: Why INVALID TOOL RESULTS Occurs in LangChain Tool Calling When a model generates an AIMessage containing tool calls, the system expects a precise one-to-one correspondence between each tool call identifier and its response. The error stems from a fundamental requirement: an assistant message with tool calls must be followed by tool messages responding to each tool call id. If the model requests two tool executions but only one response message is provided, the model rejects the incomplete message chain. Cause Analysis: Insufficient, Duplicate, and Orphaned ToolMessages Three common patterns trigger this error. First, insufficient responses occur when a model requests multiple tool executions but fewer ToolMessage objects are returned. Second, duplicate responses result from providing multiple ToolMessage objects for the same tool call ID, or from having unmatched IDs. Third, orphaned tool messages appear when a ToolMessage is sent without a preceding AIMessage containing tool calls, violating protocol requirements. Each pattern stems from breaking the expected message sequence during agent workflows. Resolution: Verifying ToolMessage Protocol Adherence To resolve INVALID TOOL RESULTS, operators should first count matching pairs: ensure one ToolMessage exists per tool call in the preceding AIMessage. Second, verify that each ToolMessage.tool call id matches an actual tool call identifier. Practical next steps include auditing the message history before model invocation, confirming that tool call counts in AIMessages equal ToolMessage responses, and checking that no duplicate or stray IDs exist in the chain. Note that this error is currently only used in langchainjs JavaScript/TypeScript . Illustrative photo · Pixabay https://www.pexels.com/photo/blackmonitorshowingtexts270373/ / Pexels Next Troubleshoot LangGraph GRAPH RECURSION LIMIT by Identifying Cycles or Long Execution Paths → https://promptcube3.com/en/threads/10085/ All Replies (0) Want a live back-and-forth? Join the global AI chat room https://promptcube3.com/en/chat/ — login to talk. No replies yet — be the first