Lab 15: Designing a Multi-Agent System Challenge
Goalβ
Goalβ
Before writing any code, a crucial step in building a multi-agent system is to design it conceptually. In this lab, you will design a simple two-agent system on paper (or in a text file). This process of planning will make the implementation in the next module much smoother.
Our system will be a "Greeting Router." It will consist of a main router agent and one specialist agent that knows how to greet in Spanish.
The Scenarioβ
We want to build an agent that can handle greetings in multiple languages. A monolithic approach would require a very complex instruction prompt. Instead, we will create a system with specialized agents for each language, and a router to direct the user's request. For this lab, we will only design the router and the Spanish specialist.
Step 1: Define the Roles and Responsibilitiesβ
First, let's define what each agent in our system will do.
Agent 1: The router_agentβ
- Purpose: This will be our main, parent agent. Its only job is to understand the user's request and delegate the task to the correct specialist agent. It should not perform any greetings itself.
- Type:
Agent. It needs the reasoning capability of an LLM to understand the user's intent. - Initial Instruction Idea:
You are a language router. Your job is to understand which language the user wants to be greeted in and delegate to the appropriate specialist.
If the user asks for a greeting in Spanish, you MUST delegate to the `spanish_greeter_agent`. - Tools: None. Its primary action is delegation.
Agent 2: The spanish_greeter_agentβ
- Purpose: This is our specialist sub-agent. Its only job is to provide a friendly greeting in Spanish.
- Type:
Agent. - Description (for the router): This is a critical piece of information -- the
router_agent's LLM reads this description to decide whether this specialist is the right match for a given request. Your task: write this description yourself, in one sentence, before moving on. A good description is specific and action-oriented (what does this agent actually do?) and would clearly distinguish it from any other specialist you might add later (say, a futurefrench_greeter_agent). Jot it down here -- you'll reuse it in Step 3's plan and in the next module's implementation. (Check thelab-solution.mdfile for one example of a description that works well, once you've written your own.) - Initial Instruction Idea:
You are a friendly assistant who only speaks Spanish.
Your job is to greet the user warmly in Spanish. Do not say anything else.
Step 2: Map the Interaction Flowβ
Now, let's trace the path of a user's request through our designed system.
Flow 1: Supported Language (Spanish)β
- User Input: The user starts a conversation with the
router_agentand says:"Can you greet me in Spanish?" - Router Receives: The ADK's runner passes this input to the
router_agent. - Router Reasons: The
router_agent's LLM receives the user input, its own instruction, and the list of available sub-agents along with their descriptions. - Router Delegates: Based on its instructions ("If the user asks for... Spanish, ...delegate to the
spanish_greeter_agent") and the description you wrote for the sub-agent in Step 1, the LLM decides to perform an agent transfer. - Framework Transfers Control: The ADK framework intercepts this decision and transfers control of the conversation to the
spanish_greeter_agent. - Specialist Executes: The
spanish_greeter_agentnow takes over. It executes its own instruction ("greet the user warmly in Spanish"). - Specialist Responds: The
spanish_greeter_agentgenerates the final response to the user, such as"Β‘Hola, mucho gusto!"
Flow 2: Unsupported Languageβ
- User Input: The user asks:
"Can you greet me in French?" - Router Receives: The input is passed to the
router_agent. - Router Reasons: The
router_agent's LLM analyzes the request. It sees that the user wants "French," but it looks at its list of sub-agents and sees no specialist with a description matching "French." - Router Responds Directly: Following its instructions for unsupported languages, the
router_agentdoes not delegate. Instead, it formulates its own response to the user. - Router's Final Response: The
router_agentreplies:"I'm sorry, I don't have a specialist for that language yet."
Step 3: Plan the File Structureβ
Based on our design, we can plan the files we'll need to create in the next lab.
adk-training/
βββ greeting_system/ <-- New project directory
βββ .env <-- For API keys
βββ agent.py <-- This will define our Workflow and Router node
βββ __init__.py <-- Makes the directory a Python package
βββ spanish_greeter_agent.py <-- This will define our Specialist node
agent.py (The Router and Workflow):
This file will need to:
- Import the
AgentandWorkflowclasses. - Import the
agentobject from yourspanish_greeter_agent.pymodule. - Define the
routeragent and register the specialist in itssub_agentslist. - Define the
root_agentas aWorkflowthat starts with therouter.
spanish_greeter_agent.py (The Specialist):
This file will need to:
- Define a standard
Agentobject. - Include a clear
descriptionfor the router. - Include
instructionthat tells the agent to only greet in Spanish.
Lab Summaryβ
You have successfully designed a multi-agent system on paper!
- You learned to break down a problem into specialized Nodes.
- You defined how nodes are registered via
sub_agentsand orchestrated viaWorkflow. - You mapped the flow of control within a Graph.
In the next module, you will bring this design to life by implementing this Greeting System.
Self-Reflection Questionsβ
- What is the most important piece of information that allows the
router_agentto decide which specialist to delegate to? - How would you extend this system to support a new language, like French? What new files or modifications would you need to make?
- This lab uses LLM-driven delegation (agent transfer). What might be the advantages or disadvantages of this approach compared to the
router_agentusing anAgentToolto explicitly call thespanish_greeter_agent? (You haven't built anAgentToolyet -- Module 19 covers it in depth. For now, just think about the difference between a permanent, one-way handoff to another agent versus calling that agent like a function and getting a result back so you can keep working.)
π Reference Solution Vaultβ
Module 15 Reference Solution Vault
Active Comprehension Gate β’ Zero Guessable URLs β’ Guided Verification