← All AI Agents & Tool Use modules

Module 6 — Routing to the Right Tool

Making it reliable · hands-on · about 25 minutes.

Give an agent one tool and there is no decision to make. Give it a toolbox — a calculator, a population lookup, a weather service, a calendar, a search — and a new question appears on every single step: which tool fits this request? That decision is called routing, and getting it right is what separates a useful agent from one that returns nonsense. Pick the wrong tool and the observation is useless or wrong, and the whole loop goes off course.

The router matches intent to capability

A router looks at the request, considers what each available tool is for (its name and description), and dispatches to the best match. "What's 12% of 90?" is arithmetic → the calculator. "What's the weather in Paris?" → the weather tool. "What's on my calendar?" → the calendar. The agent is reading the intent of the request and matching it to a tool's stated job. More tools means more power, but also more chances to misroute — which is exactly why clear tool descriptions matter so much.

Send requests through the router

Pick a request and watch the router decide. It scores each tool against the request, picks the best, calls it, and shows the observation. Try the tricky ones — a request that looks like one tool but needs another — and watch what a good router does. You can also see what happens when it routes to the wrong tool.

This activity needs JavaScript. The lesson below still covers everything.

Routing in code — read only, nothing to install
# each tool advertises what it is for; the router matches the request to one
tools = {
    "calculator": "evaluate arithmetic like '12 * 0.9'",
    "weather":    "current weather for a city",
    "calendar":   "the user's events for today",
}

def route(request):
    # the model reads the request's intent and the tool descriptions,
    # then returns the name of the single best-fitting tool
    return best_match(request, tools)

In a real agent the router IS the language model: on each step it is shown the tool list and decides which to call. "Tool/function calling" is routing — choosing the right capability for the moment.

AI anchor — routing is the decision an agent makes constantly Every step of every agent is a routing decision: given everything so far, which tool (if any) should I call next? When an assistant decides to search the web instead of answering directly, or to run code instead of guessing, that is the router at work. Whole systems are built around it — "router" models that send easy questions to a small cheap model and hard ones to a big one, and agents that choose among dozens of tools. Good routing is mostly good descriptions: a tool the model understands is a tool it can choose correctly.

Check your understanding

A few questions about routing. You will get a score.

This activity needs JavaScript.

Why this matters next A router can still pick wrong, and an agent can still loop forever or take a risky action. Module 7 adds the guardrails — step limits, loop detection, tool validation, and human approval — that keep an agent safe and reliable when things go sideways.
One-sentence summary: when an agent has many tools, routing is the decision — made on every step — of which tool best matches the request's intent; good routing depends on clear tool descriptions, and a wrong choice sends a useless observation back into the loop.

Next: Guardrails & Reliability →