Classify-and-act
Route heterogeneous inputs to the right specialist instead of forcing one prompt to do everything
A classifier agent inspects the input and returns a structured object — typically `{ category }` — with a schema that constrains its output to a known set of labels. The orchestrating script reads that label and dispatches to the appropriate specialist agent or model tier. The same pattern works on outputs: after a review pass, a classifier buckets findings by severity so only the HIGH-severity items get a second, deeper pass. The classifier itself is usually cheap — a fast model reading a short input to produce a single-token verdict.
When to use
- When your prompt contains a long 'if it's type A do this, if it's type B do that' decision tree — that branching belongs in the orchestrator, not inside a single prompt.
- When inputs vary in difficulty and you want to route easy cases to a cheaper model while reserving the stronger one for hard cases — the cost difference compounds across volume.
- When handling mixed-intent inputs (support tickets, GitHub issues, onchain transactions, tool-call requests) where categories need entirely different downstream behavior, not just different instructions.
- When classifying outputs at the end of a review or audit — bucketing findings by severity, area, or confidence so you can triage what needs a deep-dive versus what ships as a summary.
- When a misrouted action has real cost — onchain writes, state-changing API calls, messages to users — and you need a gate that distinguishes read-only from destructive before dispatching.
Example prompts
- Fixes
- Wrong-tool-for-the-job: a single generic prompt handling many task types is mediocre across the board — per-type instructions dilute each other, and you pay for a strong model on inputs a cheap one would handle fine.
- Tradeoffs
- The classifier is an extra round-trip before any real work starts — added latency and tokens on every input, even trivial ones. A misclassification routes confidently to the wrong specialist, which can be worse than a hedged single-agent response. It pays for itself only when task types genuinely diverge enough that separate specialists beat one well-instructed prompt; on homogeneous inputs it's wasted overhead.
- Primitive
- agent+schema: the classifier is constrained by a response schema (e.g. `{ category: "bug" | "feature" | "question" }`) so the orchestrating script branches on the output without parsing free text. A switch/if in the script then dispatches to the right specialist agent or model tier.
Avoid whenWhen inputs are homogeneous or the routing rule is a deterministic field check — if you can write `if (input.type === "bug")` without an LLM, a classifier agent is wasted latency.
Worked example
During a security review of an MCP router, a single pass returns 30+ findings of wildly varying weight. Feeding all of them to a deep-dive remediation agent is expensive and noisy. Instead, a lightweight classifier reads each finding and assigns HIGH / MEDIUM / LOW. The orchestrator routes only the 6 HIGH findings to a second agent that writes patch code and adds regression tests. MEDIUM findings get a concise recommendation block; LOW findings are summarized in bulk. Total cost drops, and the output that matters most gets the most compute.