The A2A specification is still evolving. Anvil isolates all protocol logic behind an adapter layer (
A2AServer and a2aHttpHandler), so spec updates require changes only to the adapter — not to your agent definitions.What is A2A?
Agent2Agent (A2A) is an open protocol proposed by Google for standardized communication between AI agents. It allows one agent to call another agent’s capabilities using a JSON-RPC 2.0 transport. Agents advertise their skills via an Agent Card — a JSON document served at a well-known URL — and callers discover and invoke those skills via themessage/send method.
Anvil’s implementation covers:
- Agent Card — served at
/.well-known/agent-card.json(and the alias/agent.json) so external agents can discover your skills message/send— synchronous task execution; calls the target skill and returns a completed Task artifacttasks/get— retrieve a previously created task by ID
Setting up an A2A server
1
Create an AgentRegistry with your agents
A2AServer dispatches incoming A2A requests to agents by skill ID. Each skill ID must match a registered agent name.2
Create the A2AServer
3
Mount the HTTP handler
a2aHttpHandler returns a standard fetch-compatible handler you can mount directly in your Anvil app.A2AServer API
Constructor options
A2AServerOptions
A2AServerOptions
server.agentCard()
Returns the AgentCard object that describes this server’s capabilities. The HTTP handler serves this automatically at the card path.
server.handle(message)
Process a raw JSON-RPC 2.0 request object. Returns a JSON-RPC response or null for notifications (requests with no id). You can call this directly if you are integrating with a custom transport.
Supported JSON-RPC methods
Any other method returns a
-32601 Unknown method error.
AgentCard and skill discovery
External agents discover your capabilities by fetching the Agent Card from/.well-known/agent-card.json. Anvil serves it automatically:
A2ASkill fields
a2aHttpHandler options
One definition, three protocols
BecauseA2AServer wraps the same AgentRegistry your application already uses, enabling A2A requires only a few extra lines — your agent logic and tools are defined once and reused: