Skip to main content

Lab 15: Building Your First Multi-Agent Greeting Router

Goal​

In this lab, you will build and run your first live Multi-Agent System (MAS) using ADK 2.0's sub_agents delegation pattern:

  • A router_agent (root_agent) whose sole job is to understand which language the user wants and transfer the conversation to the matching specialist.
  • Two domain specialists β€” spanish_greeter_agent and japanese_greeter_agent β€” isolated in their own module (specialists.py) with crisp, non-overlapping description strings.

Expected Behavior​

User PromptExpected Flow
"Can you greet me in Spanish?"router_agent transfers to spanish_greeter_agent β†’ replies warmly in Spanish ("Β‘Hola!...").
"Please greet me in Japanese."router_agent transfers to japanese_greeter_agent β†’ replies politely in Japanese.
"Greet me in French!"router_agent sees no matching specialist in sub_agents β†’ politely explains French isn't supported yet.

Step 1: Scaffold the Project​

Environment setup:

  • 1-Click Launch (Browser): Open in GitHub CodespacesOpen in Google Cloud Shell
  • Local machine: If you're continuing the course in sequence, cd into the adk-training project you created in Module 2 and skip the block below -- your environment and dependencies already carry forward. If you're starting fresh at this module, create that project first:
    uv init adk-training --python 3.10 && cd adk-training
    uv add "google-adk>=2.1.0" python-dotenv
  • DevContainer / Codespaces (Alternative): If you opened this repository in a DevContainer or GitHub Codespaces, Python 3.11, uv, gcloud, and all core ADK dependencies are pre-installed in your container environment.

From your main adk-training directory, scaffold a new agent project:

uv run adk create greeting_system

Your folder structure will look like this once you add specialists.py:

adk-training/
└── greeting_system/
β”œβ”€β”€ .env
β”œβ”€β”€ __init__.py
β”œβ”€β”€ specialists.py <-- Step 2: Specialist sub-agents
└── agent.py <-- Step 3: Coordinator (root_agent)

Step 2: Implement the Specialist Sub-Agents (greeting_system/specialists.py)​

Create greeting_system/specialists.py and complete the TODO placeholders. Remember: the coordinator's LLM reads each specialist's description to decide whom to transfer to!

# greeting_system/specialists.py
from google.adk import Agent

# TODO: Define spanish_greeter (name="spanish_greeter_agent", model="gemini-3.8-flash")
# - Write a clear `description` so the router knows it handles Spanish greetings.
# - Write an `instruction` telling it to greet warmly ONLY in Spanish.
spanish_greeter = Agent(
name="spanish_greeter_agent",
model="gemini-3.8-flash",
description=..., # TODO: Action-oriented description for discovery
instruction=..., # TODO: Greet warmly in Spanish only
)

# TODO: Define japanese_greeter (name="japanese_greeter_agent", model="gemini-3.8-flash")
# - Write a clear `description` so the router knows it handles Japanese greetings.
# - Write an `instruction` telling it to greet politely ONLY in Japanese (with romaji).
japanese_greeter = Agent(
name="japanese_greeter_agent",
model="gemini-3.8-flash",
description=..., # TODO: Action-oriented description for discovery
instruction=..., # TODO: Greet politely in Japanese only
)

Step 3: Wire the Coordinator (greeting_system/agent.py)​

Open greeting_system/agent.py and configure root_agent to delegate via sub_agents:

# greeting_system/agent.py
from google.adk import Agent
from .specialists import spanish_greeter, japanese_greeter

# TODO: Define root_agent (name="router_agent", model="gemini-3.8-flash")
# - Instruct it to delegate to the matching specialist in sub_agents (never greet in Spanish/Japanese itself),
# and politely decline unsupported languages like French.
# - Register both specialists in `sub_agents=[...]`.
root_agent = Agent(
name="router_agent",
model="gemini-3.8-flash",
instruction=..., # TODO: Triage instructions
sub_agents=[...], # TODO: Register spanish_greeter and japanese_greeter
)

Step 4: Run and Inspect the Hand-off in Dev UI​

  1. Launch the Dev UI from your parent adk-training directory:
    uv run adk web
    (Select greeting_system from the agent dropdown).
  2. Test all three scenarios (Spanish, Japanese, and unsupported French).
  3. Check the Trace Tab: Expand the turn where you asked for Spanish β€” you will see router_agent automatically invoke transfer_to_agent(agent_name="spanish_greeter_agent"), followed immediately by spanish_greeter_agent generating the final reply!

Self-Reflection Questions​

  • What is the single most important field that lets router_agent know which specialist to transfer to?
  • How would you extend this team to support Italian greetings without rewriting the existing specialists?
  • After router_agent transfers a conversation to spanish_greeter_agent, who handles the user's next message by default? (Hint: Try sending a second message in the same chat session!)

πŸ” Reference Solution Vault​

πŸ§ͺ

15: Intro to Multi-Agent Systems(Challenge Lab)

Part 3: Multi-Agent Systems β€’ Module 15

Overall Course Progress:
0%(0/98)
Next: 16: Collaborative Teams πŸ“– β†’