Agent-to-Agent Integration
How Anvio implements Google's A2A Protocol v1.0 — expose your agents to external A2A clients, and delegate tasks to external A2A agents from within Anvio.
6 min read
Anvio implements Google's Agent-to-Agent (A2A) Protocol v1.0 for cross-platform agent interoperability. Shipped in v2.4.0. See ADR-0026 for the architectural decision.
Where MCP connects agents to tools and ACP connects agents to editors, A2A connects agents to other agents — including agents running on completely different platforms.
Protocol concepts
| Concept | Description |
|---|---|
| Agent Card | JSON discovery document at /.well-known/agent.json — describes capabilities, skills, and auth schemes |
| Task | Unit of work with lifecycle states: submitted → working → completed / failed / canceled |
| Message | Multi-part payload (text, file, data) exchanged between agents |
| Artifact | Structured output produced by a task |
| Streaming | Server-Sent Events for real-time task status and artifact updates |
| Push Notifications | Webhook delivery for long-running tasks |
MCP vs A2A vs ACP
| Protocol | Connects | Package | Analogy |
|---|---|---|---|
| MCP | Agent ↔ Tool | packages/integrations | USB peripheral |
| A2A | Agent ↔ Agent | packages/a2a | Network socket |
| ACP | Agent ↔ Editor | packages/acp | IDE extension |
Two surfaces
1. A2A Server — expose Anvio agents
External A2A clients can discover and interact with your Anvio agents via standard endpoints, all routed through the Unified Gateway.
Endpoints:
| Route | Method | Description |
|---|---|---|
/.well-known/agent.json | GET | Agent Card discovery |
/a2a | POST | JSON-RPC 2.0 endpoint |
/a2a/health | GET | Health check |
/a2a/messages | POST | Send message (create/continue task) |
/a2a/messages:stream | POST | Send message with SSE streaming |
/a2a/tasks | GET | List tasks (paginated) |
/a2a/tasks/:id | GET | Get task by ID |
/a2a/tasks/:id:cancel | POST | Cancel a running task |
/a2a/tasks/:id:subscribe | GET | SSE: subscribe to task updates |
JSON-RPC 2.0 methods: sendMessage, sendMessageStream, getTask, listTasks, cancelTask, setPushNotificationConfig, getPushNotificationConfig, deletePushNotificationConfig.
2. A2A Client — delegate to external agents
A2ATool wraps any external A2A agent as an Anvio tool — available in the tool loop like any other tool.
import { A2AClient, A2ATool, AgentDiscovery } from '@anvio/a2a';
const discovery = new AgentDiscovery();
const card = await discovery.discover('https://external-agent.example.com');
const client = new A2AClient({
baseUrl: 'https://external-agent.example.com',
auth: { type: 'bearer', token: 'your-api-key' },
});
const tool = new A2ATool(client, card);
const result = await tool.invoke('Analyze this dataset', 'context-123');
// result: { taskId, status, content }Quick start
Enable the A2A server
The A2A server mounts automatically when you attach it to the platform context during boot:
import { A2AServer } from '@anvio/a2a';
const a2aServer = new A2AServer({
host: '0.0.0.0',
port: 0, // use the gateway's port
agents: loadedAgents,
cardOptions: { baseUrl: 'https://your-domain.com' },
onMessage: async (taskId, message, taskManager) => {
const session = await createSessionFromA2AMessage(message);
const result = await runtime.run(session);
taskManager.updateStatus(taskId, 'completed');
},
});
platformContext.a2aServer = a2aServer;Agent Card auto-generation
Agent Cards are built automatically from your agent's YAML frontmatter:
# workspace/agents/researcher.md
---
persona: Research Agent
description: Finds and summarizes information from multiple sources
skills:
- web-search
- summarize
model:
provider: anthropic
model: claude-sonnet-4-20250514
---This produces /.well-known/agent.json:
{
"agentId": "researcher",
"name": "researcher",
"description": "Finds and summarizes information from multiple sources",
"version": "1.0.0",
"capabilities": {
"streaming": true,
"pushNotifications": true,
"multiTurn": true
},
"skills": [
{ "id": "web-search", "name": "web-search" },
{ "id": "summarize", "name": "summarize" }
],
"interfaces": [
{ "type": "json-rpc", "url": "https://your-domain.com/a2a" },
{ "type": "http+json", "url": "https://your-domain.com/a2a/messages" }
]
}State mapping
Anvio session states map to A2A task states:
Anvio AgentRunStatus | A2A TaskState |
|---|---|
idle | submitted |
calling_model | working |
executing_tool | working |
awaiting_approval | input_required |
completed | completed |
failed | failed |
canceled | canceled |
Streaming
SSE streaming delivers real-time updates during task execution:
POST /a2a/messages:stream
Content-Type: application/json
{"message": {"messageId": "m1", "role": "user", "parts": [{"type": "text", "text": "Hello"}]}}SSE response:
event: status
data: {"taskId": "task_abc", "status": {"state": "working"}, "final": false}
event: artifact
data: {"taskId": "task_abc", "artifact": {"artifactId": "a1", "parts": [{"type": "text", "text": "..."}]}}
event: status
data: {"taskId": "task_abc", "status": {"state": "completed"}, "final": true}Push notifications
For long-running tasks, configure webhook delivery:
curl -X PUT https://your-domain.com/a2a/tasks/task_abc/pushNotificationConfigs \
-H "Content-Type: application/json" \
-d '{
"url": "https://your-callback.com/webhook",
"authentication": { "type": "bearer", "token": "callback-secret" }
}'Authentication
Supported schemes on Agent Cards:
- API Key —
x-api-keyheader - Bearer Token —
Authorization: Bearer <token> - OAuth 2.0 — full OAuth flow with scopes
- OpenID Connect — OIDC discovery
- Mutual TLS — certificate-based
A2AClient supports bearer and apiKey out of the box. For OAuth/OIDC, supply a pre-acquired token.
Architecture
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ External │────▶│ Unified │────▶│ A2A Server │
│ A2A Client │ │ Gateway │ │ (packages/ │
│ │◀────│ │◀────│ a2a) │
└──────────────┘ └──────────────┘ └──────┬───────┘
▼
┌──────────────────┐
│ Anvio Agent │
│ Runtime │
│ (packages/agents)│
└──────────────────┘
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Anvio Agent │────▶│ A2A Tool │────▶│ External │
│ (tool loop) │ │ (A2ATool) │ │ A2A Agent │
│ │◀────│ │◀────│ │
└──────────────┘ └──────────────┘ └──────────────┘Dependency graph — no circular deps:
packages/a2a ──▶ packages/core (types only)
packages/platform ──▶ packages/a2a (optional, duck-typed)
apps/gateway ──▶ packages/a2a (via platform)Package structure
packages/a2a/src/
├── types/ # A2A protocol types
├── server/
│ ├── a2a-server.ts # JSON-RPC 2.0 + REST router
│ ├── task-manager.ts # In-memory task store + state machine
│ ├── agent-card-builder.ts # AgentDefinition → Agent Card
│ ├── sse-stream.ts # SSE response wrapper
│ └── push-notifier.ts # Webhook delivery
├── client/
│ ├── a2a-client.ts # JSON-RPC transport with auth
│ ├── agent-discovery.ts # Agent Card fetch with TTL cache
│ └── a2a-tool.ts # Wraps client as Anvio ToolPort
└── mapping/
├── session-to-task.ts # AgentRunStatus ↔ TaskState
└── message-adapter.ts # ChatMessage ↔ A2A MessageRunning tests
# All A2A tests (31 tests)
npx vitest run packages/a2a/src/
# Individual suites
npx vitest run packages/a2a/src/task-manager.spec.ts # 10 tests
npx vitest run packages/a2a/src/agent-card-builder.spec.ts # 2 tests
npx vitest run packages/a2a/src/mapping.spec.ts # 12 tests
npx vitest run packages/a2a/src/a2a-server.spec.ts # 7 testsRelated
Last updated on