Skip to content

Python: Propagate A2A metadata from Message, Artifact, Task, and event types#5256

Merged
eavanvalkenburg merged 2 commits intomicrosoft:mainfrom
kartikmadan11:fix/5240-a2a-metadata-propagation
Apr 16, 2026
Merged

Python: Propagate A2A metadata from Message, Artifact, Task, and event types#5256
eavanvalkenburg merged 2 commits intomicrosoft:mainfrom
kartikmadan11:fix/5240-a2a-metadata-propagation

Conversation

@kartikmadan11
Copy link
Copy Markdown
Contributor

@kartikmadan11 kartikmadan11 commented Apr 14, 2026

Motivation and Context

The A2A protocol defines a metadata field on Message, Artifact, Task, TaskStatusUpdateEvent, and TaskArtifactUpdateEvent. Currently, A2AAgent only propagates Part-level metadata (via _parse_contents_from_a2a), but silently drops metadata at every other level, losing information transmitted by the server.

Fixes #5240

Description

Metadata is now propagated at each conversion boundary in _agent.py, namespaced under an "a2a_metadata" key inside additional_properties to avoid collisions with other framework code that may also populate additional_properties.

A2A Type Target How
Message AgentResponseUpdate.additional_properties["a2a_metadata"] {"a2a_metadata": message.metadata}
Artifact intermediate Message.additional_properties → merged into update {"a2a_metadata": {**artifact.metadata, **task.metadata}}
Task AgentResponseUpdate.additional_properties["a2a_metadata"] {"a2a_metadata": task.metadata} on all updates produced from the task
TaskArtifactUpdateEvent AgentResponseUpdate.additional_properties["a2a_metadata"] {"a2a_metadata": {**artifact.metadata, **event.metadata}} merged
TaskStatusUpdateEvent AgentResponseUpdate.additional_properties["a2a_metadata"] {"a2a_metadata": {**message.metadata, **event.metadata}} merged
History Message Message.additional_properties {"a2a_metadata": history_item.metadata}

On the outbound side, _prepare_message_for_a2a reads message.additional_properties.get("a2a_metadata") to reconstruct wire metadata cleanly.

For streaming events, metadata from the inner object (artifact or status message) is merged with the outer event metadata, since they represent different layers of information.

Eight regression tests cover all affected types plus a None-safety check.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass (74/74 in a2a package), and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

@moonbox3
Copy link
Copy Markdown
Contributor

moonbox3 commented Apr 15, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/a2a/agent_framework_a2a
   _agent.py2381693%352, 357, 359, 518, 535, 543, 564, 585, 606, 626, 640, 654, 666–667, 707–708
TOTAL27690319888% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
5611 20 💤 0 ❌ 0 🔥 1m 35s ⏱️

Comment thread python/packages/a2a/agent_framework_a2a/_agent.py Outdated
@kartikmadan11 kartikmadan11 force-pushed the fix/5240-a2a-metadata-propagation branch from 7528f1a to 280589f Compare April 16, 2026 14:21
@eavanvalkenburg eavanvalkenburg added this pull request to the merge queue Apr 16, 2026
Merged via the queue into microsoft:main with commit 43d9897 Apr 16, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Python A2AAgent Implementation Currently Ignores Metadata in TaskArtifactUpdateEvent

4 participants