Recommended resources
The freely available resources this lesson will direct you to.
Hello!
In our last lesson, we focused on designing individual specialized agents—the "employees" of our agentic system. We established how to define their roles, tools, and boundaries. We concluded by introducing the "Coordinator Pattern," where a central intelligence directs work to these specialists.
Today, we're going to design that central intelligence. This lesson is dedicated to the router: the agent responsible for delegation. A well-designed router is the key to an efficient and scalable multi-agent system, ensuring that the right task always goes to the right specialist.
Our learning outcome is to design a router agent that delegates incoming tasks to the correct specialized agent based on content. We will explore the primary architectural patterns for this, analyzing the trade-offs between flexibility, performance, and cost, so you can make informed design decisions for your client projects.
1. The Router: A Formal Definition
In the "agent-as-employee" mental model, the router is the dispatcher or team lead. It doesn't perform the core work; its sole function is to receive a task, understand its nature, and delegate it to the most appropriate downstream component. This component could be a specialized agent, a specific LLM, a tool, or an entire workflow.
From a computer science perspective, we can define this role more formally.
A Survey on Routing Strategies for Resource Optimisation in Large Language Models
This research paper provides a concise, formal definition of a router in an LLM-based system. Understanding this will ground our design discussion in a rigorous framework.
Please read the first three paragraphs of the 'Background' section (Section 1). Pay close attention to the formal definition in Equation (1). It frames routing as an optimization problem: maximizing a scoring function (like accuracy) while adhering to a budget.
As the paper notes, given a query and a set of candidate agents , the router's job is to select the agent that maximizes a score (e.g., quality) while staying within a budget (e.g., cost, latency). This optimization mindset is central to designing effective routers.
2. Core Techniques for Router Design
The fundamental design question is: How does the router make its decision? There are several established techniques, each with distinct architectural trade-offs.
Mastering the Routing Pattern: 4 Essential Techniques for Building Intelligent AI Agents
This article from 'The Adaptive Engineer' provides an excellent, high-level overview of the most common routing patterns seen in production systems. We will use this as our framework for the rest of the lesson.
Read the entire article. It introduces four key routing techniques. For this lesson, we will focus on the three most common for delegating to specialized agents: LLM-Based, Embedding-Based, and ML Model-Based routing. The fourth, Rule-Based routing, is also important for deterministic systems.
Now, let's dive into the three primary AI-driven techniques, exploring how each works and when to use it.
3. Technique 1: LLM-Based Routing
This is the most direct and flexible approach. You leverage a powerful LLM's language understanding to act as the router itself.
How it works: You provide the incoming task to an LLM, along with a list of the available specialized agents and their descriptions. You then prompt the LLM to choose the most suitable agent. To ensure reliability, you constrain the LLM to provide its answer in a structured format, like a JSON object.
Let's see this in action.
Building Effective Agents with LangGraph
This video from LangChain demonstrates a simple yet powerful implementation of LLM-based routing using LangGraph. It shows how to use an LLM to decide which of three functions (or agents) to call based on the user's input.
Watch the 'Routing' section from 10:51 to 13:45. Notice the key trick: the router uses a model bound to a structured output schema (a Pydantic model in this case). This forces the LLM to return a valid choice ('poem', 'story', or 'joke'), which is then used in a conditional edge to direct the workflow.
- When to use it: For complex, ambiguous, or multi-faceted requests where nuanced understanding is critical. It's ideal for high-value, lower-volume workflows where accuracy is paramount.
- Trade-offs: This method offers maximum flexibility but incurs the highest latency and operational cost, as each routing decision requires a full LLM call.
This approach is what the survey paper (LINK) refers to as "Prompt-based routing" in Section 4.4.3.
4. Technique 2: Embedding-Based (Semantic) Routing
This technique transforms the routing problem from a linguistic task into a mathematical one: finding the nearest neighbor in a high-dimensional vector space.
How it works:
- Index: You write clear, descriptive summaries for each of your specialized agents (e.g., "This agent is a financial analyst that retrieves stock prices and market data."). You then use an embedding model to convert these descriptions into vectors and store them in a vector database.
- Query: When a new task arrives, you embed the task's description using the same model.
- Route: You perform a similarity search (e.g., cosine similarity) between the task vector and the stored agent vectors. The agent corresponding to the most similar vector is chosen.
This architecture is extremely common in production systems.

