← All topics
Knowledge

Routing: send each input to the right handler

Routing puts a thin classifier in front of your specialists — it inspects each input, picks the handler best suited to it, and dispatches without doing the work itself.

What it is

Routing puts a thin classifier in front of your specialists. It reads each input, decides which handler fits, and hands off — nothing more.

  • The router classifies and dispatches; it does no real work itself.
  • The handlers are specialized prompts, tools, or sub-agents, each good at one kind of input.
  • The classifier can be an LLM call, a cheap embedding match, or plain rules — whatever reliably picks the right lane.

When to use it

Reach for routing when one entrypoint has to serve genuinely different kinds of work.

  • A support agent where *refund*, *bug report*, and *sales* each need a different prompt and toolset.
  • Mixed difficulty: send easy classification to a small/cheap model, hard reasoning to the frontier one — a cost lever, see cost control.
  • Anywhere a single mega-prompt is sprawling because it tries to handle every case at once.

Skip it when inputs are uniform, or when steps always run in a fixed order — that's prompt chaining, not routing.

How it works

The router classifies into one of a fixed, known set of routes, then dispatches. Keep the route set small and the classifier's only job classification.

  • Define routes up front, e.g. "refund" | "bug" | "sales" | "other".
  • The classifier returns one route label — constrain it to that enum, don't let it free-text.
  • Dispatch the original input to the matching handler; the router does not answer.
  • Always include a fallback route ("other") for inputs that match nothing.

The handler downstream may itself chain, call tools, or be a full sub-agent — see multi agent.

Watch out for

  • Misroutes are silent. A wrong label sends good input to the wrong specialist and you get a confident wrong answer. Log the chosen route and treat misroutes as a measurable failure — see evals.
  • No fallback. Without an explicit "other" lane, novel inputs get force-fit into the nearest route. Make the catch-all a real, handled outcome.
  • The router creeping into doing work. The moment it starts answering instead of dispatching, you've lost the separation that made routing testable. Keep it thin.
  • Too many routes. A bloated enum tanks classification accuracy; merge rarely-used lanes.

Related patterns

Ask the swarm