agent-patterns

router

flowchart TD
    Input([Task input]) --> Router[Router agent]
    Router --> C{Category}
    C -- BUG_FIX --> B[Bug-fix agent]
    C -- FEATURE --> F[Feature agent]
    C -- REFACTOR --> R[Refactor agent]
    C -- SECURITY --> S[Security agent]
    B & F & R & S --> Done([Result])

A classifier agent analyzes the input and dispatches to the appropriate specialist agent. The routing decision is made once, upfront — no specialist ever sees tasks outside its domain.

How it works

  1. The router agent classifies the input into a known category (e.g. BUG_FIX, FEATURE, REFACTOR, SECURITY).
  2. The category determines which specialist agent receives the task.
  3. The specialist processes the task with a focused system prompt.
  4. Effort is allocated per role: the router runs at low effort with a small max_tokens (one word out); the specialist gets the budget at medium. Same model, one cache namespace — measure this before reaching for a cheaper classifier model.

When to use

When not to use

Trade-offs

   
Pro Each specialist is focused — smaller prompt, better results
Pro Easy to add specialists without touching existing ones
Pro Routing cost stays small next to the specialist call when the router runs at low effort
Con Misclassification silently sends the task to the wrong agent
Con Tasks that span categories require either multi-label routing or a fallback generalist

Failure modes