Skip to content

A2A support with a new microsoft-agents-hosting-a2a package - #596

Draft
Rodrigo Brandão (rodrigobr-msft) wants to merge 47 commits into
mainfrom
users/robrandao/a2a
Draft

Rodrigo Brandão (rodrigobr-msft) wants to merge 47 commits into
mainfrom
users/robrandao/a2a

Conversation

@rodrigobr-msft

Copy link
Copy Markdown
Contributor

This pull request introduces the new microsoft-agents-hosting-a2a library and adds support for the A2A protocol across the codebase. It also includes enhancements to the core activity model and test coverage for A2A JWT validation. The most important changes are summarized below.


A2A Protocol and Library Integration:

  • Added the new microsoft-agents-hosting-a2a library, including its public API, client, turn context, agent extension, and supporting files. This provides first-class support for the A2A protocol, enabling integration with A2A agents and services. (microsoft_agents/hosting/a2a/__init__.py, a2a_agent_extension.py, a2a_client.py, a2a_turn_context.py, activity/__init__.py, MANIFEST.in, LICENSE) [1] [2] [3] [4] [5] [6] [7]
  • Registered the new library as a dependency for integration tests. (dev/integration/pyproject.toml)

A2A Protocol Support in Core Libraries:

  • Added the a2a channel to the list of supported channel IDs in the activity model. (microsoft_agents/activity/channels.py)
  • Added a new error code to EndOfConversationCodes for improved error handling. (microsoft_agents/activity/end_of_conversation_codes.py)

Activity Model Enhancements:

  • Added a get_streaming_entity helper to the Activity class to retrieve streaming-related entities, and improved typing and documentation for get_product_info_entity. (microsoft_agents/activity/activity.py) [1] [2]
  • Allowed service_url and request_id to be None in ConversationReference and Activity, respectively, improving flexibility for A2A and other scenarios. (microsoft_agents/activity/conversation_reference.py, microsoft_agents/activity/activity.py) [1] [2]
  • Imported StreamInfo in the activity model to support streaming entities. (microsoft_agents/activity/activity.py)

Testing and Validation:

  • Added integration tests for A2A JWT validation, including acceptance of real service connection tokens and rejection of tokens with invalid audiences. (dev/integration/tests/jwt_validation/test_a2a_jwt_validation.py)

@rodrigobr-msft Rodrigo Brandão (rodrigobr-msft) linked an issue Sep 23, 2026 that may be closed by this pull request

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Task ownership isolation, Blob listing semantics, streaming completion, route construction, and the documented sample contain blocking correctness and security issues.

Review effort: Balanced
Findings: 5 High severity · 5 Medium severity · 1 Low severity

Open (11)
What changed in this PR

Introduces first-class A2A protocol hosting, persistence, authentication integration, samples, and comprehensive tests.

Changes:

  • Adds the microsoft-agents-hosting-a2a package and FastAPI routes.
  • Adds A2A activity conversion, streaming, task handling, and Blob persistence.
  • Extends core models and adds protocol/JWT integration coverage.
