Module 2 · Orchestration topologies
Dynamic routing and agent specialization
5 min read
A multi-agent system is only as good as its routing decisions: sending the right task to the right agent, with the right model and the right tools. This lesson covers dynamic routing — deciding at runtime who handles what — and specialization — what makes one agent genuinely different from another.
The three levels of routing
From cheapest to most expensive:
1. Deterministic rules
Keywords, regular expressions, metadata (channel, language, customer type). Free, instant, unit-testable. They often handle a significant share of traffic.
2. The lightweight classifier
A fast, economical model with a structured output whose possible values are enumerated:
class Route(BaseModel):
agent: Literal["billing", "technical"]
reason: str
The Literal is essential: the model cannot invent a nonexistent agent. The reason field serves debugging and auditing.
3. Full reasoning
The main model, when the decision requires a fine understanding of the request (several intents mixed together, implicit context). That's what Atlas's planner does: decomposing is a complex routing decision.
Cascade principle: each level only handles what the previous level couldn't settle.
def route(request: str) -> str:
text = request.lower()
if any(w in text for w in ("invoice", "refund", "payment")):
return "billing" # level 1: rule
decision = extract(SYSTEM_ROUTER, request, Route, model=WORKER_MODEL)
return decision.agent # level 2: lightweight classifier
Handling uncertainty
A router makes mistakes. Plan for:
- A fallback option: an
"unknown"or"human"value in theLiteral, rather than forcing a choice. - The ability to correct: a specialist receiving a request outside its domain must be able to send it back (the handoff from lesson 2.2).
- Measurement: log each decision with its reason and the agent that ultimately answered. A high re-routing rate signals a poorly calibrated router or badly split domains.
class Route(BaseModel):
agent: Literal["billing", "technical", "human"]
reason: str
confident: bool # the router flags its own doubts
decision = extract(SYSTEM_ROUTER, request, Route, model=WORKER_MODEL)
target = decision.agent if decision.confident else "human"
Specialization: what really distinguishes two agents
Two agents sharing the same model, prompt and tools aren't two agents: they're two identical calls. An agent is specialized along four axes.
1. Instructions
A system prompt focused on one role, with its own quality criteria. Compare Atlas's prompts: the researcher "answers ONLY from the documents provided", the critic "evaluates faithfulness, coverage, clarity". Short, specific instructions beat a long generic prompt.
2. Tools (least privilege)
Each agent only gets the tools its role requires:
| Agent | Tools | No access to |
|---|---|---|
| Researcher | knowledge base read access | writing, sending, web |
| Writer | none | any external tool |
| Publisher | publishing (with approval) | reading external content |
Fewer tools also means fewer tool-selection mistakes and a shorter prompt. The longer the tool list, the harder the choice becomes for the model: one more argument for specialization (and, for very large catalogs, for on-demand tool search).
3. Model and effort
Not every task deserves the most capable model:
| Task | Model | Effort |
|---|---|---|
| Classify, route, extract | Economical (claude-haiku-5-5) | low |
| Summarize provided documents | Economical or mid-tier | medium |
| Plan, critique, arbitrate | Most capable (claude-opus-5-5) | medium to high |
Atlas applies this with WORKER_MODEL for its researchers. Effort is a second lever that doesn't require changing models:
draft = complete(SYSTEM_WRITER, prompt, effort="medium") # writing
plan = complete(SYSTEM_PLANNER, prompt, effort="high") # structuring decision
Lower effort produces fewer tool calls, less preamble, more direct answers. Measure before generalizing (module 5).
4. Context
Each agent receives the minimal context for its role. The researcher only knows its sub-question; the critic sees the note and the question, but not the raw documents. A smaller context improves the model's focus and reduces cost.
Anti-pattern: the all-knowing router
A router that must know the inner workings of every agent becomes a fragile coupling point: every change to a specialist requires changing the router. Prefer short, stable capability descriptions ("invoices, payments, refunds"), maintained by each specialist — exactly like tool descriptions. The router chooses based on these descriptions, without knowing the details.
Key takeaways
- Route in a cascade: deterministic rules, then an economical classifier, then full reasoning.
- Enumerate destinations in a
Literal, provide a fallback option, and measure the re-routing rate.- An agent is specialized by its instructions, its tools (least privilege), its model and effort, and its context.
- Specialists publish stable capability descriptions; the router doesn't depend on their internals.
Hands-on
- Add a
"human"value and theconfidentfield to the router in05_handoffs.py; route to an escalation node when the router is unsure. - Write 20 test requests (5 of them ambiguous) and measure the share handled by rules alone.
- For each Atlas agent, list its tools and justify that none is superfluous.