Skip to main content

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:
  • A2AServer serves an Agent, any structure with a run(task) method, or a plain function, as an A2A agent. It publishes a public agent card and answers SendMessage requests.
  • A2AClient reads a remote agent’s card and runs tasks on it. It has an agent_name, an agent_description and a run(task) method, so it works anywhere a local agent does, including as a handoff target.
For a walkthrough, see the A2A quickstart.

Import

Both come with 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

Any | List[Any] | Dict[str, Any]
required
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.
str
default:"/.well-known/agent-card.json"
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.
str
default:"/a2a"
Where the JSON-RPC SendMessage endpoint is served. The card advertises its full URL.
str
default:"1.0"
The A2A version shown on the card and required in every request’s A2A-Version header.
str
default:"1.0.0"
The version of your agent, shown on the card as version.
Optional[Dict[str, Any]]
default:"None"
The card’s capabilities object. None shows {}. The server does not stream or push, so don’t advertise either.
Sequence[str]
default:"(\"text/plain\",)"
Media types the agent accepts, shown as defaultInputModes.
Sequence[str]
default:"(\"text/plain\",)"
Media types the agent returns, shown as defaultOutputModes.
Optional[List[Dict[str, Any]]]
default:"None"
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.
Any
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’s name and description come from the deployer: For the Researcher agent in the quickstart, GET /.well-known/agent-card.json returns:
The interface URL is built from the request, so it shows the host and port the client used. Behind a proxy that mounts the app under a prefix, the prefix is included.

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 the A2A-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.
The reply is a single agent message, with the target’s output as its only text part:
The output is whatever the target’s 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.
One target instance answers every request, from every caller. An Agent keeps its conversation between calls, so with the default output_type the second caller’s reply starts with the first caller’s question and answer, and every request is answered in the context of the ones before it. Set output_type="final", and when callers must not share context, serve a function that builds a fresh agent per request, as shown in Keep callers apart.

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 Task object, so GetTask, CancelTask and 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 Agent keeps one memory for all callers. See the warning under SendMessage and State between calls.
  • With several targets, A2A serves the first. Run one A2AServer per 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

The constructor fetches the agent card from url + card_path right away, so the remote server must be running when you build the client.
str
required
The remote agent’s base URL, such as http://127.0.0.1:8000. A trailing slash is ignored.
Optional[str]
default:"None"
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.
Optional[httpx.BaseTransport]
default:"None"
The httpx transport, for example httpx.HTTPTransport(retries=3) to retry failed connections, or httpx.MockTransport in tests.
float
default:"300.0"
Seconds to wait for each request, the card fetch included. A model call on the server can take a while, so keep this generous.
Optional[Dict[str, str]]
default:"None"
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.
str
default:"/.well-known/agent-card.json"
Where the card lives under url.
str
default:"1.0"
The A2A version sent in the A2A-Version header. The card must advertise a JSON-RPC interface with this version.
Optional[str]
default:"None"
The name to use locally instead of the card’s name. Useful for handoffs, where the model addresses targets by name.
Optional[str]
default:"None"
The description to use locally instead of the card’s description.

Attributes

run()

Send one task to the remote agent and return its reply.
The task goes out as one SendMessage request with a single text part. The return value is:
  • for a message reply, its text parts, joined with newlines;
  • for a task reply in state TASK_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’s handoffs 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.
If the remote call fails, the model gets the error as the handoff’s result instead of the run crashing. See Agent Handoffs and Task Delegation.