How does a LangChain agent handle a tool error?

By default it doesn’t: in langchain 1.5.0, an exception that escapes a tool stops the run. The tool node create_agent builds uses a default handler that sends only invalid arguments and unknown tool names back to the model as a message.

Two built-in middleware change that. ToolErrorMiddleware calls your on_error function with each exception. Return text and it becomes an error message for the model; return None and the exception propagates. It never retries. ToolRetryMiddleware does retry, twice after the first attempt by default, with exponential backoff. When the retries run out it returns an error message to the model, or re-raises if you set on_failure="error".

Once a failure becomes a message, the run can finish without a crash, so a clean run says little. What matters is what the agent does after the error. The tool node is the one LangGraph ships, so its default is the same.

published

sources

keep reading

More on this.

Try Tessary on Cloud.

free · 10,000 traces a month · 1 GB · 30-day retention · $10 one-time credit for triage and RCA · no credit card