Overview

9 Router: Classifying and dispatching

The router pattern addresses the problem of many specialized agent components needing a single, simple entry point. Instead of forcing one general-purpose agent to handle every request, a lightweight selector classifies the incoming task and forwards it to the most appropriate specialist. This keeps the outside interface unified while allowing the internal system to remain modular, more reliable, and easier to govern.

A central benefit of routing is that it reduces tool overload, prevents domain knowledge from bleeding across unrelated tasks, and enables specialization. Each sub-agent can use its own prompt, tools, retrieval sources, and policy constraints, so billing, technical support, fraud handling, or other domains can be optimized independently. The routing chokepoint also becomes a natural place for logging, access control, escalation, and other oversight functions.

The chapter also shows several ways routers can be extended. An ensemble router can send one task to multiple specialists and reconcile their outputs when the best path is uncertain; a multi-layered router can route through a hierarchy of increasingly specific selectors; and a proximity router can decentralize routing so agents hand tasks among neighbors. These variants support different goals such as accuracy, cost control, load balancing, and privilege enforcement, and the chapter illustrates them with examples like tax advice, budget-aware model selection, and medical triage.

The AFD of the Router pattern. The input task is first seen by the selector element, which decides which sub-agent to invoke. The task is then forwarded unaltered to the selected sub-agent, and the result of that sub-agent's processing is eventually presented as the output of the whole routing component.
The AFD of the Ensemble router variant. The input task is seen by the selector element, which decides on which group of sub-agent to invoke. The task is then forwarded to the selected sub-agents, and the results of all sub-agents' processing is gathered and fed into reconciliation element, which produces the final output.
The AFD of the Multi-layered router variant. The input task is seen by the root selector element, which decides on which of its children sub-selectors to invoke. This continues until a leaf sub-agent is selected. The task is then forwarded to the selected sub-agent, and its result is presented as the final output.
The AFD of the Proximity router variant. The input task is seen by the root selector element, which decides on which the many sub-agents to invoke. The selected sub-agent can then either take on the input task or refer it to one of its neighbors, which may in turn do the same. The process terminates when a sub-agent takes on the task, at which point its output becomes the final output of the component.

Summary

  • The growth in specialized components within complex agents creates a need for a unified mechanism that directs tasks to the right component while presenting a single, general interface to the rest of the system.
  • The Router pattern is a component that selects among sub-agents based on task properties, constructs an appropriate payload, and forwards the task for processing without incrementally building context.
  • Routers forward inputs and outputs, expose a general interface despite heterogeneous sub-agent interfaces, and make constraint-preference choices based on task nature, complexity, or security demands.
  • Routers primarily improve robustness and reliability once specialized components exist, and they differ from Orchestrators by not subdividing problems or maintaining cross-step work context.
  • Router variants include the Ensemble Router (parallel invocation with reconciliation), the Multi-layered Router (a hierarchical tree of selectors), and the Proximity Router (decentralized routing decisions delegated to sub-agents).
  • Examples such as a jurisdiction-aware tax advisor, a complexity-driven inference budget optimizer, and an ensemble-based medical symptom triage system illustrate Router as a pattern that professionalizes agent architecture by turning ad-hoc component selection into disciplined, structured dispatch.

FAQ

```html
What is the Router pattern in agent design?A Router is a component that classifies an incoming task and forwards it to the most appropriate specialized sub-agent. The task goes in whole and comes out whole, but is handled by whichever specialist best fits the request.
Why not use one general-purpose agent for every task?A single general-purpose agent can suffer from tool overload, knowledge cross-contamination, and lack of specialization. Routing tasks to sub-agents keeps each path focused on the right tools, policies, and expertise.
What role does the selector play in a Router?The selector is the classification element in the Router. It examines the task, decides which sub-agent should handle it, and returns the key or identifier of the chosen component.
How does a Router communicate with its sub-agents?A Router maintains a unified interface to the outside world, forwards the input task to the selected sub-agent, and passes the output back without altering it. Internally, it manages the mapping between task types and specialized components.
What are the main benefits of using a Router?Routers improve robustness, reliability, code clarity, and modularity. They also reduce hallucinations, enable independent specialization, and create a natural chokepoint for logging, access control, and governance.
What are common use cases for the Router pattern?Common uses include specialized domain triage, inference budget optimization, load balancing, and information security privilege enforcement. In each case, the Router decides where a task should go based on task properties such as domain, complexity, availability, or sensitivity.
How does a Router help with specialized domain triage?A Router can inspect user intent and route the query to a sub-agent with the right domain knowledge. For example, a tax assistant can send Swiss tax questions to a Swiss specialist and US tax questions to a US specialist.
How does the Router pattern support inference budget optimization?A lightweight classifier can estimate task complexity and route simple tasks to cheaper, faster models while reserving expensive frontier models for complex requests. This helps conserve reasoning budget and reduce latency.
What is an Ensemble Router?An Ensemble Router selects multiple sub-agents instead of only one, runs them in parallel, and then reconciles their outputs. It is useful when routing is ambiguous or when hedging across multiple specialists is safer.
What is a Multi-layered Router and when is it useful?A Multi-layered Router routes tasks through a hierarchy of routers before reaching a terminal specialist. It is useful for coarse-to-fine triage, because each selector only needs to distinguish among its immediate children rather than the entire system.
```

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Agent Design Patterns ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Agent Design Patterns ebook for free