$building.effective.agents
Menu
Last verified: April 2026
· Pattern P02

Routing.

A classifier picks one of N specialised handlers based on the input. The classifier may itself be an LLM call or a deterministic rule. The pattern is appropriate when input classes have meaningfully different cost or quality requirements.

Definition

“Routing classifies an input and directs it to a specialized followup task. This workflow allows for separation of concerns, and building more specialized prompts. Without this workflow, optimizing for one kind of input can hurt performance on other inputs.”

From Anthropic, “Building Effective Agents”, December 2024.

What it does

The pattern is a two-step pipeline: a classifier reads the input and emits a label, then a dispatcher picks the handler associated with that label. The classifier might be a small LLM call, an embedding-based nearest-neighbour lookup, or a deterministic rule over input metadata. The handler set is open: a cheap model for the easy class, a reasoning model for the hard class, a human escalation path for the boundary case.

inputclassifierpicks branchhandler Acheap modelhandler Breasoning modelhandler Chuman escalationa confidence gate before the branch fires reduces mis-routes

The strength of routing is cost separation: the cheap path stays cheap, the expensive path is reserved for inputs that genuinely need it. The trade-off is that mis-classification routes inputs to the wrong handler, which is a different (and harder) failure mode than a single oversized prompt would have.

When it is appropriate

Routing is the right pattern when:

  • Input classes have different cost or quality requirements. Customer support is the textbook example: refund queries route differently from technical questions.
  • The classification is reliable. If the classifier mis-labels more than a small fraction of inputs, the cost saving evaporates under retry overhead.
  • There is a sensible default handler for unclassified inputs, including a path to human escalation.

Public examples

Cost considerations

The classifier adds a fixed per-input call. If the classifier is a small model and the dispatched-to handlers include a much larger model, the routing pattern saves cost on average. Vendor pricing pages (Anthropic, OpenAI) typically separate by an order of magnitude between the cheapest and most capable models, which is the cost lever the pattern exploits.

A second consideration is mis-routing recovery. If a downstream handler can detect that the input was mis-classified (for example, the “cheap” handler returns low confidence), a fall-through to a more capable handler raises cost on that input but preserves quality.

Failure mode

The dominant failure mode is silent mis-routing: the classifier confidently picks the wrong branch and the wrong handler returns plausible-but-wrong output. Mitigation typically uses a confidence threshold on the classifier output (a “confidence gate”) and a fall-through path to a more capable handler when confidence is low.

Glossary

See routing, classifier, confidence gate.

Foundational definitions on the sibling reference site: tool routing.

Read next