- When to use it: When you need a good balance of semantic understanding and high performance. It's excellent for a wide range of production systems where routing decisions must be fast and cost-effective.
- Trade-offs: Performance is critically dependent on the quality of your agent descriptions and the chosen embedding model. It's less flexible than full LLM routing for handling highly complex or context-dependent queries.
The survey paper (LINK) covers this under "Similarity-based Routing" in Section 4.1.
5. Technique 3: ML Model-Based Routing
This approach occupies a middle ground, using a dedicated, fine-tuned machine learning model to perform routing as a classification task.
How it works: Instead of using a general-purpose LLM, you train a smaller, specialized classification model (e.g., fine-tuning a BERT-family model) on a labeled dataset of (task, correct_agent) pairs. This model learns the specific patterns of your use case.
This is a powerful strategy for optimizing cost and performance at scale.
The concept of a router model has been developed extensively for a slightly different problem: routing queries between powerful/expensive LLMs and weaker/cheaper ones. This video explains the 'RouteLLM' framework, which is a perfect case study for ML-model-based routing. The principles are directly applicable to routing between specialized agents.
Watch from the beginning to 07:28. Focus on the core idea: training a model to predict which downstream model is best suited for a given query. Pay attention to the types of models they use for the router itself (similarity-weighted ELO, matrix factorization, classifiers), as this demonstrates the variety of classic ML techniques applicable here.
- When to use it: In high-throughput systems where you have a well-defined set of routes and can gather labeled data. It's perfect when you need to optimize for both cost and domain-specific accuracy.
- Trade-offs: This approach requires the overhead of creating a dataset and training/maintaining a model. It's less adaptable to new agents or tasks than LLM-based routing, as it typically requires retraining.
The survey paper (LINK) provides extensive detail on this under "Supervised Routing" (Section 4.2), covering techniques like "Domain Classification" and "Query complexity inference."
6. Architectural Synthesis
The choice of routing technique is a critical system design decision. Here is a summary of the trade-offs:
| Technique | Flexibility & Accuracy | Latency & Cost | Implementation Complexity |
|---|---|---|---|
| LLM-Based | Highest (understands nuance) | High (LLM call per query) | Low (prompt engineering) |
| Embedding-Based | Good (semantic understanding) | Very Low (vector search) | Medium (requires vector store) |
| ML Model-Based | High (domain-specific) | Low (fast classifier) | High (requires data & training) |
In advanced systems, these patterns can be combined. For example, a fast embedding-based router could handle the majority of requests, with an LLM-based router acting as a fallback for low-confidence queries.
The "router" is the heart of a dynamic, multi-agent system, orchestrating the collaboration between specialists.
Conclusion
You now have a robust framework for designing the most critical component of a multi-agent team: the router. By understanding the core techniques and their trade-offs, you can architect systems that are not only powerful but also efficient and scalable.
Key Takeaways:
- Routing as Optimization: A router's function is to select the optimal agent for a task based on criteria like quality, cost, and latency.
- Three Core Design Patterns:
- LLM-Based Routing: Maximum flexibility for complex queries, but with higher cost and latency.
- Embedding-Based Routing: The best balance of speed, cost, and semantic understanding for most production use cases.
- ML Model-Based Routing: The most performant and cost-effective for high-volume, well-defined tasks, but requires a training pipeline.
- The Right Tool for the Job: The choice of routing pattern is a strategic architectural decision based on the specific requirements of your client's problem.
In this lesson, we designed the agent that handles delegation. In our next lesson, we will build upon this to design a sequence-managing orchestrator that executes a multi-step workflow across several agents. We'll move from managing a single handoff to project-managing an entire end-to-end process.