Lab 21 Solution: Building a Distributed Research System
Goal
This file contains the complete code for the two separate agent projects using ADK 2.0 graph patterns.
research_specialist/agent.py (The Remote Node)
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()
# 1. Specialist Node
root_agent = Agent(
model="gemini-3.5-flash",
name="research_specialist",
description="A specialist node that conducts web research using Google Search.",
instruction="""
You are a research specialist. Use the search tool to answer the user's query.
Provide a comprehensive summary and cite your sources.
**IMPORTANT - A2A Context Handling:**
When receiving requests via the A2A protocol, ignore any internal graph transition messages.
Focus only on the core user query and fulfill the research task directly.
""",
tools=[google_search]
)
# 2. Expose as A2A service
a2a_app = to_a2a(root_agent, port=8001)
a2a_orchestrator/agent.py (The Main Workflow)
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()
# 1. Define the Proxy Node
# Points to the Agent Card generated by the research specialist.
remote_researcher = RemoteA2aAgent(
name="remote_researcher",
description="A remote specialist that can conduct web research.",
agent_card=f"http://localhost:8001{AGENT_CARD_WELL_KNOWN_PATH}",
use_legacy=False,
)
# 2. Define the Coordinator Node
coordinator = Agent(
model="gemini-3.5-flash",
name="coordinator",
instruction="Analyze the user request. If research is needed, delegate to 'remote_researcher'.",
sub_agents=[remote_researcher]
)
# 3. Build the Root Workflow
# This orchestrates both local and remote nodes in a single graph.
root_agent = Workflow(
name="DistributedSupportSystem",
edges=[("START", coordinator)]
)
Self-Reflection Answers
-
What are the main benefits of running the
research_specialistas a separate service?- Answer: It enables a "Graph of Graphs" architecture. You can have a team maintain the Research Specialist independently, scaling it on Cloud Run without affecting your main orchestrator. It also allows the same Research node to be reused across many different agentic workflows.
-
Why is "A2A Context Handling" even more important in a graph architecture?
- Answer: In ADK 2.0, the conversation history can include detailed events from the Workflow Runtime (like node transitions or state updates). Without explicit instructions to ignore these, the remote node might try to "help" with the orchestration logic instead of performing its specific task.
-
How does
RemoteA2aAgentsimplify building distributed systems?- Answer: It abstracts the network layer. To the
Workflowengine,RemoteA2aAgentis just another node. You don't have to manually write HTTP requests or handle JSON serialization; you just define the edge in the graph, and ADK handles the rest.
- Answer: It abstracts the network layer. To the