Book a free call

How to Implement the A2A Protocol Step by Step

To implement A2A, give each agent a card, a task endpoint and a shared message format, then add authentication and retries so agents can work together.

Hertiv engineering teamReviewed by a senior engineer
7 min read
How to Implement the A2A Protocol Step by Step
On this page

Short answer

To implement the A2A protocol, give each agent a public agent card describing its skills, expose a task endpoint that accepts standard task messages, and use the shared JSON format for sending tasks, updates and results. Then add authentication, error handling and a way to watch tasks in progress, and test with one pair of agents before connecting the rest.

What is the A2A protocol?

The A2A protocol, short for Agent-to-Agent, is a standard way for AI agents built by different teams to work together. It defines how one agent finds another, how it sends a task, and how the other agent reports progress and results. Without a shared protocol, every pair of agents needs custom integration work; with A2A, an agent built by one team can call an agent built by another using the same message format.

Three ideas carry most of the design. The agent card is a public document that says what an agent can do and where to reach it. The task is the unit of work: one agent sends a task, the other works on it and sends back updates and a result. The message format is standard JSON, so any programming language can read and write it.

Piece What it does Who provides it
Agent card Lists skills and endpoint Each agent
Task message Carries the work request The calling agent
Task endpoint Receives tasks over HTTP Each agent
Status updates Reports progress while working The working agent
Result message Returns the finished work The working agent
Authentication Proves who is calling Both sides

A2A does not replace the agent itself. It only standardises the conversation between agents, so the hard work, such as reasoning, tool use and data access, stays inside each agent. For the basics, what is the A2A protocol explains the design and the message flow.

The pieces you need before you start

Before writing any A2A code, list the agents that will talk to each other and what each one can do. A travel agent that books flights and a finance agent that approves spending are a natural pair; two agents that do the same job are not. The agent card for each one should state its skills in plain words, because the calling agent uses that description to decide whether to send a task.

Next, decide how tasks will be identified and tracked. Every task needs an ID that both sides can quote, so a status update or a result can be matched to the right request. Without IDs, a system with more than a few tasks in flight becomes impossible to debug. A simple store, such as a database table or a queue, holds the task state while the work runs.

Authentication comes before the first real task. Agents should prove who they are, usually with a token or a signed request, and each agent should only accept tasks from callers it trusts. An endpoint that accepts tasks from anyone will be found and abused. MCP vs A2A explains how A2A differs from the tool protocol most agents already use.

How to implement A2A in six steps

Implementing A2A is a sequence of small, testable steps. Build the card and the endpoint first, then add the task flow, then the safety checks. Each step can be tested on its own, which keeps the debugging simple.

  1. Write the agent card: name, description, skills, and the URL of the task endpoint.
  2. Build the task endpoint: accept a task message, store it with an ID, and return an acknowledgement.
  3. Implement the task loop: work on the task, send status updates, and return a result message when done.
  4. Add authentication: check a token or signature on every incoming task, and sign outgoing calls.
  5. Add retries and timeouts: retry a failed send a small number of times, then report the failure.
  6. Connect the first pair of agents and test end to end, then add the next pair.

Keep the first version simple. A task endpoint that accepts a message, does the work and returns a result is enough to prove the design. Streaming updates, cancellation and long-running tasks can wait until the basic flow is working. AI agent development covers the agent design that sits behind the protocol.

Example (hypothetical): two agents booking a trip

Example (hypothetical): a company has a travel agent and a finance agent. An employee asks the travel agent to book a trip costing no more than $1,200. The travel agent finds a flight for $780 and a hotel for $320, a total of $1,100, and sends a task to the finance agent asking for approval.

The finance agent checks the budget, approves $1,100, and sends the result back. The travel agent then books both, and the whole exchange takes four messages.

Now suppose the hotel price rises to $450 while the finance agent is checking. The total becomes $1,230, which is over the $1,200 limit. The finance agent rejects the task with the reason in the result message, and the travel agent searches for a cheaper hotel instead of booking an over-budget trip. The arithmetic is simple, and it shows why the result message must carry the reason, not just a yes or no.

