
Imagine you’re building an AI system to analyze social media trends. A single AI agent could do the job, but what if you could have specialized agents working together — one expert at finding trending topics, another skilled at deep data analysis, and a third orchestrating their collaboration? This is where multi-agent systems shine.
The challenge? Getting these agents to communicate effectively. The diverse frameworks, APIs, and protocols present significant challenges for inter-agent communication. Enter Agent-to-Agent (A2A) protocol — a standardized way for AI agents to discover, communicate, and collaborate, regardless of their underlying implementation.
In this guide, we’ll build a practical three-agent system that demonstrates the power of A2A, showing you how to create specialized agents that work together seamlessly.
The Agent-to-Agent (A2A) protocol is Google’s answer to the agent communication challenge. Think of it as a universal language that allows AI agents to:
- Discover each other’s capabilities through standardized metadata
- Communicate using a common JSON-RPC based protocol
- Collaborate on complex tasks through orchestration
- Stream responses for real-time interactions
Check out the full code at:
and also at the A2A Samples Github Repository:
You can execute it on our various platforms: Colab, Vertex AI Workbench, BQ Studio, Colab Enterprise. You can also find it from our VSCode Cloud Code, along with other AI/ML code templates:
Each agent exposes its capabilities through a standardized endpoint, allowing other agents to understand what it can do without knowing its internal implementation.
The beauty of this approach is its flexibility. Agents can be developed independently, deployed on different infrastructure, and even built with different frameworks — as long as they speak A2A.
Also check out these other resources:
Codelabs:
Let’s build a practical example: a system that finds trending topics and provides deep analysis. We’ll create three specialized agents:
- Trending Topics Agent: Searches the web for current trends
- Trend Analyzer Agent: Performs quantitative analysis on specific trends
- Host Agent: Orchestrates the other agents to provide comprehensive insights
Our first agent specializes in finding what’s trending right now. Using Google’s ADK (Agent Development Kit), we create an agent with web search capabilities:
from google.adk.agents import Agent
from google.adk.tools import google_searchtrending_agent = Agent(
model="gemini-2.5-pro",
name="trending_topics_agent",
instruction="""
You are a social media trends analyst. Your job is to search the web
for current trending topics, particularly from social platforms.
When asked about trends:
1. Search for "trending topics today" or similar queries
2. Extract the top 3 trending topics
3. Return them in a JSON format
You MUST return your response in the following JSON format:
{
"trends": [
{
"topic": "Topic name",
"description": "Brief description",
"reason": "Why it's trending"
}
]
}
""",
tools=[google_search],
)
Obs: in the context of agent orchestration there is currently a constraint that requires us to explicitly perform controlled generation instead of configuring the structured output.
The second agent takes a specific trend and digs deep, finding quantitative data and metrics:
analyzer_agent = Agent(
model="gemini-2.5-pro",
name="trend_analyzer_agent",
instruction="""
You are a data analyst specializing in trend analysis.
When given a trending topic, perform deep research to find
quantitative data and insights.
For each trend you analyze:
1. Search for statistics, numbers, and metrics
2. Look for:
- Engagement metrics (views, shares, mentions)
- Growth rates and timeline
- Geographic distribution
- Related hashtags or keywords
3. Provide concrete numbers and data points
""",
tools=[google_search],
)
Here’s where the magic happens. We need to wrap our ADK agents with the A2A protocol. This involves creating an executor that handles A2A requests and responses:
class ADKAgentExecutor(AgentExecutor):def __init__(self, agent, status_message="Processing…", artifact_name="response"):
self.agent = agent
self.status_message = status_message
self.artifact_name = artifact_name
self.runner = Runner(
app_name=agent.name,
agent=agent,
artifact_service=InMemoryArtifactService(),
session_service=InMemorySessionService(),
memory_service=InMemoryMemoryService(),
)
…
The Host Agent is special — it doesn’t do the work itself but coordinates the other agents:
# Create the Host ADK Agent
host_agent = Agent(
model="gemini-2.5-pro",
name="trend_analysis_host",
instruction="""
You are an expert AI Orchestrator.
Your primary responsibility is to intelligently interpret user requests, plan the necessary sequence of actions if multiple steps are involved, and delegate them to the most appropriate specialized remote agents.
You do not perform the tasks yourself but manage their assignment, sequence, and can monitor their status.
Core Workflow & Decision Making:
1. **Understand User Intent & Complexity:**
…
2. **Agent Discovery & Selection:**
…
3. **Task Planning & Sequencing (for Multi-Step Requests):**
…
4. **Task Delegation & Management:**
…
**Communication with User:**
…
""",
tools=[a2a_client.list_remote_agents, a2a_client.create_task]
)
To run our multi-agent system, we start each agent as an A2A server:
# Start agent servers
print("Starting agent servers…\n")
trending_thread = run_agent_in_background(create_trending_agent_server, 10020, "Trending Agent")
analyzer_thread = run_agent_in_background(create_analyzer_agent_server, 10021, "Analyzer Agent")
host_thread = run_agent_in_background(create_host_agent_server, 10022, "Host Agent")# Register remote agents with the A2A client
a2a_client = A2AToolClient()
a2a_client.add_remote_agent("http://localhost:10020")
a2a_client.add_remote_agent("http://localhost:10021")
remote_agents = a2a_client.list_remote_agents()### Output
# Remote agent url: http://localhost:10020
# Remote agent name: Trending Topics Agent
# Remote agent skills: [{'description': 'Searches for current trending topics on social media', 'examples': ["What's trending today?", 'Show me current Twitter trends', 'What are people talking about on social media?'], 'id': 'find_trends', 'name': 'Find Trending Topics', 'tags': ['trends', 'social media', 'twitter', 'current events']}]
# Remote agent version: 1.0.0
# ----
# Remote agent url: http://localhost:10021
# Remote agent name: Trend Analyzer Agent
# Remote agent skills: [{'description': 'Provides quantitative analysis of a specific trend', 'examples': ['Analyze the #ClimateChange trend', 'Get metrics for the Taylor Swift trend', 'Provide data analysis for AI adoption trend'], 'id': 'analyze_trend', 'name': 'Analyze Trend', 'tags': ['analysis', 'data', 'metrics', 'statistics']}]
# Remote agent version: 1.0.0
# ----
# Execute a complex multi-agent task
host_analysis = await a2a_client.create_task(
"http://localhost:10022",
"Find the most relevant trends today and give me a complete analysis with quantitative data"
)
By interacting with our Host Agent, based on the user prompt and its orchestration instructions, it is capable of discover the relevant remote agents it should interact it, reason about it, and communicate with each one to achieve the desired goal:
Here is a complete analysis of the **G7 Summit 2025** trend, with quantitative data, as provided by the Trend Analyzer Agent:
### G7 Summit 2025: A Data-Driven Analysis of an Evolving Global Agenda
The 2025 G7 Summit, hosted by Canada in Kananaskis, Alberta from June 15–17, convenes at a critical juncture for the world’s leading economies. Against a backdrop of uneven economic recovery, escalating geopolitical tensions, and the accelerating challenges of climate change and technological disruption, the summit’s agenda is squarely focused on three pillars: safeguarding global security, advancing the energy and digital transitions, and forging resilient future partnerships. This analysis delves into the quantitative data underpinning these priorities, offering a snapshot of the trends and challenges shaping the G7’s discussions.
…
Source Credit: https://medium.com/google-cloud/a-practical-guide-to-building-multi-agents-ai-systems-with-a2a-2c0e3d77af24?source=rss—-e52cf94d98af—4