All articles
December 15, 2024 4 min read

Routing: send each input to the model that should handle it

Classify the incoming request first, then dispatch it to a specialised prompt or model. Separation of concerns for AI workflows — and a quiet way to cut cost.

Written forEngineering
AI WorkflowsDesign PatternsRouting

When one prompt has to handle wildly different kinds of input, it ends up mediocre at all of them. Routing fixes that: a first step classifies the input, then hands it to a follow-up that's specialised for exactly that category. It's separation of concerns applied to AI workflows.

InRouter — classifyBilling agentTech supportSales agentOut
A lightweight router classifies the request, then dispatches to the specialised handler for that category.

How it works

The router is usually a small, cheap model (or even a classifier) whose only job is to pick a category. Each downstream path then gets a prompt tuned for its case — and optionally a different model. Simple queries go to a fast, cheap model; hard ones go to a frontier model. You optimise each path without any one of them dragging down the others.

  • Each handler is tuned for one category, so quality rises across the board.
  • Route easy traffic to cheap models and reserve frontier models for hard cases.
  • Add a new category by adding a route — no risk of regressing the others.
Classify, then dispatch
const category = await router(input);   // 'billing' | 'tech' | 'sales'

switch (category) {
  case 'billing': return billingAgent(input);
  case 'tech':    return techSupportAgent(input);
  default:        return salesAgent(input);
}

When to use it

Use routing when inputs fall into distinct classes that are best handled differently — support triage, multi-language handling, or tiering by difficulty. The one thing to watch: the router is now a dependency. Measure its accuracy, because a misroute sends the request down the wrong path entirely.

Don't build one prompt that's average at everything. Route to the one that's excellent at the thing in front of it.
Building something with LLMs?
I help teams ship GenAI that’s reliable and cost-efficient.
Let’s talk