Tools · Free preview

Routing to the Right Tool

Match intent to tool

A model routes a request by reading each tool's description and picking the one whose keywords best match the user's intent — and calls nothing when none match.

Match intent to a tool

You wrote one tool's description last lesson. Real agents carry a handful — a weather tool, a calculator, a search tool — and now the model faces a new problem: given a user message, which one? That decision is called routing, and it is the moment all those carefully-worded descriptions earn their keep.

The mechanism is simpler than it sounds. The model reads every tool's description and judges which one's purpose overlaps most with what the user asked. You'll model that overlap concretely: each tool advertises the keywords that describe what it's for, and a message routes to the tool whose keywords it hits most. "Calculate the sum of these numbers" contains calculate and sum — two hits on the calculator, zero on weather or search — so it routes to calculator. This keyword-scoring stands in for the model's semantic judgment; the shape of the decision is identical.

The case that matters most is the one with no winner. "Tell me a story about a dragon" matches no tool's keywords at all — and the correct move is to call nothing and answer in plain text. Forcing a bad tool call here is a real failure mode: it wastes a round-trip, can throw an error, and erodes trust when the agent grabs a calculator to tell a bedtime story. "Call nothing" is always a valid route.

Below is a small registry of tools, each advertising its keywords, and four user messages. Finish route so it scores every tool by how many keywords appear in the message, returns the highest scorer's name, and falls back to "none" when the best score is 0. Done is all four messages routing exactly as expected, including the dragon story routing to none.

Routing is just matching intent to description. The better your tool descriptions, the better the model routes — and "call nothing" is always a valid choice.

In the full academy, you write and run this — live, graded:

// A tiny tool registry. Each tool advertises the keywords it handles —
// this is what a model "reads" in the description to decide when to call it.
const registry = [
  { name: "weather",    keywords: ["weather", "forecast", "temperature", "rain"] },
  { name: "calculator", keywords: ["calculate", "sum", "add", "multiply", "math"] },
  { name: "search",     keywords: ["find", "search", "lookup", "place"] },
];

const messages = [
  "what is the weather forecast today",
  "calculate the sum of these numbers",
  "find me a good sushi place",
  "tell me a story about a dragon",
];

// Route each message to the tool whose keywords best match it.
function route(message) {
  // TODO: score every tool by how many of its keywords appear in the message,
  // pick the highest-scoring tool, and return "none" if nothing matches.
  // Right now this naively grabs the first tool, ignoring intent.
  

🔒 Live code execution, real agent runs, mastery tracking and verifiable credentials unlock with the full academy.

This is 1 of 50 lessons.

The full academy: write real code, watch real agents run, and earn verifiable credentials — across 8 tracks, in a 3D campus.

Unlock the full academy — $100 →

14-day refund · 🔒 Stripe-secured checkout · lifetime access

More free lessons: An LLM Is a Function  ·  The Agent Loop  ·  Define a Tool  ·  Give an Agent a Tool  ·  Durable State

← The Agent Marketplace