# A2A

The [A2A (Agent2Agent Protocol)](https://a2a-protocol.org/latest/) communication system in AG2 enables agents to communicate across different processes, machines, applications, or even different frameworks and languages. This powerful feature allows you to build distributed agent systems where agents can be deployed as separate services and interact with each other seamlessly.

Consider using A2A when:

- The agent you need to talk to is a **separate, standalone service** (e.g., a specialized financial modeling agent)
- The agent is maintained by a **different team or organization**
- You need to connect agents written in **different programming languages or agent frameworks**
- You want to enforce a **strong, formal contract** (the A2A protocol) between your system's components
- You need **Human in the Loop (HITL)** support for interactive workflows across distributed agents

Note

We are using official [A2A python sdk](https://github.com/a2aproject/a2a-python) to implement A2A in AG2.

You can check their documentation for more details on how to use A2A in your own projects.

## Creating an A2A Server

We've built a convenience wrapper that exposes regular AG2 `ConversableAgent` agents as A2A servers - let's have a quick look at how to use it:

| server.py |
| --- |
| ```<br> 1<br> 2<br> 3<br> 4<br> 5<br> 6<br> 7<br> 8<br> 9<br>10<br>11<br>12<br>13<br>14<br>``` | ```<br>from autogen import ConversableAgent, LLMConfig<br>from autogen.a2a import A2aAgentServer<br># Create your regular agent<br>llm_config = LLMConfig({ "model": "gpt-4o-mini" })<br>agent = ConversableAgent(<br>    name="python_coder",<br>    system_message="You are an expert Python developer...",<br>    llm_config=llm_config,<br>)<br># Create A2A server<br>server = A2aAgentServer(agent).build()<br>``` |

Now you can start it using any ASGI server, for example:

```
uvicorn server:server
```

To read more about how to configure an A2A server, please refer to [A2A Server Setup](https://docs.ag2.ai/0.14.0/docs/user-guide/a2a/server) documentation.

## Creating an A2A Client

| client.py |
| --- |
| ```<br>1<br>2<br>3<br>4<br>5<br>6<br>``` | ```<br>from autogen.a2a import A2aRemoteAgent<br>remote_coding_agent = A2aRemoteAgent(<br>    url="http://localhost:8000",  # your server URL<br>    name="python_coder",<br>)<br>``` |

Now you can use it just like any other `ConversableAgent`:

|     |     |
| --- | --- |
| ```<br> 1<br> 2<br> 3<br> 4<br> 5<br> 6<br> 7<br> 8<br> 9<br>10<br>11<br>12<br>13<br>14<br>15<br>16<br>17<br>18<br>19<br>20<br>``` | ```<br>from autogen import ConversableAgent, LLMConfig<br>from autogen.a2a import A2aRemoteAgent<br>llm_config = LLMConfig({ "model": "gpt-4o-mini" })<br>review_agent = ConversableAgent(<br>    name="reviewer",<br>    system_message="You are a code reviewer...",<br>    llm_config=llm_config,<br>)<br>remote_coding_agent = A2aRemoteAgent(<br>    url="http://localhost:9999",<br>    name="python_coder",<br>)<br>await review_agent.a_initiate_chat(<br>    recipient=remote_coding_agent,<br>    message={"role": "user", "content": prompt},<br>)<br>``` |

Warning

`A2aRemoteAgent` supports only asynchronous methods - this is the limitation of the A2A client we use.

To read more about how to use `A2aRemoteAgent`, please refer to [A2A Client Usage](https://docs.ag2.ai/0.14.0/docs/user-guide/a2a/client) documentation.

## Interoperability with other frameworks

A2A is supported [by other frameworks](https://a2a-protocol.org/latest/community/#a2a-integrations), so you can use `A2aRemoteAgent` with them, too.

As an example, you can easily connect your AG2 agents with [Pydantic AI](https://ai.pydantic.dev/a2a/) agents:

| server.py |
| --- |
| ```<br>1<br>2<br>3<br>4<br>5<br>6<br>7<br>``` | ```<br>from pydantic_ai import Agent<br>agent = Agent(<br>    "openai:gpt-4.1",<br>    instructions="You are an expert Python developer...",<br>)<br>app = agent.to_a2a()<br>``` |

Now, without any changes, your `A2aRemoteAgent` clients can interact with them:

| client.py |
| --- |
| ```<br>1<br>2<br>3<br>4<br>5<br>6<br>7<br>``` | ```<br>from autogen.a2a import A2aRemoteAgent<br># works correctly with other frameworks A2A servers<br>remote_agent = A2aRemoteAgent(<br>    url="http://localhost:8000",<br>    name="python_coder",<br>)<br>``` |
