The A2A client allows you to connect to remote A2A agent servers and interact with them as if they were local agents. This guide covers everything you need to know about using A2A clients.
Warning
A2aRemoteAgent supports only asynchronous methods - this is the limitation of the A2A client we use.
Generally, you can use A2aRemoteAgent like any other ConversableAgent. In the example below, we specify a remote agent and start a chat between a local agent and that remote agent, asking them to generate code.
fromautogen.a2aimportA2aRemoteAgent# Connect to a remote agentremote_agent=A2aRemoteAgent(url="http://localhost:8000",name="python_coder")# Use it like any other agentawaitlocal_agent.a_initiate_chat(recipient=remote_agent,message={"role":"user","content":"Create a calculator function",})
Here's another example of a A2aRemoteAgent client agent working with a local agent, with the conversation printed out afterwards.
importasynciofromautogenimportConversableAgent,LLMConfigfromautogen.a2aimportA2aRemoteAgent# Configure local agentllm_config=LLMConfig({"model":"gpt-4o-mini"})reviewer=ConversableAgent(name="code_reviewer",system_message="You are a code reviewer...",llm_config=llm_config,)# Connect to remote agentcoder=A2aRemoteAgent(url="http://localhost:8000",name="python_coder")# Start conversationasyncdefreview_code():awaitreviewer.a_initiate_chat(recipient=coder,message={"role":"user","content":"Create a Python calculator"})# Process the responsemessages=reviewer.chat_messages[coder.name]formessageinmessages:print(f"{message['name']}: {message['content']}")# Run the conversationasyncio.run(review_code())
Commonly, you will need to set some custom options on the remote agent's HTTP client, such as headers, timeout, etc. To do this, pass your own HttpxClientFactory instance to the A2aRemoteAgent constructor.
The A2A client has a few configuration options that you can pass to the A2aRemoteAgent constructor, use the client_config parameter and a ClientConfig to do that.
fromautogen.a2aimportA2aRemoteAgent# works correctly with other frameworks A2A serversremote_agent=A2aRemoteAgent(url="http://localhost:8000",name="python_coder",)