Skip to content

< all problems25 · Level 04, Tool Calling

Route a Question to the Right Tool

medium · implement · Tool Calling

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.

  1. Describe the tools in the prompt. The model cannot route to capabilities it was not told about.
  2. Constrain the output. "Reply with only the tool name" is not always obeyed, but it cuts how often you fall back to parsing.
  3. Parse case-insensitively. "Search", "**search**" and "I would use the search tool" have all routed correctly.
  4. 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.