a2a-protocol
它能做什么
这项技能指导构建遵循 Google 开放的 Agent2Agent 协议进行通信的智能体。它适合希望其智能体与基于其他框架构建的智能体相互发现并交换任务的开发者。
适用场景
- ✓当你希望通过 Agent Card 让你的智能体可被发现时。
- ✓当两个基于不同框架构建的智能体需要交换任务的时候。
- ✓当你需要智能体之间的流式响应或推送通知的时候。
技能链接
https://github.com/internet-court/internet-court-skill/blob/main/vendored/terminalskills/a2a-protocol/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“你能帮我把我的 Python 智能体改造成带有 Agent Card 的 A2A 服务器,让其他智能体可以向它发送任务吗?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会编写描述智能体技能和端点的 Agent Card,然后通过 JSON-RPC 实现任务生命周期。它可以添加流式传输和推送通知,客户端则遵循同一协议调用服务器。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
A2A Protocol
Overview
Implements the Agent2Agent (A2A) open protocol for communication between AI agents built on different frameworks. A2A enables agents to discover each other via Agent Cards, negotiate interaction modalities, manage collaborative tasks, and exchange data — all without exposing internal state, memory, or tools. Supports JSON-RPC 2.0 over HTTP(S), streaming via SSE, gRPC, and async push notifications.
Instructions
1. Core Concepts
- A2A Client: Initiates requests to an A2A Server (on behalf of a user or another agent)
- A2A Server (Remote Agent): Exposes an A2A-compliant endpoint, processes tasks
- Agent Card: JSON metadata at
/.well-known/agent.jsondescribing identity, capabilities, skills, endpoint, auth - Task: Unit of work with lifecycle (submitted → working → input-required → completed/failed/canceled/rejected)
- Message: Communication turn (role: "user" or "agent") containing Parts (text, file, or JSON)
- Artifact: Output generated by the agent (documents, images, structured data)
2. Python SDK Setup
pip install a2a-sdk # Core
pip install "a2a-sdk[http-server]" # With FastAPI/Starlette
pip install "a2a-sdk[grpc]" # With gRPC
3. Building an A2A Server (Python)
from a2a.types import AgentCard, AgentSkill, AgentCapabilities
from a2a.server.agent_execution import AgentExecutor, RequestContext
from a2a.server.events import EventQueue
from a2a.server.apps.starlette import A2AStarletteApplication
from a2a.server.request_handler import DefaultRequestHandler
from a2a.types import Message, TextPart, TaskState, TaskStatus
import uvicorn
agent_card = AgentCard(
name="Research Assistant",
description="Searches the web and answers questions with citations.",
url="https://research-agent.example.com",
version="1.0.0",
capabilities=AgentCapabilities(streaming=True, pushNotifications=True),
skills=[AgentSkill(
id="web-search", name="Web Search",
description="Search the web for current information",
tags=["search", "research"], examples=["Find the latest news about AI regulation"],
)],
defaultInputModes=["text/plain"],
defaultOutputModes=["text/plain", "application/json"],
)
class ResearchAgentExecutor(AgentExecutor):
async def execute(self, context: RequestContext, event_queue: EventQueue):
query = context.get_user_message().parts[0].text
await event_queue.enqueue_event(
TaskStatus(state=TaskState.working, message=Message(
role="agent", parts=[TextPart(text="Searching...")]
))
)
result = await self._research(query)
await event_queue.enqueue_event(
TaskStatus(state=TaskState.completed, message=Message(
role="agent", parts=[TextPart(text=result)]
))
)
async def cancel(self, context: RequestContext, event_queue: EventQueue):
await event_queue.enqueue_event(TaskStatus(state=TaskState.canceled))
async def _research(self, query: str) -> str:
return f"Research results for: {query}"
# Start server — Agent Card auto-served at /.well-known/agent.json
agent_executor = ResearchAgentExecutor()
request_handler = DefaultRequestHandler(agent_executor=agent_executor, task_store=InMemoryTaskStore())
app = A2AStarletteApplication(agent_card=agent_card, http_handler=request_handler)
uvicorn.run(app.build(), host="0.0.0.0", port=8000)
4. Building an A2A Client (Python)
from a2a.client import A2AClient
from a2a.types import MessageSendParams, SendMessageRequest, Message, TextPart
client = await A2AClient.get_client_from_agent_card_url(
"https://research-agent.example.com/.well-known/agent.json"
)
# Synchronous request
request = SendMessageRequest(params=MessageSendParams(
message=Message(role="user", parts=[TextPart(text="Latest quantum computing developments?")])
))
response = await client.send_message(request)
if hasattr(response, 'status'):
print(f"Task {response.id}: {response.status.state}")
if response.status.message:
print(response.status.message.parts[0].text)
# Streaming response
async for event in client.send_message_streaming(request):
if hasattr(event, 'status') and event.status.message:
for part in event.status.message.parts:
if hasattr(part, 'text'):
print(part.text, end="", flush=True)
5. Node.js SDK
np
常见问题
该协议会暴露内部记忆吗?
不会。该技能说明,A2A 不会暴露内部状态、记忆或工具。
它使用哪个 Python 包?
该技能展示了安装 a2a-sdk 包的方法,并提供 HTTP 和 gRPC 选项。
Agent Card 放在哪里?
该技能说明,它以 JSON 形式在 well-known 智能体路径下提供。
详情
作者的原始描述
Builds Agent-to-Agent (A2A) servers and clients following Google's open protocol for agent interoperability. Use when the user wants to create an A2A-compliant agent, build an Agent Card, implement task management, connect agents across frameworks, set up agent discovery, handle streaming responses, implement push notifications, or orchestrate multi-agent workflows. Trigger words: a2a, agent to agent, agent2agent, a2a protocol, a2a server, a2a client, agent card, agent interoperability, agent collaboration, multi-agent, agent discovery, a2a sdk, a2a task.
热度
- GitHub 星标
- 7.0k
- 排名
- #13690
- 许可证
- —
- 更新时间
- 2026/10/26
评论
- …
同一仓库的更多技能
internet-court
7.0k帮你的智能体安全地向其他 AI 智能体或付费服务付款、雇用或进行交易,并指引它找到合适的专业指南。
genlayer-erc7710-connector
7.0k帮你的智能体把 AI 审核结果与权限系统连接起来,使不合格的审核可以限制或取消智能体的权限。
genlayer-intelligent-contracts
7.0k帮你的智能体定义 AI 裁判的规则、证据和输出,用于检查另一个智能体是否遵循了其授权范围。
x402-erc7710
7.0k帮你的智能体按次为网络服务付款,并设置在权限预算范围内的持续支出。