Routing
Also known as: router, intent routing, model routing
- Who decides
- The model
- Shape
- Branch
Intent
Put a classifier in front of several specialised handlers and run exactly one of them for each input, so each handler keeps its own prompt, tools and model. The router decides once and steps aside: it never sees the answer and never decides again.
About the name. Frameworks also call an agent that hands the whole conversation to a specialist a “router”, “triage agent” or “coordinator”, which is a handoff. On this page a router is a single classification step that never gets control back.
Problem
You are building the support assistant of an online shop that sells headphones and speakers. Customers write about four things: refunds (“I want my money back”), technical problems (“my earbuds won’t pair”), delivery (“where is my parcel?”) and general questions (“what are your hours?”).
The first version is one support prompt that holds the rules and tools for all four topics, with the largest model behind it. Every fix for one topic causes trouble in another:
- Rules leak across topics. You make the refund instructions strict (always check the order date, never promise money), and the troubleshooting answers turn stiff and defensive.
- The wrong tools get called. With diagnostics, refund and order tools in one prompt, the model runs diagnostics on a refund request.
- Easy questions cost as much as hard ones. “What are your hours?” goes to the same large model as a firmware bug, and the prompt grows with every new topic, so every request gets slower and more expensive.
Solution
Split the assistant into specialised handlers and put a small classification step in front of them. The router reads the message and picks one label from a closed list. Your code checks that label and calls the matching handler, which is written and tested on its own.
On the pairing question, a run looks like this:
- Classify. The customer writes “My earbuds stopped pairing with my laptop after the last update.” The router, a small model asked for structured output, returns the label
tech_supportwith a confidence of 0.88. It does not answer the customer. - Apply the policy. Code checks that the label is on the list and compares the confidence with a threshold, say 0.7. Here the route stands. Below the threshold, or on the label
none, the message would go to a fallback: one clarifying question, a generalist handler or a human. - Dispatch. Code, not the model, calls the tech-support handler: a troubleshooting prompt with the
run_diagnosticsandsearch_kbtools. The refund rules and refund tools are not in its context at all. - Answer and log. The handler’s reply goes straight back to the customer. The route and its confidence are logged, so you can measure how often the router is right and notice when that changes.
A refund request takes another path, with a strict prompt and an approval step, and “what are your hours?” goes to a small model that searches the FAQ, so only the hard requests pay for the large model.
The nearest pattern, Supervisor, also chooses who handles the work, but it sees each result and decides again, while a router decides once and never sees the answer.
Structure
Hover over a number, or tap it, to read what it is.
- Router. Maps the request, and sometimes a short window of history, to one label from a closed list plus a confidence. It can be a model with structured output, an embedding match or plain rules.
- Policy. Code that checks the label, compares the confidence with a threshold and chooses between the named route and the fallback. Because it is code, it can be tested and changed without touching the model.
- Handlers. The specialised paths, one per label. Each has its own prompt, tools and model, and can be anything from a single prompt to a chain or a full agent.
- Fallback. Where low-confidence and out-of-scope requests go: a clarifying question, a generalist handler or a human queue.
- Decision log. The route and confidence for each request, the data you need to measure accuracy and notice drift.
Use it when / Avoid it when
Use it when
- Inputs fall into distinct categories. Each needs its own prompt, tools or model, and two people labelling the same message would agree.
- You can classify accurately. Measure the router on a labelled set of real messages before you build the handlers.
- Difficulty varies and model prices differ a lot. The RouteLLM paper by Ong et al. prices GPT-4 at about 100 times Mixtral 8x7B, so sending easy requests to the cheap model saves money.
- Some requests carry more risk. Refunds can take a guarded path with an approval step while FAQ answers stay fast.
Avoid it when
- Most requests mix several intents. Use a Supervisor, which can call several workers and combine their results.
- The right specialist only shows mid-conversation. Use handoffs, where the current agent passes the conversation on when it sees the need.
- The subtasks cannot be listed in advance. Use Orchestrator–Workers, which invents them at run time; a router only chooses among fixed paths.
- One handler would do. Use a single call with a good prompt, which avoids misroutes, an extra step and several prompts to maintain.
How it fails
- Silent misroute
-
The router picks the wrong label and the handler answers confidently with the wrong rules and tools. Nothing reports an error, because the handler does not know it was chosen by mistake.
Mitigation: test the router on a labelled set and add examples for the pairs of routes it confuses.
- Forced choice
-
A message that fits no route, such as a job application, still lands in one of the handlers.
Mitigation: add a
nonelabel and send it, with low-confidence results, to the fallback. - Follow-ups without context
-
“Yes, do that” is classified on its own, the router cannot tell what “that” means, and the conversation jumps to an unrelated handler.
Mitigation: give the router the last few turns, or keep follow-ups with the handler already in charge.
- Drift
-
A new product or a seasonal problem appears, and accuracy drops without anyone noticing.
Mitigation: watch the route mix and the fallback rate in the decision log, and relabel samples regularly.
Related patterns
- Supervisor: a manager agent that routes at every step and gets each worker’s result back, where a router decides once and the handler’s answer goes straight to the caller.
- Swarm / Handoffs: the active agent passes the conversation to a peer, which keeps it and may pass it on again; a “triage agent” in a framework is usually this, not a router.
- Prompt Chaining: a router often sits in front of several chains, picking which fixed sequence runs; inside a chain, a gate with two outcomes is a tiny router.
- Parallelization: runs several branches at once instead of one; picking a subset of branches per input sits between the two.
Try it
Describe your routes and the generator writes two things: a system prompt for the router, which classifies and never answers, and the dispatch policy your code applies to its label.
Open the generator on this pattern
Further reading
- Building effective agents (Anthropic, 2024): defines the routing workflow and when it fits.
- RouteLLM: Learning to Route LLMs with Preference Data (Ong et al., 2024): routing between a cheap and an expensive model, and how to measure the trade.
- Rerouting LLM Routers (Shafran et al., 2025): how crafted inputs push a router onto the path an attacker wants.