What Is Google’s New Agent2Agent (A2A) Protocol and How Does It Enable AI Agent Interoperability?
This article explains the motivation behind Google’s Agent2Agent (A2A) protocol, describes its architecture and key components, compares it with the MCP protocol, and provides a step‑by‑step demo with code showing how to build, run, and test an A2A‑enabled AI agent system.
Why A2A Was Created
Integrating multiple AI agents—often built with different vendors, platforms, and frameworks—requires extensive API glue code, handling diverse message formats, and managing long‑running or multi‑turn tasks. A2A was introduced to provide a standard, low‑coupling way for heterogeneous agents to communicate, share information, and delegate work.
What Is A2A?
A2A (Agent2Agent) is an open protocol that defines a common “language” for agents to interact. It enables agents to publish their capabilities, discover each other, exchange messages, and return final results (artifacts) regardless of the underlying implementation.
A2A Architecture
The architecture consists of several core components:
Agent Card : a metadata “business card” describing an agent’s abilities.
A2A Server : a web server exposing endpoints for clients to send tasks and receive notifications.
A2A Client : any agent or application that consumes the server’s API.
Task : a unit of work submitted by a client.
Artifact : the final output of a task (text, image, video, etc.).
Messages : intermediate communication between client and server, supporting multi‑turn dialogue.
Notifications : optional push messages from server to client about task progress.
The typical flow is: the server registers an Agent Card, the client reads the card, sends a task, receives streaming messages, and finally receives an artifact. The process can be synchronous or asynchronous.
Relation to MCP
MCP (Model‑Centric Protocol) focuses on integrating an agent with external tools and data (agent‑internal integration), while A2A targets agent‑to‑agent integration (higher‑level coordination). The two protocols are complementary and can coexist in a system that uses MCP for tool access and A2A for inter‑agent collaboration.
Scope : MCP = agent ↔ tools; A2A = agent ↔ agent.
Architecture : Both use a client/server model and JSON‑RPC 2.0 over HTTP, but MCP also supports local stdio.
Service capabilities : A2A exposes agent cards; MCP exposes tool listings.
Demo Walkthrough
Below is a minimal LangGraph agent that implements invoke (non‑streaming) and stream (streaming) methods. The agent’s system instruction tells it to use a search_tavily tool.
...
@tool
def search_tavily(query: str, search_depth: str = "basic") -> Dict[str, Any]:
...
class ResponseFormat(BaseModel):
"""以这种格式回应用户。"""
status: Literal["input_required", "completed", "error"] = "input_required"
message: str
class SearchAgent:
SYSTEM_INSTRUCTION = (
"你是一个专门进行网络搜索的助手。"
"你的主要目的是使用'search_tavily'工具来回答用户问题,提供最新、最相关的信息。"
"如果需要用户提供更多信息来进行有效搜索,将响应状态设置为input_required。"
"如果处理请求时发生错误,将响应状态设置为error。"
"如果请求已完成并提供了答案,将响应状态设置为completed。"
)
def __init__(self):
...
def invoke(self, query, sessionId) -> str:
...
async def stream(self, query, sessionId) -> AsyncIterable[Dict[str, Any]]:
...Next, the A2A server is started. It declares capabilities, creates a skill, builds an AgentCard, configures push‑notification authentication, and launches the server (e.g., via uvicorn).
def main(host, port):
try:
capabilities = AgentCapabilities(streaming=True, pushNotifications=True)
skill = AgentSkill(
id="search_web",
name="搜索工具",
description="搜索web上的相关信息",
tags=["Web搜索", "互联网搜索"],
examples=["请搜索最新的黑神话悟空的消息"]
)
agent_card = AgentCard(
name="搜索助手",
description="搜索Web上的相关信息",
url=f"http://{host}:{port}/",
version="1.0.0",
defaultInputModes=SearchAgent.SUPPORTED_CONTENT_TYPES,
defaultOutputModes=SearchAgent.SUPPORTED_CONTENT_TYPES,
capabilities=capabilities,
skills=[skill]
)
notification_sender_auth = PushNotificationSenderAuth()
notification_sender_auth.generate_jwk()
server = A2AServer(
agent_card=agent_card,
task_manager=AgentTaskManager(agent=SearchAgent(), notification_sender_auth=notification_sender_auth),
host=host,
port=port,
)
server.app.add_route("/.well-known/jwks.json", notification_sender_auth.handle_jwks_endpoint, methods=["GET"])
logger.info(f"正在启动服务器,地址:{host}:{port}")
server.start()
except MissingAPIKeyError as e:
logger.error(f"错误:{e}")
exit(1)
except Exception as e:
logger.error(f"服务器启动过程中发生错误:{e}")
exit(1)
if __name__ == "__main__":
main()The client uses the official CLI to discover the Agent Card, submit a task, and receive streaming messages and the final artifact. Demonstrated capabilities include:
Multi‑turn dialogue (the server returns input_required when more information is needed).
Server‑initiated notifications (the client can run a local server to receive push messages).
Asynchronous result retrieval (tasks can be polled by ID after the client disconnects).
Conclusion
A2A offers a standardized, low‑coupling approach for AI agents to interoperate, supporting capabilities publishing, streaming, multi‑turn conversations, and asynchronous task handling. Although still early, it shows promise as a replacement for custom FastAPI‑style integrations in enterprise AI systems.
AI Large Model Application Practice
Focused on deep research and development of large-model applications. Authors of "RAG Application Development and Optimization Based on Large Models" and "MCP Principles Unveiled and Development Guide". Primarily B2B, with B2C as a supplement.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
