Skip to main content

Lab 21: Building a Distributed Research System Challenge

Goalโ€‹

In this lab, you will build a distributed multi-agent system. You will create a main Orchestrator agent and a separate, standalone Research Specialist agent. The Orchestrator will delegate tasks to the Research Specialist over the network using the ADK's A2A capabilities.

Step 1: Create the Project Structureโ€‹

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.
  1. Create two separate agent projects that will run independently.

    uv run adk create a2a_orchestrator
    uv run adk create research_specialist
  2. Install Server Dependencies: From your adk-training root, install uvicorn, which is needed to run the agent as a web server (plain pip install fails on PEP 668-managed Pythons and doesn't reach your uv-managed venv anyway):

    uv add uvicorn sse-starlette "google-adk[a2a]"

Step 2: Build the Research Specialist (The Server)โ€‹

Exercise: Navigate into the research_specialist directory. Open agent.py and implement the specialist agent and expose it as an A2A server.

# In research_specialist/agent.py (Starter Code)
from google.adk import Agent
from google.adk.a2a.utils.agent_to_a2a import to_a2a
from google.adk.tools import google_search
from dotenv import load_dotenv
load_dotenv(override=True)

# TODO: 1. Define the agent (The Node), passing google_search in its tools list
# - Remember to include the A2A Context Handling instruction!
root_agent = Agent(...)

# TODO: 2. Expose as an A2A web application using 'to_a2a'
# Hint: a2a_app = to_a2a(root_agent, port=8001)

Step 3: Build the Orchestrator (The Client)โ€‹

Exercise: Navigate into the a2a_orchestrator directory. Open agent.py and implement the orchestrator using a Workflow and a RemoteA2aAgent.

# In a2a_orchestrator/agent.py (Starter Code)
from google.adk import Agent, Workflow
from google.adk.agents.remote_a2a_agent import RemoteA2aAgent, AGENT_CARD_WELL_KNOWN_PATH
from dotenv import load_dotenv
load_dotenv(override=True)

# TODO: 1. Define the Proxy Node (RemoteA2aAgent) pointing to the specialist server
# Hint: use f"http://localhost:8001{AGENT_CARD_WELL_KNOWN_PATH}"
# Hint: pass use_legacy=False to opt into the reliability-fixed A2A executor
remote_researcher = ...

# TODO: 2. Define the Local Coordinator Node and register 'remote_researcher'
coordinator = ...

# TODO: 3. Build the Distributed Workflow Graph (edges START -> coordinator)
root_agent = ...

Action: Confirm the .env file adk create generated in this directory is configured for the orchestrator's Gemini model.

Step 4: Run and Test the Distributed Systemโ€‹

This requires two separate terminals.

  1. Terminal 1 (Specialist Server):

    • Navigate to the research_specialist directory.
    • Run uv run uvicorn agent:a2a_app --host localhost --port 8001.
  2. Terminal 2 (Orchestrator Client):

    • Navigate to the parent adk-training directory.
    • Run uv run adk web and select a2a_orchestrator from the agent dropdown.
  3. Interact with the System:

    • Open the Dev UI for the orchestrator (http://localhost:8000 -- adk web's default port).
    • Give it a research task, like: "Please research the latest advancements in quantum computing."
    • Observe the Trace View to confirm that coordinator successfully delegates the task to remote_researcher.

Lab Summaryโ€‹

You have successfully built a distributed multi-agent system. You have learned to:

  • Expose an ADK agent as a network service using to_a2a().
  • Connect to a remote agent using the RemoteA2aAgent class.
  • Orchestrate tasks between agents running in separate processes.

Self-Reflection Questionsโ€‹

  • What are the main benefits of running the research_specialist as a separate service instead of just including it as a local sub-agent in the orchestrator?
  • The "A2A Context Handling" instruction is critical for the remote agent to function correctly. What kind of problems could arise if you forgot to include it?
  • How do the Agent Card (/.well-known/agent-card.json) and RemoteA2aAgent work together to simplify building decoupled distributed systems?

๐Ÿ” Reference Solution Vaultโ€‹

๐Ÿงช

21: Distributed Multi-Agent Graphs(Challenge Lab)

Part 3: Multi-Agent Systems โ€ข Module 21