Overview
A2A (Agent2Agent) is an open protocol for agents built by different teams, on different frameworks, to call each other over HTTP. Swarms speaks A2A version 1.0 over its JSON-RPC binding, in both directions:A2AServerserves anAgent, any structure with arun(task)method, or a plain function, as an A2A agent. It publishes a public agent card and answersSendMessagerequests.A2AClientreads a remote agent’s card and runs tasks on it. It has anagent_name, anagent_descriptionand arun(task)method, so it works anywhere a local agent does, including as a handoff target.
Import
pip install -U swarms. The server runs on the mcp package’s HTTP stack, and the client uses httpx; both are core dependencies.
A2AServer
A2AServer is an MCPDeployer with two extra routes. The same process and port keep serving the target as an MCP tool at /mcp, with the health check at /health, so one server answers both MCP and A2A clients.
Constructor
What to serve: an
Agent, any structure with run(task), or a callable that takes the task string. A list or a {tool name: target} dict serves several as MCP tools, but A2A answers with the first one only. See How a target becomes a tool.Where the agent card is served. It is added to
public_paths, so it never needs a key. Clients find the card at this path by default.Where the JSON-RPC
SendMessage endpoint is served. The card advertises its full URL.The A2A version shown on the card and required in every request’s
A2A-Version header.The card’s
capabilities object. None shows {}. The server does not stream or push, so don’t advertise either.The card’s
skills list. None shows one skill built from the first target: its tool name as id and name, its description, and its class name as the only tag.Every
MCPDeployer option: name, description, tool_name, host, port, api_keys, api_key_env, api_key_header, auth, token_verifier, required_scopes, allow_anonymous, public_paths, timeout, verbose, show_banner and the rest. As with MCPDeployer, a server with no auth configured raises ValueError unless allow_anonymous=True.What the card says
The card’sname and description come from the deployer:
For the
Researcher agent in the quickstart, GET /.well-known/agent-card.json returns:
Endpoints
Auth is the deployer’s: a key from
api_keys or api_key_env, sent in the x-api-key header (or the header named by api_key_header) or as Authorization: Bearer <key>; or your own auth callable or token_verifier. A request without valid credentials gets HTTP 401 with {"error": "unauthorized"}. See Auth, in order of precedence.
SendMessage
Every request needs theA2A-Version: 1.0 header. The server reads the text parts of params.message, joins them with newlines, and runs the target on that text as the task.
run returns, turned into text: a string as is, anything else as indented JSON. An Agent, a SequentialWorkflow and most other structures return their history by default, so serve them with output_type="final" to reply with only the final answer.
Errors
JSON-RPC errors are sent with HTTP status
200, as {"jsonrpc": "2.0", "id": ..., "error": {"code": ..., "message": ...}}.
Running it
A2AServer inherits the deployer’s lifecycle:
See Methods on the MCPDeployer page.
Limits
- Text in and text out. Non-text parts are ignored, and a message with no text part is an error.
- One reply message per request. There is no streaming, no push notification and no
Taskobject, soGetTask,CancelTaskand the other A2A methods return-32601. - The target runs once per message, like an MCP tool call, and there is no A2A context or session: a served
Agentkeeps one memory for all callers. See the warning under SendMessage and State between calls. - With several targets, A2A serves the first. Run one
A2AServerper agent, on its own port, to put several agents on A2A.
A2AClient
A2AClient is a remote A2A agent that you run like a local one.
Constructor
url + card_path right away, so the remote server must be running when you build the client.
Sent as
Authorization: Bearer <api_key> on every request, the card included. A2AServer accepts it. Leave it None for a server that allows anonymous calls.The
httpx transport, for example httpx.HTTPTransport(retries=3) to retry failed connections, or httpx.MockTransport in tests.Seconds to wait for each request, the card fetch included. A model call on the server can take a while, so keep this generous.
Extra headers sent on every request, such as
{"x-api-key": "..."} for a server that reads a different header, or a tracing header. They override the defaults when the names match.The A2A version sent in the
A2A-Version header. The card must advertise a JSON-RPC interface with this version.The name to use locally instead of the card’s
name. Useful for handoffs, where the model addresses targets by name.Attributes
run()
Send one task to the remote agent and return its reply.SendMessage request with a single text part. The return value is:
- for a
messagereply, its text parts, joined with newlines; - for a
taskreply in stateTASK_STATE_COMPLETED, the text of its artifacts, one per line.
Errors
Servers that speak only A2A 0.3, with the
message/send method, are not supported.
Remote agents as handoffs
An agent’shandoffs take any object with agent_name, agent_description and run(task), so an A2AClient can be a handoff target next to local agents. The model sees the remote agent’s name and description from its card in the handoff prompt, and delegates to it through the usual handoff_task tool.
Related
- A2A quickstart
- MCPDeployer, which
A2AServerextends - A2A protocol specification
- Source: a2a_server.py and a2a_client.py