File Description
tests/​hosting_core/​test_service_set.py Tests required-service lookup.
tests/​hosting_a2a/​test_blob_task_store.py Tests Blob task persistence.
tests/​hosting_a2a/​test_add_a2a.py Tests A2A route registration.
tests/​hosting_a2a/​test_a2a_turn_context.py Tests A2A context wrapping.
tests/​hosting_a2a/​test_a2a_client.py Tests context service access.
tests/​hosting_a2a/​test_a2a_agent_extension.py Tests route extension behavior.
tests/​hosting_a2a/​test_a2a_adapter.py Tests adapter conversions and events.
tests/​hosting_a2a/​server/​test_utils.py Tests interface-path parsing.
tests/​hosting_a2a/​server/​test_sdk_server_call_context_builder.py Tests request context construction.
tests/​hosting_a2a/​server/​test_routes.py Tests protocol and card routes.
tests/​hosting_a2a/​server/​__init__.py Adds server test package.
tests/​hosting_a2a/​request_handling/​test_request_handling.py Tests task lifecycle handling.
tests/​hosting_a2a/​request_handling/​__init__.py Adds request-handling tests package.
tests/​hosting_a2a/​integration/​test_protocol.py Adds end-to-end protocol tests.
tests/​hosting_a2a/​integration/​test_blob_protocol.py Tests Blob-backed protocol behavior.
tests/​hosting_a2a/​integration/​conftest.py Defines A2A integration harness.
tests/​hosting_a2a/​integration/​__init__.py Adds integration test package.
tests/​hosting_a2a/​activity/​test_utils.py Tests activity conversion helpers.
tests/​hosting_a2a/​activity/​test_a2a_activity.py Tests A2A activity mapping.
tests/​hosting_a2a/​activity/​__init__.py Adds activity test package.
tests/​hosting_a2a/​__init__.py Adds A2A test package.
tests/​activity/​test_activity.py Tests streaming entity lookup.
test_samples/​a2a/​requirements.txt Declares sample dependencies.
test_samples/​a2a/​README.md Documents the A2A sample.
test_samples/​a2a/​client/​cli.py Adds interactive A2A client.
test_samples/​a2a/​client/​__init__.py Adds client package.
test_samples/​a2a/​agent/​start_server.py Hosts the sample agent.
test_samples/​a2a/​agent/​setup.py Adds sample configuration setup.
test_samples/​a2a/​agent/​main.py Adds sample entry point.
test_samples/​a2a/​agent/​agent.py Implements the echo agent.
test_samples/​a2a/​agent/​a2a.py Configures its A2A adapter.
test_samples/​a2a/​agent/​__init__.py Exports sample components.
scripts/​dev_setup.sh Installs A2A package on Unix.
scripts/​dev_setup.ps1 Installs A2A package on Windows.
libraries/​microsoft-agents-hosting-fastapi/​microsoft_agents/​hosting/​fastapi/​_fastapi_request_adapter.py Exposes request URLs.
libraries/​microsoft-agents-hosting-core/​microsoft_agents/​hosting/​core/​http/​_http_request_protocol.py Adds URL to request protocol.
libraries/​microsoft-agents-hosting-core/​microsoft_agents/​hosting/​core/​channel_adapter.py Uses the core adapter protocol.
libraries/​microsoft-agents-hosting-core/​microsoft_agents/​hosting/​core/​channel_adapter_protocol.py Defines core adapter contract.
libraries/​microsoft-agents-hosting-core/​microsoft_agents/​hosting/​core/​_utils/​_service_set.py Adds required-service retrieval.
libraries/​microsoft-agents-hosting-aiohttp/​microsoft_agents/​hosting/​aiohttp/​_aiohttp_request_adapter.py Exposes aiohttp request URLs.
libraries/​microsoft-agents-hosting-a2a/​setup.py Defines package dependencies.
libraries/​microsoft-agents-hosting-a2a/​readme.md Adds package README placeholder.
libraries/​microsoft-agents-hosting-a2a/​pyproject.toml Defines package metadata.
libraries/​microsoft-agents-hosting-a2a/​microsoft_agents/​hosting/​a2a/​server/​sdk_server_call_context_builder.py Builds A2A call contexts.
libraries/​microsoft-agents-hosting-a2a/​microsoft_agents/​hosting/​a2a/​server/​routes.py Creates protocol routes.
libraries/​microsoft-agents-hosting-a2a/​microsoft_agents/​hosting/​a2a/​server/​_utils.py Normalizes interface paths.
libraries/​microsoft-agents-hosting-a2a/​microsoft_agents/​hosting/​a2a/​server/​_constants.py Defines identity state key.
libraries/​microsoft-agents-hosting-a2a/​microsoft_agents/​hosting/​a2a/​server/​__init__.py Exports server APIs.
libraries/​microsoft-agents-hosting-a2a/​microsoft_agents/​hosting/​a2a/​request_handling/​a2a_request_handler.py Extends request handling.
libraries/​microsoft-agents-hosting-a2a/​microsoft_agents/​hosting/​a2a/​request_handling/​a2a_http_adapter.py Defines HTTP adapter protocol.
libraries/​microsoft-agents-hosting-a2a/​microsoft_agents/​hosting/​a2a/​request_handling/​a2a_agent_executor.py Bridges requests to agent turns.
libraries/​microsoft-agents-hosting-a2a/​microsoft_agents/​hosting/​a2a/​request_handling/​__init__.py Exports request APIs.
libraries/​microsoft-agents-hosting-a2a/​microsoft_agents/​hosting/​a2a/​py.typed Marks typed package.
libraries/​microsoft-agents-hosting-a2a/​microsoft_agents/​hosting/​a2a/​extension/​route_handlers.py Wraps A2A route handlers.
libraries/​microsoft-agents-hosting-a2a/​microsoft_agents/​hosting/​a2a/​extension/​a2a_turn_context.py Adds A2A-aware turn context.
libraries/​microsoft-agents-hosting-a2a/​microsoft_agents/​hosting/​a2a/​extension/​a2a_client.py Exposes per-turn A2A services.
libraries/​microsoft-agents-hosting-a2a/​microsoft_agents/​hosting/​a2a/​extension/​a2a_agent_extension.py Adds A2A message decorators.
libraries/​microsoft-agents-hosting-a2a/​microsoft_agents/​hosting/​a2a/​extension/​__init__.py Exports extension APIs.
libraries/​microsoft-agents-hosting-a2a/​microsoft_agents/​hosting/​a2a/​blob_task_store.py Implements Blob task storage.
libraries/​microsoft-agents-hosting-a2a/​microsoft_agents/​hosting/​a2a/​add_a2a.py Registers A2A with FastAPI.
libraries/​microsoft-agents-hosting-a2a/​microsoft_agents/​hosting/​a2a/​activity/​utils.py Converts activities and A2A parts.
libraries/​microsoft-agents-hosting-a2a/​microsoft_agents/​hosting/​a2a/​activity/​a2a_activity.py Defines A2A activity model.
libraries/​microsoft-agents-hosting-a2a/​microsoft_agents/​hosting/​a2a/​activity/​__init__.py Exports A2A activity.
libraries/​microsoft-agents-hosting-a2a/​microsoft_agents/​hosting/​a2a/​a2a_adapter.py Implements protocol adapter behavior.
libraries/​microsoft-agents-hosting-a2a/​microsoft_agents/​hosting/​a2a/​__init__.py Defines public package API.
libraries/​microsoft-agents-hosting-a2a/​MANIFEST.in Includes package version data.
libraries/​microsoft-agents-hosting-a2a/​LICENSE Adds MIT license.
libraries/​microsoft-agents-activity/​microsoft_agents/​activity/​end_of_conversation_codes.py Adds generic error code.
libraries/​microsoft-agents-activity/​microsoft_agents/​activity/​conversation_reference.py Relaxes service URL typing.
libraries/​microsoft-agents-activity/​microsoft_agents/​activity/​channels.py Adds A2A channel ID.
libraries/​microsoft-agents-activity/​microsoft_agents/​activity/​attachment.py Relaxes attachment strings.
libraries/​microsoft-agents-activity/​microsoft_agents/​activity/​activity.py Adds streaming entity helper.
dev/​integration/​tests/​jwt_validation/​test_a2a_jwt_validation.py Tests A2A JWT validation.
dev/​integration/​pyproject.toml Adds A2A integration dependency.
dev/​a2a/​run_tck.ps1 Adds TCK runner.
dev/​a2a/​README.md Documents TCK usage.
dev/​a2a/​agent.py Implements TCK agent.
dev/​a2a/​.gitignore Ignores TCK artifacts.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +43 to +45
agent_card_routes = create_agent_card_routes(
adapter.get_agent_card,
f"{interface.url}{AGENT_CARD_WELL_KNOWN_PATH}",
Comment on lines +103 to +108
def _get_blob_name(task_id: str) -> str:
"""Generates a blob name for the given task ID."""

if not task_id:
raise ValueError("Task ID cannot be empty.")
return f"{_TASK_PREFIX}{urllib.parse.quote_plus(task_id)}"
Comment on lines +34 to +39
if getattr(request.state, "claims_identity", None) is not None:
state[_CLAIMS_IDENTITY_KEY] = request.state.claims_identity

return ServerCallContext(
user=self.build_user(request),
state=state,
Comment on lines +10 to +14
from microsoft_agents.hosting.core import (
AgentApplication,
)

app = AgentApplication()

STORAGE = MemoryStorage()
CONNECTIONS = MsalConnectionManager(**CONFIG)
ADAPTER = A2AAdapter()
Comment on lines +334 to +335
append=False,
last_chunk=True,
Comment on lines +387 to +392
if activity.code == EndOfConversationCodes.error:
task_state = TaskState.TASK_STATE_FAILED
elif activity.code == EndOfConversationCodes.user_cancelled:
task_state = TaskState.TASK_STATE_CANCELED
else:
task_state = TaskState.TASK_STATE_COMPLETED
Comment on lines +88 to +91
Part(
metadata=_get_a2a_metadata(entity),
data=_to_protobuf_value(entity.model_dump(exclude_none=True)),
)
Comment on lines +152 to +156
items = self._container_client.list_blobs(
name_starts_with=_TASK_PREFIX, **kwargs
)

iterator = items.by_page(params.page_token)
name = "microsoft-agents-hosting-a2a"
dynamic = ["version", "dependencies", "optional-dependencies"]
description = "Library adding A2A handling to an SDK Agent"
readme = {file = "readme.md", content-type = "text/markdown"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A2A Support in Agents SDK for Python

2 participants