Agent-to-agent (A2A) with ADK: concepts and a demo peer
Explain A2A concepts, contrast them with app-to-tool connections, and optionally call a fixed, trusted demo peer.
By Invicly Tech, , in Google ADK with Python for AI Agents. About 11 minutes to read.
In short
Agent2Agent (A2A) is an open protocol that lets independent agents, often run by different teams, call each other over HTTP as peers. Each A2A agent publishes an agent card, a JSON file describing its name, skills and endpoint. ADK can expose an agent over A2A with to_a2a() or adk api_server --a2a, and call a remote one with RemoteA2aAgent; for this course it is optional and only used with a fixed, trusted demo peer.
Think of it like this: MCP is your agent picking up a tool from the shelf; A2A is your agent phoning a colleague in another team and asking them to handle a task.
Explained simply
Imagine your support agent could ask a billing agent, built by another team, to explain an invoice. The billing agent has its own model, its own tools and its own deployment. Agent2Agent, or A2A, is an open protocol for exactly this: one agent sending a task to another agent over HTTP.
Each A2A agent publishes an agent card. It is a small JSON file at a well-known address that says the agent's name, what it can do (its skills), and where to send requests. A client reads the card first, then sends tasks.
This is different from MCP. With MCP your agent calls a tool, which simply runs a function. With A2A your agent hands a task to another agent, which thinks for itself and may call its own tools. You get less control over how the answer is produced.
ADK supports both sides. You can serve your agent over A2A, and you can call a remote A2A agent with RemoteA2aAgent as if it were a sub-agent. In this course A2A is optional, and you only call a fixed demo peer that you run yourself on your machine.
Press Play on a diagram to walk through it one step at a time.
- Your agent calls a tool or reads a resource
- The server has no reasoning of its own
- Typed inputs and outputs per tool
- Good for data access and simple actions
- Your agent hands a task to another agent
- The peer plans and uses its own tools
- Described by an agent card with skills
- Good across team or company boundaries
- 1Fetch agent card
From the peer's well-known URL
- 2Check it
Expected name, URL and skills only
- 3Delegate
Root agent hands one task to RemoteA2aAgent
- 4Peer works
Runs its own model and tools
- 5Result returns
Treat it as untrusted data
- One function you own
- Python function tool
- Tool from another team's server
- MCP via McpToolset
- Filter tools, read-only creds
- Agent in the same app
- Sub-agent or AgentTool
- Agent owned and deployed elsewhere
- A2A with RemoteA2aAgent
- Fixed URL, auth, timeouts
In depth
The agent card
An agent card is the A2A agent's public description. With the a2a-sdk versions that google-adk 2.15.1 supports, ADK fetches it from /.well-known/agent-card.json on the peer's base URL (older a2a-sdk releases used /.well-known/agent.json). The card includes a name, description, the url where tasks are sent, a version, capabilities such as whether streaming is supported, default input and output types, and a list of skills.
Each skill has an id, name, description and tags. Skills help a client, or the model in your coordinator agent, decide whether this peer is the right one for a task. They are a description, not a security boundary.
The card can also list security schemes, telling clients how to authenticate. For anything beyond a local demo, the peer should require authentication and your client should send credentials, the same as any service-to-service call.
- name, description, version
- url: where tasks are sent
- capabilities: for example streaming
- skills: id, name, description, tags
- security schemes: how to authenticate
Exposing and consuming with ADK
Install the extra with pip install "google-adk[a2a]==2.15.1". To serve an agent, wrap it with to_a2a(root_agent, port=8001) from google.adk.a2a.utils.agent_to_a2a; it returns an app you run with Uvicorn and builds the agent card for you. Alternatively, adk api_server --a2a --port 8001 serves agent folders that include an agent.json card.
To call a peer, create RemoteA2aAgent(name=..., description=..., agent_card=...) from google.adk.agents.remote_a2a_agent. agent_card can be a URL, a local file path or an AgentCard object. Add it to your root agent's sub_agents, and the coordinator can transfer a task to it like any sub-agent.
Two cautions. A remote call adds network latency and another model's cost on top of yours. And the peer's reply is untrusted: check it against your rules before showing it or acting on it.
- RemoteA2aAgent to Demo peer server: GET agent card1GET agent card
- Demo peer server to RemoteA2aAgent: Card: name, url, skills2Card: name, url, skills
- Root agent to RemoteA2aAgent: Transfer: explain invoice INV-00423Transfer: explain invoice INV-0042
- RemoteA2aAgent to Demo peer server: Send message as an A2A task4Send message as an A2A task
- Demo peer server to RemoteA2aAgent: Task result with text5Task result with text
- RemoteA2aAgent to Root agent: Result returned as events6Result returned as events
Trust: why the demo peer is fixed
An A2A peer is another program that you do not fully control, and its answers come from its own model. That brings three risks. It could be the wrong service, if the URL comes from user input or an unchecked config. It could return text that tries to steer your agent, for example by saying ignore your rules. And it could receive more context than it needs, such as a customer's ticket history.
The course rules are simple. Keep the peer URL in config, not in prompts or user messages. Check the fetched card's name and URL match what you expect before use. Send the peer only the fields the task needs. Treat everything it returns as data, and keep your own tools and scope checks unchanged no matter what it says. For a cross-company peer, add authentication, timeouts and logging like any external API.
When A2A is worth it
A2A earns its cost when the other agent is genuinely separate: a different team owns it, it is deployed and scaled on its own, it is written in another framework or language, or it belongs to a partner company. The protocol gives you a stable contract across that boundary.
It is the wrong tool when everything lives in one codebase and one deployment. There, a sub-agent or a plain function tool does the same job with no network hop, no second auth setup and simpler traces. Many teams also overuse delegation: if the job is one lookup, a tool is faster and cheaper than asking another agent.
A quick test: if you could import the other agent's Python module and call it directly, you probably do not need A2A yet.
Learn it in 5 short steps
About 25m each. Track them with a timer in your plan.
- 1Read an agent card~25m
- 2Compare A2A with MCP~25m
- 3Expose an agent over A2A~25m
- 4Consume a trusted demo peer~25m
- 5Decide when A2A is worth it~25m
Key points
- Install the extra: pip install "google-adk[a2a]==2.15.1".
- An agent card lists name, description, url, version, capabilities and skills.
- RemoteA2aAgent (google.adk.agents.remote_a2a_agent) points at a peer's card and acts like a sub-agent.
- Text that comes back from a peer is untrusted input, just like a web page or user message.
- Use A2A only when the other agent is truly separate; inside one codebase, a sub-agent or tool is simpler.
Key terms
Tap a card to flip it. 0/5 known
Examples
Run a demo peer and read its card
Prerequisites: pip install "google-adk[a2a]==2.15.1" uvicorn, and a tiny billing_agent that answers from fixture invoices such as INV-0042. Step 1: save the code below as peer.py. Step 2: run uvicorn peer:app --port 8001. Step 3: fetch the card. Evidence: JSON with the name billing_agent, a url on port 8001 and at least one skill. Cleanup: stop Uvicorn with Ctrl+C.
# peer.py
from google.adk.a2a.utils.agent_to_a2a import to_a2a
from billing_agent.agent import root_agent # answers from fixture invoices
app = to_a2a(root_agent, port=8001)
# Terminal:
# uvicorn peer:app --port 8001
# curl -s localhost:8001/.well-known/agent-card.json | python -m json.toolConsume the trusted peer from the support agent
The support agent gets a billing sub-agent that lives in another process. The peer URL comes from an environment variable with a safe local default, never from a user message. Run adk web and ask about INV-0042. Evidence: the trace shows a transfer to billing_agent and a response from the peer. Rollback: remove the sub-agent line, and the support agent goes back to saying it cannot answer billing questions.
import os
from google.adk.agents import Agent
from google.adk.agents.remote_a2a_agent import RemoteA2aAgent
PEER = os.environ.get("BILLING_PEER_URL", "http://localhost:8001")
billing = RemoteA2aAgent(
name="billing_agent",
description="Explains synthetic invoices. Read-only.",
agent_card=f"{PEER}/.well-known/agent-card.json",
)
root_agent = Agent(name="support_agent", model="gemini-flash-latest",
instruction="Hand invoice questions to billing_agent.",
tools=[get_ticket_status], sub_agents=[billing])Quick reference
- pip install "google-adk[a2a]==2.15.1" adds A2A support
- Serve: to_a2a(root_agent, port=8001), then run the app with uvicorn
- Or: adk api_server --a2a --port 8001 for folders with an agent.json card
- Consume: RemoteA2aAgent(name=..., agent_card=URL or file or AgentCard)
- Card path in current a2a-sdk: /.well-known/agent-card.json
- MCP: agent calls a tool. A2A: agent hands a task to another agent
- Peer replies are untrusted data; keep the peer URL fixed in config
Common mistakes
- Pointing RemoteA2aAgent at any URL a user supplies; keep the peer URL fixed in config.
- Treating the peer's reply as instructions rather than data to check.
- Reaching for A2A to split one small app into many network services, adding latency for no gain.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Fetch the agent card of your local demo peer and list its skill names.
- Exercise 2medium
Write a check that refuses to start the support agent if the peer's card name or URL is not what you expect.
- Exercise 3hard
Write a short decision record: should the support assistant call billing over A2A, as a sub-agent, or as a tool? Cover ownership, latency, cost, trust and tracing.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- Is A2A the same as MCP?
- No. MCP connects an AI app to tools and data. A2A connects agents to other agents that reason on their own. Many systems use both.
- Do I need Google Cloud to try A2A?
- No. You can run the peer and the client on your own machine with Uvicorn, as in this topic. Gemini calls need an API key or you can use a mock model.
- Can an ADK agent talk to an A2A agent built with another framework?
- Yes, that is the point of a shared protocol. As long as both sides support compatible A2A versions, the client only needs the peer's agent card.