Choosing Among Several Tools

routing to the right tool

Part of: Tool-Using Agent

One tool is a demo. A real agent has a toolbox, and the model has to pick the right tool for each question on its own. This lesson adds a weather tool and a search tool next to the calculator, then shows how you route each request to the matching Python function once the model picks one. Register more than one tool Add more schemas to the same tools list. Each gets its own name, description, and input schema: The model reads all three descriptions and picks based on the question. Ask about weather and it calls get weather. Ask it to multiply two numbers and it calls calculator. Ask "who won the last World Cup" and it calls web search. You never tell it which one. That is the payoff of the good descriptions you wrote in lesson 1. Routing the call in your code Once you get a tool use block back, look up block["name"] in a dispatch table instead of writing a long if/elif chain: block["input"] unpacks the dict straight into keyword arguments, so run weather(city="Tokyo") gets called correctly whichever tool fired, as long as your function's parameter names match the schema's property names exactly. Why a dispatch dict A dispatch dict scales to ten tools as easily as three, while an if/

Challenge: Route the Question