AI Pattern · Control flow

Router Pattern

The model classifies the request and routes it to the right path.

A router inspects the incoming request and decides which tool, model, or sub-chain should handle it, then dispatches to that path. A cheap model can handle easy work while a strong model is reserved for hard cases, and each category gets a focused, specialized chain.

How it works

  1. 1Receive the request
  2. 2Classify it, intent, difficulty, or domain
  3. 3Route to the matching tool, model, or sub-chain
  4. 4Run that path and return the result

Strengths

  • Cost control, small model for easy, big only when needed
  • Specialization, a tuned path per category
  • Keeps each downstream prompt focused

Watch-outs

  • A wrong route cascades into a wrong answer
  • More moving parts and an added failure point
  • Routing logic needs its own maintenance

When to use it

Heterogeneous workloads, support that is part FAQ, part billing, part bug report, or cost optimization across a mix of easy and hard queries.

Example prompt

Classify this request into exactly one label: [billing, technical, account, other].
Reply with only the label.

Request: <text>