How to Connect to 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 connect to a remote agent using this protocol with the A2AAgent
class from the wayflowcore 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 wayflowcore.a2a.a2aagent import A2AAgent, A2AConnectionConfig
agent = A2AAgent(
agent_url="http://<URL>",
connection_config=A2AConnectionConfig(verify=False)
)
Then, use the agent as shown below:
from wayflowcore.executors.executionstatus import UserMessageRequestStatus
# With a linear conversation
conversation = agent.start_conversation()
conversation.append_user_message("What is the answer to 2+2?")
status = conversation.execute()
if isinstance(status, UserMessageRequestStatus):
assistant_reply = conversation.get_last_message()
print(f"---\nAssistant >>> {assistant_reply.content}\n---")
else:
print(f"Invalid execution status, expected UserMessageRequestStatus, received {type(status)}")
Agent Spec Exporting/Loading#
You can export the assistant configuration to its Agent Spec configuration using the AgentSpecExporter.
from wayflowcore.agentspec import AgentSpecExporter
serialized_assistant = AgentSpecExporter().to_json(agent)
Here is what the Agent Spec representation will look like ↓
Click here to see the assistant configuration.
{
"component_type": "A2AAgent",
"id": "5ba508ef-7cae-417a-9197-8f2aeee870b6",
"name": "a2a_agent_4311ebd5__auto",
"description": "",
"metadata": {
"__metadata_info__": {}
},
"inputs": [],
"outputs": [],
"agent_url": "http://<URL>",
"connection_config": {
"component_type": "A2AConnectionConfig",
"id": "c01ebe14-f467-4c01-a25b-0f3f22bfa550",
"name": "connection_config",
"description": null,
"metadata": {},
"timeout": 600.0,
"headers": null,
"verify": false,
"key_file": null,
"cert_file": null,
"ssl_ca_cert": null
},
"session_parameters": {
"timeout": 60.0,
"poll_interval": 2.0,
"max_retries": 5
},
"agentspec_version": "25.4.2"
}
component_type: A2AAgent
id: 5ba508ef-7cae-417a-9197-8f2aeee870b6
name: a2a_agent_4311ebd5__auto
description: ''
metadata:
__metadata_info__: {}
inputs: []
outputs: []
agent_url: http://<URL>
connection_config:
component_type: A2AConnectionConfig
id: 7d7a7c03-616b-4740-bd8e-ebcfed45092c
name: connection_config
description: null
metadata: {}
timeout: 600.0
headers: null
verify: false
key_file: null
cert_file: null
ssl_ca_cert: null
session_parameters:
timeout: 60.0
poll_interval: 2.0
max_retries: 5
agentspec_version: 25.4.2
You can then load the configuration back to an assistant using the AgentSpecLoader.
from wayflowcore.agentspec import AgentSpecLoader
agent: A2AAgent = AgentSpecLoader().load_json(serialized_assistant)
Next steps#
Now that you have learned how to use A2A Agents in WayFlow, you may proceed to How to Use Agents in Flows.
Full code#
Click on the card at the top of this page to download the full code for this guide or copy the code below.
1# Copyright © 2025 Oracle and/or its affiliates.
2#
3# This software is under the Apache License 2.0
4# %%[markdown]
5# Code Example - How to Use A2A Agents
6# ------------------------------------
7
8# How to use:
9# Create a new Python virtual environment and install the latest WayFlow version.
10# ```bash
11# python -m venv venv-wayflowcore
12# source venv-wayflowcore/bin/activate
13# pip install --upgrade pip
14# pip install "wayflowcore==26.1"
15# ```
16
17# You can now run the script
18# 1. As a Python file:
19# ```bash
20# python howto_a2aagent.py
21# ```
22# 2. As a Notebook (in VSCode):
23# When viewing the file,
24# - press the keys Ctrl + Enter to run the selected cell
25# - or Shift + Enter to run the selected cell and move to the cell below# (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) or Universal Permissive License
26# (UPL) 1.0 (LICENSE-UPL or https://oss.oracle.com/licenses/upl), at your option.
27
28
29
30# %%[markdown]
31## Creating the agent
32
33# %%
34from wayflowcore.a2a.a2aagent import A2AAgent, A2AConnectionConfig
35
36agent = A2AAgent(
37 agent_url="http://<URL>",
38 connection_config=A2AConnectionConfig(verify=False)
39)
40
41
42# %%[markdown]
43## Running the agent
44
45# %%
46from wayflowcore.executors.executionstatus import UserMessageRequestStatus
47
48# With a linear conversation
49conversation = agent.start_conversation()
50
51conversation.append_user_message("What is the answer to 2+2?")
52status = conversation.execute()
53if isinstance(status, UserMessageRequestStatus):
54 assistant_reply = conversation.get_last_message()
55 print(f"---\nAssistant >>> {assistant_reply.content}\n---")
56else:
57 print(f"Invalid execution status, expected UserMessageRequestStatus, received {type(status)}")
58
59
60# %%[markdown]
61## Export config to Agent Spec
62
63# %%
64from wayflowcore.agentspec import AgentSpecExporter
65
66serialized_assistant = AgentSpecExporter().to_json(agent)
67
68# %%[markdown]
69## Load Agent Spec config
70
71# %%
72from wayflowcore.agentspec import AgentSpecLoader
73
74agent: A2AAgent = AgentSpecLoader().load_json(serialized_assistant)