Send each request to the agent built to handle it

Conditional routing uses a classifier agent to read each incoming request and hand it to the specialist that deals with that type of work, with a defined fallback for anything that matches no route.

Browse the guides

How routing selects the right specialist

One input, several possible specialists

A pipeline often receives requests that are not alike. One input needs a specialist that can search the web, another needs one that writes code, and a third only needs to read from a database. Running every input through the same fixed sequence wastes a step on work an agent was never built to do, or skips a step a different input actually needed. Routing sends the input down one path.

What the classifier agent does

A router is a classifier agent placed at the front of the agent graph, before any specialist runs. It reads the input, decides what kind of request it is, and checks that decision against the trigger condition set for each specialist in the graph. Once a condition matches, the classifier hands the input to that one agent and the other specialists never see it.

The classifier's job is to decide the branch. It does not pass the input to more than one specialist unless the design calls for that on purpose. Where an input is genuinely ambiguous, a classifier agent can match it to the wrong branch, which is why the conditions it checks against need to describe real differences between requests rather than near-identical wording of the same request.

A customer request handler, routed by query type

This example is invented to show the pattern.

A support team wants one inbox that can take any customer message and send it to the right specialist without a person reading it first. The message might be about a double charge, a crashing app, or a request to change an email address, and each of those needs a different agent with different tools.

The roles

AgentHandlesTools assigned
Billing agentCharges, refunds, subscription changesPayment system lookup, refund tool
Technical agentBugs, crashes, login errorsDiagnostics tool, bug tracker
Account agentEmail changes, password resets, plan changesAccount database write access
Fallback agentAnything the router cannot classify with confidenceTicket queue, human escalation

A router agent sits in front of these four and reads every incoming message first. It does not answer the customer. It assigns a label, and the label decides the handoff.

Four messages through the router

  1. "I was charged twice for my subscription last month." The router labels this billing and hands it to the Billing agent, which checks the payment record and can issue the refund directly.
  2. "My app crashes every time I open the settings page." The router labels this technical and hands it to the Technical agent, which runs diagnostics against the error.
  3. "Please update my billing address and email." The router labels this account, not billing, because the request is a change to stored details rather than a charge, and hands it to the Account agent.
  4. "Why does my dashboard look different today?" The router finds no label it is confident in, so the trigger condition for billing, technical and account all fail, and the message falls through to the fallback agent for a human to pick up.

The fourth case is the one worth designing for deliberately. A classifier agent reads intent from wording, and wording is sometimes ambiguous, so the router will occasionally sit between two labels or none. Giving the fallback agent its own trigger condition is what keeps a wrong classification from reaching a specialist agent that cannot actually resolve it.

Trigger conditions and what happens when none match

What a trigger condition has to specify

A trigger condition is the rule attached to a route, the test a classifier agent applies to decide whether a given input belongs to that specialist. A condition written as "billing-related" is too loose, because the classifier has no fixed way to tell where billing stops and an account change begins. A condition written as "contains an invoice number, a payment date, or the words refund or charge" gives the classifier something it can check directly against the input in front of it.

Each route in a configuration needs a condition specific enough that it does not overlap with its neighbours. Where two conditions can both be true of the same input, the router has no principled way to choose between them, and the outcome depends on whichever condition happens to be checked first.

Handling the input that matches nothing

Every router eventually meets an input that fits none of its defined routes: a request phrased oddly, a question that spans two specialists, or a case nobody anticipated when the routes were written. Without a defined fallback, that input either stalls, loops back through the classifier, or reaches whatever agent happens to run last by accident of configuration.

A fallback route deserves the same attention as any other route in the graph. Common options include:

  • Sending the input to a general-purpose agent that attempts a broad answer or asks the person a clarifying question.
  • Returning the input to the person who submitted it, with a message naming what could not be classified.
  • Flagging the input for a human to review before any agent acts on it.

Which option fits depends on what the workflow is for. A system facing customers directly usually needs to avoid leaving a request unanswered, so a general agent or a clarifying question tends to suit it better. A system handling financial or account changes more often needs the human review path, since an agent guessing at the wrong category there carries a real cost.

Setting this alongside the rest of the role map

Attach a trigger condition and a fallback route to each agent role in the same plan, so the fallback shows up in the handoff order. A condition that reads cleanly on paper can still overlap once real input reaches it, so check the wording against real examples. For routing alongside dynamic task delegation, see Orchestrator-Workers, and the guides cover the other patterns a role map depends on.