The same pattern works for any pair of agents: one asks, the other checks and answers, and the first acts on the answer. If a step is missing, such as the approval, the trip either never gets booked or gets booked without a check. Both failures are worse than a slow booking.

Testing agent-to-agent calls

Test A2A with two agents and one task before connecting anything else. Send a task, watch the status updates arrive, and check the result message. Then test the failure cases: the other agent is down, the task is malformed, the result never comes. Each failure should produce a clear error, not a silent hang.

Log every task with its ID, the sender, the receiver, the time sent and the time the result arrived. When a task goes missing, the log is the only way to find out where it stopped. A task that times out after 30 seconds should be visible in the log as a timeout, not as a task that simply never finished.

Test with slow and fast agents. A task that takes five minutes needs status updates, or the caller will assume it failed and send it again. A task that takes two seconds does not. Set the timeout and the retry rules per task type, not one global value for everything.

Security, identity and keeping tasks safe

Security in A2A starts with identity. Each agent should have its own credential, and each endpoint should check it on every call. A shared password for all agents means one leak compromises the whole system. Rotate credentials regularly, and revoke them immediately when an agent is retired.

Limit what each agent can ask for. A travel agent should be able to ask the finance agent for approval, not for a full budget dump. The agent card should state what the agent offers, and the endpoint should reject tasks outside that list. That limit is what keeps a compromised agent from doing wide damage.

Keep task data minimal. A task message should carry only what the other agent needs to do the work, not the full history of the conversation that led to it. Sensitive data, such as payment details, should stay with the agent that owns it, and the result should carry a reference rather than the data itself. For the cost side of running agents, A2A protocol cost covers what to budget for.

What are the common mistakes?

The most common mistakes in A2A implementation are skipping the agent card, having no timeouts, and trusting every caller. Each one is avoidable.

  • No agent card. Without a card, other agents cannot find what yours does; write the card before the endpoint.
  • No timeouts. A task that never returns will hang the caller; set a timeout and a retry limit per task type.
  • Trusting every caller. An open endpoint will be found and abused; check credentials on every task.
  • No task IDs. Without IDs, status updates cannot be matched to tasks; store every task with an ID.
  • Skipping the failure tests. The happy path is the easy part; test the down, slow and malformed cases first.

Key takeaways

  • The agent card, task endpoint and shared message format are the core of A2A
  • Build the card and endpoint first, then the task flow, then safety checks
  • Every task needs an ID so updates and results can be matched to it
  • Check credentials on every call and limit what each agent can request
  • Test the failure cases first: down, slow and malformed calls

Frequently asked questions

What is the A2A protocol?

A2A, short for Agent-to-Agent, is a standard way for AI agents built by different teams to work together. It defines how one agent finds another, sends a task, and receives progress updates and results, using a shared JSON message format.

How is A2A different from MCP?

MCP connects an agent to tools and data sources, while A2A connects one agent to another. An agent can use MCP to call a tool and A2A to ask another agent to do a whole task. The two protocols cover different parts of the same system.

Do I need a special framework to implement A2A?

No. A2A is a message format over HTTP, so any language that can send JSON can implement it. The work is in the agent card, the task endpoint, authentication and error handling, not in a specific library.

How long does an A2A implementation take?

A basic two-agent setup with a card, an endpoint and task flow usually takes a few weeks. Authentication, retries, monitoring and scaling to more agents take longer, because each pair needs its own testing.

What happens if the other agent goes down?

The calling agent should get a clear error after a timeout, not a silent hang. Set a timeout per task type, retry a small number of times, then report the failure so a human or another agent can act on it.

Is A2A secure by default?

No. A2A defines the message format, not the security. Each agent needs its own credentials, every endpoint must check them, and task messages should carry only the data the other agent needs.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: AI and agent systems in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Building agents that need to work together? Talk to Hertiv.

A senior engineer replies within one business day. Or see our AI Agent Development service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to [email protected].

Prefer email? Write to [email protected]
Estimate costBook a call