Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b43cfe0
docs: add a how to guide for serving and consuming A2A Agents using M…
sathvikbhagavan Dec 2, 2025
787de88
refactor: allow A2AAgent in ManagerWorkers
sathvikbhagavan Dec 2, 2025
b3bd7e9
test: have A2A servers and clients for the doc example
sathvikbhagavan Dec 2, 2025
a78fb4e
docs: fix typo in howto_a2a
sathvikbhagavan Dec 2, 2025
697bd30
docs: clean up the descriptions
sathvikbhagavan Dec 3, 2025
6d57044
docs: update the title
sathvikbhagavan Dec 3, 2025
05047ba
docs: clean up the headings of the sections
sathvikbhagavan Dec 3, 2025
cafebbc
docs: refactor a2a how to guide
sathvikbhagavan Dec 15, 2025
b87b9bf
refactor: make A2AAgent work in agent execution step
sathvikbhagavan Dec 15, 2025
9f41c15
docs: clean up A2A Agent how to guide
sathvikbhagavan Jan 6, 2026
1218372
docs: clean up the tutorial
sathvikbhagavan Jan 14, 2026
2e8be75
chore: fix typo
sathvikbhagavan Jan 14, 2026
5677ffe
chore: remove unnecessary file
sathvikbhagavan Jan 15, 2026
2812124
refactor: only allow workers to also be A2AAgents
sathvikbhagavan Jan 29, 2026
5f9e2f4
chore: fix typo
sathvikbhagavan Jan 29, 2026
40bdc9c
refactor: return types in _validate_agent_unicity
sathvikbhagavan Jan 29, 2026
951d7f2
fix: convert from agentspec to wayflow
sathvikbhagavan Jan 30, 2026
a4a3273
fix: types
sathvikbhagavan Jan 30, 2026
10113b1
chore: sort imports
sathvikbhagavan Jan 30, 2026
2417c48
refactor: error message in agent spec deseriaization for ManagerWorkers
sathvikbhagavan Jan 30, 2026
5d97938
docs: address comments
sathvikbhagavan Jan 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 152 additions & 4 deletions docs/wayflowcore/source/core/code_examples/howto_a2aagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
# mypy: ignore-errors
# docs-title: Code Example - How to Use A2A Agents

### Basic Usage

# .. start-##_Creating_the_agent
from wayflowcore.a2a.a2aagent import A2AAgent, A2AConnectionConfig

Expand All @@ -35,13 +37,159 @@
print(f"Invalid execution status, expected UserMessageRequestStatus, received {type(status)}")
# .. end-##_Running_the_agent

# .. start-##_Export_config_to_Agent_Spec
# .. start-##_Export_config_to_Agent_Spec1
from wayflowcore.agentspec import AgentSpecExporter

serialized_assistant = AgentSpecExporter().to_json(agent)
# .. end-##_Export_config_to_Agent_Spec
# .. start-##_Load_Agent_Spec_config
# .. end-##_Export_config_to_Agent_Spec1
# .. start-##_Load_Agent_Spec_config1
from wayflowcore.agentspec import AgentSpecLoader

agent: A2AAgent = AgentSpecLoader().load_json(serialized_assistant)
# .. end-##_Load_Agent_Spec_config1

### Manager Workers Usage

# Server part
import random
from typing import Annotated

from wayflowcore.agentserver.server import A2AServer
from wayflowcore.agent import Agent
from wayflowcore.models import VllmModel
from wayflowcore.tools import tool

# .. start-##_llm
llm = VllmModel(
model_id="LLAMA_MODEL_ID",
host_port="LLAMA_API_URL",
)
# .. end-##_llm

(llm,) = _update_globals(["vision_llm"]) # docs-skiprow # type: ignore


# .. start-##_Server_Setup_Prime_Agent
def get_prime_agent():
@tool
def check_prime(a: Annotated[int, "first required integer"]) -> bool:
"Check if the first number (a) is a prime number."
if a < 2:
return False
for i in range(2, int(a**0.5) + 1):
if a % i == 0:
return False
return True
agent = Agent(
llm=llm,
name="prime_agent",
custom_instruction="You are a math agent that can check whether a number is prime or not using the equipped tool.",
tools=[check_prime],
can_finish_conversation=True,
)
return agent
# .. end-##_Server_Setup_Prime_Agent


# .. start-##_Server_Setup_Sample_Agent
def get_sample_agent():
@tool
def sample_number(a: Annotated[int, "first required integer"]) -> int:
"Simulate sampling from a range, return a random number between 1 and the specified value."
result = random.randint(1, a) # nosec
return result
agent = Agent(
llm=llm,
name="sample_agent",
custom_instruction="You are an agent that can generate a random number between 1 and a specified value.",
tools=[sample_number],
can_finish_conversation=True,
)
return agent
# .. end-##_Server_Setup_Sample_Agent

