Giving the Agent Tools
tool registry and dispatch
Part of: Multi-Step Task Agent
Your plan names a tool on every step: "search," "calculate," "write file." Right now those names are just strings in a JSON blob. Nothing runs until each name points at real code. This lesson builds the tool registry , the map from a tool's name to the Python function that does the work. Defining tools for the model The Anthropic API lets the model call a tool once you describe each one with a name, a description, and an input schema: When the model decides to use a tool, its reply carries a tool use content block holding a name and an input dict of the arguments it guessed. You take that name and route it to the matching Python function. The name might come from a live tool-choice reply or from a planned step's "tool" field; either way, the routing is the same. The registry pattern A tool registry is a plain dict from tool name to function. Dispatching a step is one lookup and one call: Every step of every plan runs through this same two-line dispatch, whatever the step does. That is the point of it. The executor never needs a growing chain of if tool == "search": ... elif tool == "calculate": ...; it looks the name up. Why guard the unknown case A planner can hallucinate a tool n
Challenge: Dispatch to the Tool Registry