How to Build A2A Agents#
A2A Protocol is an open standard that defines how two agents can communicate with each other. It covers both the serving and consumption aspects of agent interaction.
In this guide, you will learn how to build an A2A agent with the A2AAgent class from the pyagentspec package.
Basic Usage#
To get started with an A2A agent, you need the URL of the remote server agent you wish to connect to. Once you have this information, creating your A2A agent is straightforward and can be done in just a few lines of code:
from pyagentspec.a2aagent import A2AAgent
# Define the URL endpoint of the remote server agent to connect
# Replace "<IP ADDRESS>" with the actual IP address or hostname of the server agent
SERVER_AGENT_URL = "<IP ADDRESS>"
# Create an A2A Agent instance to communicate with the specified server agent's URL
a2a_agent = A2AAgent(
name="Test A2A Agent",
agent_url=SERVER_AGENT_URL
)
Note that the A2AAgent is an extension of RemoteAgent in Agent Spec, which is considered an AgenticComponent.
It follows that A2A agents can be used in AgentNodes inside Agent Spec flows.
Agent Spec Serialization#
You can export the agent configuration using the AgentSpecSerializer.
from pyagentspec.serialization import AgentSpecSerializer
serialized_assistant = AgentSpecSerializer().to_json(a2a_agent)
Here is what the Agent Spec representation will look like ↓
Click here to see the assistant configuration.
{
"component_type": "A2AAgent",
"id": "f48c79a1-ca6e-4281-b1b0-c8e602ec50e9",
"name": "Test A2A Agent",
"description": null,
"metadata": {},
"inputs": [],
"outputs": [],
"agent_url": "<IP ADDRESS>",
"agentspec_version": "25.4.2"
}
# Copyright © 2025 Oracle and/or its affiliates.
#
# This software is under the Apache License 2.0
# (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) or Universal Permissive License
# (UPL) 1.0 (LICENSE-UPL or https://oss.oracle.com/licenses/upl), at your option.
component_type: A2AAgent
id: f48c79a1-ca6e-4281-b1b0-c8e602ec50e9
name: Test A2A Agent
description: null
metadata: {}
inputs: []
outputs: []
agent_url: <IP ADDRESS>
agentspec_version: 25.4.2
Recap#
This how-to guide covered how to define an A2A Agent in Agent Spec.
Below is the complete code from this guide.
1from pyagentspec.a2aagent import A2AAgent
2
3# Define the URL endpoint of the remote server agent to connect
4# Replace "<IP ADDRESS>" with the actual IP address or hostname of the server agent
5SERVER_AGENT_URL = "<IP ADDRESS>"
6
7# Create an A2A Agent instance to communicate with the specified server agent's URL
8a2a_agent = A2AAgent(
9 name="Test A2A Agent",
10 agent_url=SERVER_AGENT_URL
11)
Next Steps#
Now that you have learned how to build A2A Agents, you can proceed to How to Use the WayFlow Runtime to Execute Agent Spec.