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
Prompt chaining: decompose, verify each step
Prompt chaining splits a complex task into a fixed sequence of focused LLM steps, each feeding the next, with a deterministic check between them so one bad step can't poison the rest.
Parallelization: fan out independent work
Parallelization runs independent sub-tasks concurrently — split-and-merge for speed, or same-task-N-ways for accuracy — but only when no step depends on another's output.
Multi-agent: split roles, coordinate the work
Break a hard job into specialized agents with narrow roles and separate context windows, then coordinate their work through an orchestrator or a structured exchange.