# .. start-##_Server_Startup_Logic
# Start both sample and prime servers
sample_agent = get_sample_agent()
sample_server = A2AServer()
sample_server.serve_agent(sample_agent, "http://<sample_agent_url>")
# Note: Uncomment the line below to start the server
# sample_server.serve()

prime_agent = get_prime_agent()
prime_server = A2AServer()
prime_server.serve_agent(prime_agent, "http://<prime_agent_url>")
# Note: Uncomment the line below to start the server
# prime_server.serve(port=8001)
# .. end-##_Server_Startup_Logic

(sample_server,) = _update_globals(["sample_a2a_server"]) # docs-skiprow # type: ignore
(prime_server,) = _update_globals(["prime_a2a_server"]) # docs-skiprow # type: ignore

# Client part
from wayflowcore.a2a.a2aagent import A2AAgent, A2AConnectionConfig
from wayflowcore.agent import Agent
from wayflowcore.models import VllmModel

# .. start-##_Client_Setup
sample_agent = A2AAgent(
name="sample_agent",
agent_url="http://<sample_agent_url>",
description="Agent that can generate random numbers",
connection_config=A2AConnectionConfig(verify=False),
)
prime_agent = A2AAgent(
name="prime_agent",
agent_url="http://<prime_agent_url>",
description="Agent that handles checking if numbers are prime.",
connection_config=A2AConnectionConfig(verify=False),
)
# .. end-##_Client_Setup

(sample_agent, prime_agent) = _update_globals(
["sample_a2a_agent", "prime_a2a_agent"]
) # docs-skiprow # type: ignore

# .. start-##_Manager_Setup
MANAGER_SYSTEM_PROMPT = """
You are a helpful assistant that can sample numbers and check if the sampled numbers are prime.
You delegate sampling tasks to the `sample_agent` and prime checking tasks to the `prime_agent`.
Follow these steps:
1. If the user asks to sample a number, delegate to the `sample_agent`.
2. If the user asks to check primes, delegate to the `prime_agent`.
3. If the user asks to sample a number and then check if the result is prime, call `sample_agent` first, then pass the result to `prime_agent`.
Always clarify the results before proceeding.
""".strip()

manager = Agent(
name="PrimeChecker",
description="You are a PrimeChecker who can sample integers and check if they are prime.",
llm=llm,
custom_instruction=MANAGER_SYSTEM_PROMPT,
)
# .. end-##_Manager_Setup

# .. start-##_ManagerWorkers_Execution
from wayflowcore.managerworkers import ManagerWorkers

group = ManagerWorkers(
group_manager=manager,
workers=[sample_agent, prime_agent],
)

main_conversation = group.start_conversation()
main_conversation.append_user_message("Sample a number from 1 to 20 and check if it's prime")
main_conversation.execute()
print(main_conversation.get_messages())
# .. end-##_ManagerWorkers_Execution

# .. start-##_Export_config_to_Agent_Spec2
from wayflowcore.agentspec import AgentSpecExporter

serialized_assistant = AgentSpecExporter().to_json(group)
# .. end-##_Export_config_to_Agent_Spec2
# .. start-##_Load_Agent_Spec_config2
from wayflowcore.agentspec import AgentSpecLoader

agent: A2AAgent = AgentSpecLoader().load_json(serialized_assistant)
# .. end-##_Load_Agent_Spec_config
# .. end-##_Load_Agent_Spec_config2
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"component_type": "A2AAgent",
"id": "5ba508ef-7cae-417a-9197-8f2aeee870b6",
"name": "a2a_agent_4311ebd5__auto",
"id": "47b982ac-dbbe-4674-8c97-f6d82a21554c",
"name": "a2a_agent_a5ea926f__auto",
"description": "",
"metadata": {
"__metadata_info__": {}
Expand All @@ -11,8 +11,8 @@
"agent_url": "http://<URL>",
"connection_config": {
"component_type": "A2AConnectionConfig",
"id": "c01ebe14-f467-4c01-a25b-0f3f22bfa550",
"name": "connection_config",
"id": "1912133f-0bc6-4846-a140-2a5bfb5f9c42",
"name": "",
"description": null,
"metadata": {},
"timeout": 600.0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
component_type: A2AAgent
id: 5ba508ef-7cae-417a-9197-8f2aeee870b6
name: a2a_agent_4311ebd5__auto
id: 47b982ac-dbbe-4674-8c97-f6d82a21554c
name: a2a_agent_a5ea926f__auto
description: ''
metadata:
__metadata_info__: {}
Expand All @@ -9,8 +9,8 @@ outputs: []
agent_url: http://<URL>
connection_config:
component_type: A2AConnectionConfig
id: 7d7a7c03-616b-4740-bd8e-ebcfed45092c
name: connection_config
id: 1912133f-0bc6-4846-a140-2a5bfb5f9c42
name: ''
description: null
metadata: {}
timeout: 600.0
Expand Down
Loading