Contents

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:

Four different kinds of customer messages all go into one support prompt that holds every rule and tool, and the answers suffer.I want my money backMy earbuds won't pairWhere is my parcel?What are your hours?One support promptall rules, all toolsrefunds + troubleshooting+ tracking + FAQlarge model for every queryAnswersdiagnostics on refundsstiffer tech answersbig-model price for FAQseach fix breaks another
Scroll to see all of it.
One prompt for every kind of request: each topic’s rules and tools get in the way of the others, and easy questions pay the large-model price.

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:

  1. 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_support with a confidence of 0.88. It does not answer the customer.
  2. 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.
  3. Dispatch. Code, not the model, calls the tech-support handler: a troubleshooting prompt with the run_diagnostics and search_kb tools. The refund rules and refund tools are not in its context at all.
  4. 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

A request goes to a router that returns a label and a confidence, a code policy dispatches it to one of four handlers or a fallback, the handler's answer goes straight to the caller, and the decision is logged.Request+ historyRouterlabel + confidenceclosed enumPolicythresholdin codeDecision logroute + confidenceRefundlarge model, refund toolsTech supportdiagnostics toolsOrder statussmall model, orders APIGeneral FAQsmall model + FAQ indexFallbackclarify, generalist, humanAnswerto caller12345
Scroll to see all of it.

Hover over a number, or tap it, to read what it is.

Solid lines carry the request, dashed lines carry the answer and the log entry. The accent line is the one path taken; no line returns to the router.
  1. 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.
  2. 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.
  3. 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.
  4. Fallback. Where low-confidence and out-of-scope requests go: a clarifying question, a generalist handler or a human queue.
  5. 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

Avoid it when

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 none label 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

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.

Further reading