← All AI Agents & Tool Use modules

Module 6 — Routing to the Right Tool

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

When an agent has access to a single tool, no selection is required. When the agent has access to a set of tools — a calculator, a population lookup, a weather service, a calendar, a search facility — a decision arises at every iteration: which tool is appropriate for this request? This selection problem is termed routing, and its correct resolution determines whether the agent produces useful output. An incorrect routing decision yields an irrelevant or erroneous observation, which propagates through the remainder of the loop.

The router matches intent to capability

A router examines the request, considers the function of each available tool (as defined by its name and description), and dispatches the request to the most appropriate tool. "What is 12% of 90?" is arithmetic and is routed to the calculator. "What is the weather in Paris?" is routed to the weather service. "What is on my calendar?" is routed to the calendar. The router infers the intent of the request and matches it to the stated function of a tool. A larger tool set provides greater capability but increases the number of routing decisions that may be made incorrectly — which is precisely why precise tool descriptions are essential.

Submit requests to the router

Select a request and observe the router's decision. It scores each tool against the request, selects the highest-scoring tool, invokes it, and displays the observation. Examine the ambiguous cases — requests that superficially resemble one tool's function but require another — to observe the behavior of a well-designed router. The activity also illustrates the consequences of routing to an inappropriate tool.

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

Routing expressed in code
# 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 production agent, the router is the language model: at each iteration it is provided with the tool list and selects the tool to invoke. The "tool calling" and "function calling" APIs are routing — the selection of an appropriate capability for the current request.

Route your own request

The presets above are routed for you. Now type anything and watch the same router score every tool and dispatch to the winner — including the case where a vague request matches nothing and a good agent should ask for clarification instead of guessing.

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

AI anchor — routing as a recurring agent decision Every iteration of every agent constitutes a routing decision: given the current state, which tool (if any) should be invoked next? When an assistant elects to perform a web search rather than respond directly, or to execute code rather than generate an answer from its parameters, the router is making that determination. Entire systems are organized around routing — "router" architectures that direct simple queries to small efficient models and complex queries to large capable models, and agents that select among dozens of tools. Effective routing depends primarily on the quality of tool descriptions: a tool that is precisely described is a tool that can be selected correctly.

Check your understanding

Answer a short set of questions on routing.

This activity needs JavaScript.

Why this matters next The router may still select an incorrect tool, and the agent may still enter an infinite loop or execute a high-risk action. Module 7 introduces guardrails — step limits, loop detection, tool-call validation, and human-in-the-loop approval — that maintain agent safety and reliability when execution deviates from expected behavior.
Summary: when an agent has access to multiple tools, routing is the per-iteration decision of which tool best matches the intent of the current request. Effective routing depends on precise tool descriptions; an incorrect routing decision returns an irrelevant observation that propagates through the remainder of the loop.

Next: Guardrails & Reliability →