Route a Question to the Right Tool
Implement route(llm, question) returning the name of the tool that should handle the question: "search", "calculate", or "weather". TOOLS maps each name to what it is for.
- Describe the tools in the prompt. The model cannot route to capabilities it was not told about.
- Constrain the output. "Reply with only the tool name" is not always obeyed, but it cuts how often you fall back to parsing.
- Parse case-insensitively.
"Search","**search**"and"I would use the search tool"have all routed correctly. - Always return a valid name, even when the model produces nothing usable. A crash here takes out the whole request.
A real model answers. The tests send arithmetic, weather and policy questions, and check that an empty or nonsense question still returns a key of TOOLS.