Tools & Routing
Define LangGraph tools with @tool, wire ToolNode and tools_condition into an agent loop, use the prebuilt create_agent, and write custom routers that branch on your own state.
Last updated
After this section you can
- Wire tools into a graph with ToolNode and tools_condition, and explain how the messages map to Claude's tool_use and tool_result
- Choose between create_agent and a hand-built graph, and write a router for rules the model must not decide
- Configure ToolNode error handling so recoverable tool failures reach the model instead of ending the run
Tools & Routing
A tool is a typed function with a docstring. Wiring it into a graph takes one prebuilt node and one conditional edge, and those two edges are the whole agent loop. Then: the prebuilt agent, routing on your own rules, and what happens when a tool fails.
The model never runs your tool. It returns an AIMessage with tool_calls; ToolNode runs them and appends one ToolMessage per call; a conditional edge sends the run back to the model or to END. The while loop from Part 3 becomes a cycle of two edges.