Files
agent-framework/python/samples/02-agents/a2a
T
Giles Odigwe 5affc9c333 Python: Reorganize A2A samples and use package A2AExecutor (#6165)
* Reorganize A2A samples: client demos in 02-agents, use package A2AExecutor

- Move client samples (agent_with_a2a, a2a_agent_as_function_tools) to samples/02-agents/a2a/
- Add new concept samples: polling, stream reconnection, protocol selection
- Replace sample agent_executor.py with package-level A2AExecutor (stream=True)
- Update 04-hosting/a2a to focus on server-side, point to 02-agents for clients
- Add README.md for the new 02-agents/a2a/ sample collection

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Fix streaming artifact coalescing and address PR review feedback

A2AExecutor fix:
- Generate a stable artifact_id per stream in _run_stream so all streaming
  chunks share the same ID, enabling proper append=True coalescing per the
  A2A spec (TaskArtifactUpdateEvent with same artifactId).
- Previously, item.message_id was None for OpenAI/Foundry streaming updates,
  causing the SDK to generate a new random UUID per token (100+ separate
  artifacts instead of 1 appended artifact).

Sample improvements:
- Replace join workaround with response.text now that coalescing works
- Add background=True to stream reconnection resume call (required for
  continuation token emission on in-progress tasks)
- Fix type ignore specificity in polling sample

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
5affc9c333 · 2026-06-01 07:09:11 +00:00
History
..

A2A Client Samples

These samples demonstrate how to consume remote A2A-compliant agents using the Agent Framework's A2AAgent class.

For hosting your own agents as A2A servers, see samples/04-hosting/a2a/.

Samples

Sample Concept
agent_with_a2a.py Basic consumption — non-streaming and streaming
a2a_agent_as_function_tools.py Expose A2A skills as function tools for a host agent
a2a_polling.py Poll a long-running task with continuation tokens
a2a_stream_reconnection.py Resume an interrupted stream via continuation token
a2a_protocol_selection.py Configure preferred protocol bindings (JSONRPC, GRPC, HTTP+JSON)

Prerequisites

  • A running A2A-compliant agent server (see samples/04-hosting/a2a/ to start one)
  • Set A2A_AGENT_HOST environment variable to the server URL
  • For a2a_agent_as_function_tools.py: also set FOUNDRY_PROJECT_ENDPOINT and FOUNDRY_MODEL

Running

cd python/samples/02-agents/a2a

# Start an A2A server in another terminal first:
#   cd python/samples/04-hosting/a2a && uv run python a2a_server.py

export A2A_AGENT_HOST="http://localhost:5001/"
uv run python agent_with_a2a.py

Key APIs

from agent_framework.a2a import A2AAgent

# Connect to a remote agent
async with A2AAgent(url="http://localhost:5001/", agent_card=card) as agent:
    # Non-streaming
    response = await agent.run("Hello")

    # Streaming
    stream = agent.run("Hello", stream=True)
    async for update in stream:
        print(update.text)

    # Background + polling
    response = await agent.run("Long task", background=True)
    while response.continuation_token:
        response = await agent.poll_task(response.continuation_token)