ToolNode and tools_condition
ToolNode executes tool calls from the last AI message. tools_condition routes to that node when tool calls exist, or to END when they do not.1
Tiny example
Section titled “Tiny example”from langgraph.graph import START, StateGraph, MessagesStatefrom langgraph.prebuilt import ToolNode, tools_condition
builder = StateGraph(MessagesState)builder.add_node("model", call_model)builder.add_node("tools", ToolNode([lookup_order]))builder.add_edge(START, "model")builder.add_conditional_edges("model", tools_condition)builder.add_edge("tools", "model")The loop is: model proposes a call → tools execute → model reads the result → model calls again or answers.
The default error boundary
Section titled “The default error boundary”Event inside ToolNode |
Default behavior |
|---|---|
| Model supplies invalid tool arguments | Return an error ToolMessage so the model can correct the call |
| Tool function raises during execution | Re-raise the exception so the graph can fail or retry |
handle_tool_errors=True |
Catch all tool exceptions and return error ToolMessage values |
Failure note
Section titled “Failure note”If handle_tool_errors=True catches a transient execution error, the node’s RetryPolicy never sees that exception. Choose deliberately: error message for model correction, or escaped exception for system retry. ToolNode can execute multiple tool calls in parallel, so every write tool must tolerate a repeated node attempt.
Related
Section titled “Related”Footnotes
Section titled “Footnotes”-
LangChain, Tools — ToolNode and
ToolNodeAPI reference. ↩