Skip to main content

Agent to Agent (A2A)

The Agent to Agent (A2A) protocol enables seamless collaboration between specialized AI agents, allowing them to communicate, share knowledge, and coordinate responses based on their unique capabilities and domain expertise. With VideoSDK's A2A implementation, you can create multi-agent systems where different agents work together to provide comprehensive solutions.

How It Works​

Basic Flow​

  1. Agent Registration: Agents register themselves with an AgentCard that contains their capabilities and domain expertise
  2. Client Query: Client sends a query to the main agent
  3. Agent Discovery: Main agent discovers relevant specialist agents using agent cards
  4. Query Forwarding: Main agent forwards specialized queries to appropriate agents
  5. Response Chain: Specialist agents process queries and respond back to the main agent
  6. Client Response: Main agent formats and delivers the final response to the client

A2A Architecture

Example Scenario​

Client → "Book a flight to New York and find a hotel"
↓
Travel Agent (Main) → Analyzes query
↓
Travel Agent → Discovers Flight Booking Agent & Hotel Booking Agent
↓
Travel Agent → Forwards flight query to Flight Booking Agent
Travel Agent → Forwards hotel query to Hotel Booking Agent
↓
Specialist Agents → Process queries and respond back (text format)
↓
Travel Agent → Combines responses and sends to client (audio format)

Core Components

1. AgentCard​

The AgentCard is how agents identify themselves and advertise their capabilities to other agents.

Structure​

AgentCard(
id="agent_flight_001",
name="Skymate",
domain="flight",
capabilities=[
"search_flights",
"modify_bookings",
"show_flight_status"
],
description="Handles all flight-related tasks"
)

Parameters​

ParameterTypeRequiredDescription
idstringYesUnique identifier for the agent
namestringYesHuman-readable agent name
domainstringYesPrimary expertise domain
capabilitieslistYesList of specific capabilities
descriptionstringYesBrief description of agent's purpose
metadatadictNoAdditional metadata for the agent

2. A2AMessage​

A2AMessage is the standardized communication format between agents.

Structure​

message = A2AMessage(
from_agent="travel_agent_1",
to_agent="agent_flight_001",
type="flight_status_query",
content={"query": "What's the status of AI202?"},
metadata={"client_id": "xyz123", "urgency": "medium"}
)

Parameters​

ParameterTypeRequiredDescription
from_agentstringYesID of the sending agent
to_agentstringYesID of the receiving agent
typestringYesMessage type/event name
contentdictYesMessage payload
metadatadictNoAdditional message metadata

3. Agent Registry​

register_a2a(agent_card)​

Register an agent with the A2A system.

async def on_enter(self):
await self.register_a2a(AgentCard(
id="agent_flight_001",
name="Skymate",
domain="flight",
capabilities=[
"search_flights",
"modify_bookings",
"show_flight_status"
],
description="Handles all flight-related tasks"
))

What Registration Does:

  • Adds the agent to the global AgentRegistry singleton
  • Makes the agent discoverable by other agents
  • Stores both the AgentCard and agent instance
  • Enables message routing to this agent

unregister()​

Unregister an agent from the A2A system.

await self.unregister_a2a()

4. A2AProtocol Class​

The main class for managing agent-to-agent communication.

Agent Discovery​

find_agents_by_domain(domain: str)​

Discover agents based on their domain expertise.

agents = self.a2a.registry.find_agents_by_domain("hotel")
# Returns: ["agent_hotel_001"]

find_agents_by_capability(cap: str)​

Find agents with specific skills.

agents = await self.a2a.registry.find_agents_by_capability("modify_bookings")
# Returns: ["agent_flight_001"]

Agent Communications​

send_message(to_agent, message_type, content, metadata=None)​

Send messages directly to other agents.

await self.a2a.send_message(
to_agent="agent_hotel_001",
message_type="hotel_booking_query", # Event name that the receiving agent listens for
content={"query": "Find 3-star hotels in Delhi under $100"},
metadata={"client_id": "xyz123"} # Optional metadata
)

Parameters:

  • to_agent (string): Target agent ID
  • message_type (string): Event name the receiving agent listens for
  • content (dict): Message payload
  • metadata (dict, optional): Additional message metadata

on_message(message_type, handler)​

Register message handlers for incoming messages.

# Register a handler for specialist queries
self.a2a.on_message("hotel_booking_query", self.handle_specialist_query)

async def handle_specialist_query(self, message):
# Process the incoming message
query = message.content.get("query")
# ... process query ...
# Return response
return {"response": "Current mortgage rates are 6.5%"}

Next Steps​

Now that you're familiar with the core A2A concepts, it's time to move from theory to practice:

👉 Explore the Full A2A Implementation Dive into a complete, working example that demonstrates agent discovery, messaging, and collaboration in action.

Got a Question? Ask us on discord