Skip to content

Serving (A2A)

any-agent provides a simple way of serving agents from any of the supported frameworks using the Agent2Agent Protocol (A2A). You can refer to the link for more information on the protocol, as explaining it is out of the scope of this page.

Warning

The A2A protocol is in early stages of development and so is the functionality provided by any-agent here.

You can configuring and serve an agent using the ServingConfig and the AnyAgent.serve method.

Example

Info

Until an official SDK is released (see this issue), you need to install the A2A dependencies as follows:

pip install "git+https://github.com/google/A2A#subdirectory=samples/python"

For illustrative purposes, we are going to define 2 separate scripts, each defining an agent to answer questions about a specific agent framework (either OpenAI Agents SDK or Google ADK):

# google_expert.py
from any_agent import AgentConfig, AnyAgent
from any_agent.config import ServingConfig
from any_agent.tools import search_web

agent = AnyAgent.create(
    "google",
    AgentConfig(
        name="google_expert",
        model_id="gpt-4.1-nano",
        instructions="You must use the available tools to find an answer",
        description="An agent that can answer questions specifically about the Google Agents Development Kit (ADK).",
        tools=[search_web]
    )
)

agent.serve(ServingConfig(port=5001))
# openai_expert.py
from any_agent import AgentConfig, AnyAgent
from any_agent.config import ServingConfig
from any_agent.tools import search_web

agent = AnyAgent.create(
    "openai",
    AgentConfig(
        name="openai-expert",
        model_id="gpt-4.1-nano",
        instructions="You must use the available tools to find an answer",
        description="An agent that can answer questions specifically about the OpenAI Agents SDK.",
        tools=[search_web]
    )
)

agent.serve(ServingConfig(port=5002))

We can then run each of the scripts in a separate terminal and leave them running in the background.

There are multiple options to interact with these agents. We are going to use the example demo UI and follow the instructions to get it running.

With the UI running, we can register the 2 new that are being served using their corresponding URLs:

Google Expert Card

OpenAI Expert Card

Now that the agents are registered, we can interact with the "host" agent that will (hopefully) redirect the request to the appropriate expert:

Host Agent Conversation