Skip to main content
A2A (Agent2Agent) lets agents built on different frameworks call each other over HTTP. This guide serves a Swarms agent as an A2A agent with A2AServer, then calls it with A2AClient, with curl, and as a handoff target from another agent. Reference: A2AServer and A2AClient.

Install

A2AServer and A2AClient need nothing else.

1. Serve an agent

Save this as server.py and run it. It serves the agent on port 8000 and accepts one API key.
The agent’s agent_description becomes the description other agents see, so make it say what the agent is good at. output_type="final" matters for a served agent. One agent answers every request and keeps its conversation between them, and the default output_type returns that history. Without it, the second caller’s reply would start with the first caller’s question and answer. See Keep callers apart to stop requests sharing context at all.
A2AServer refuses to start without auth. Pass api_keys, api_key_env, auth or token_verifier, or allow_anonymous=True for a local experiment.

2. Look at the agent card

The card is public, so any client can find out what the agent does before calling it:
The card’s name is a snake_case form of the agent’s name. Pass name="Researcher" to A2AServer to show a different one.

3. Call it from Python

In a second terminal:
A2AClient reads the card when it is built, so the server must already be running. run() sends one SendMessage request and returns the reply as a string.

4. Call it from any language

The endpoint is plain JSON-RPC, so anything that can send HTTP can call it. Every request needs the A2A-Version: 1.0 header and the key, either as x-api-key or as Authorization: Bearer:
The answer is in result.message.parts[0].text:

5. Server and client in one script

A2AServer is a context manager: the with block starts the server in a background thread and stops it on exit. That makes a self-contained script, or a test:

6. Hand tasks off to a remote agent

An A2AClient has an agent_name, an agent_description and a run() method, so it can go in an agent’s handoffs next to local agents. With the server from step 1 running:
The coordinator sees researcher and its description in its handoff prompt, calls handoff_task, and the request goes over A2A. To give the remote agent a different local name, pass agent_name= and agent_description= to A2AClient.

7. Serve a whole swarm

The target can be any structure with run(task). Give it output_type="final" so the reply is the final answer rather than the whole conversation:
Callers see one agent named writing_team with the workflow’s description. They don’t need to know a team is behind it.

8. Keep callers apart

The server runs one target instance for every request, from every caller. An Agent remembers each task it was given, so later requests see earlier ones, and requests that arrive together run on separate threads against the same agent. When callers must not share context, serve a function that builds a fresh agent for each request:
The card is named after the function, research, and its description is the first line of the docstring.

9. Keys from the environment

Keep keys out of code with api_key_env. It reads a comma-separated list, so you can rotate keys without downtime:
host="0.0.0.0" listens on every interface, for a server other machines call. Run it behind HTTPS in production. For tokens checked against your own identity provider, see Auth on the MCPDeployer page; A2AServer takes the same options.

10. Handle errors

11. MCP on the same port

A2AServer extends MCPDeployer, so the same process also serves the agent as an MCP tool at /mcp, with a public health check at /health. One deployment reaches both A2A agents and MCP clients such as Claude Desktop or another Swarms agent with mcp_url.

Next steps