Python: fix: consistent response_id and metadata forwarding in A2AAgent#5288
Python: fix: consistent response_id and metadata forwarding in A2AAgent#5288LEDazzio01 wants to merge 2 commits intomicrosoft:mainfrom
Conversation
Fix microsoft#5263: Use task_id (not message_id) for response_id in the A2AMessage path, matching the behavior of all Task-based paths. message_id is now set as a separate field on AgentResponseUpdate. Fix microsoft#5240: Forward metadata as additional_properties from: - A2AMessage (message-level metadata) - TaskArtifactUpdateEvent (artifact metadata) - TaskStatusUpdateEvent (status message metadata) Previously, only Part-level metadata was forwarded via _parse_contents_from_a2a(). Message/event-level metadata was dropped.
There was a problem hiding this comment.
Pull request overview
Fixes A2AAgent’s Python A2A-stream mapping so response_id is consistent across A2AMessage vs task-based responses, and ensures message/event-level metadata is forwarded into AgentResponseUpdate.additional_properties.
Changes:
- Use
task_id(with UUID fallback) asresponse_idfor A2AMessage updates, while preservingmessage_idseparately. - Forward metadata from A2AMessage, TaskArtifactUpdateEvent, and TaskStatusUpdateEvent into
AgentResponseUpdate.additional_properties. - Add/update unit tests covering
response_idbehavior and metadata forwarding.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| python/packages/a2a/agent_framework_a2a/_agent.py | Aligns A2AMessage response_id with task-based paths; forwards message/event metadata into updates. |
| python/packages/a2a/tests/test_a2a_agent.py | Updates existing expectations and adds new tests for response_id, message_id, and metadata forwarding. |
| mock_a2a_client.add_message_response( | ||
| "msg-abc", "Hello", task_id="task-xyz" | ||
| ) |
There was a problem hiding this comment.
These arguments are split across lines in a way that doesn’t match the repo’s Ruff formatter output. Please run ruff format (or adjust line breaks / trailing commas) so CI formatting checks pass.
| mock_a2a_client.add_message_response( | |
| "msg-abc", "Hello", task_id="task-xyz" | |
| ) | |
| mock_a2a_client.add_message_response("msg-abc", "Hello", task_id="task-xyz") |
| ) -> None: | ||
| """Test that A2AMessage metadata is forwarded as additional_properties (#5240).""" | ||
| mock_a2a_client.add_message_response( | ||
| "msg-meta", "Hello", task_id="task-meta", |
There was a problem hiding this comment.
This call formatting (mixed arguments on the same line plus line breaks) is not Ruff-format compliant. Please reformat (e.g., one-line call or one-arg-per-line with trailing commas) to satisfy ruff format.
| "msg-meta", "Hello", task_id="task-meta", | |
| "msg-meta", | |
| "Hello", | |
| task_id="task-meta", |
| # Should be a valid UUID string, not message_id | ||
| assert response.response_id != "msg-no-task" | ||
| assert len(response.response_id) > 0 |
There was a problem hiding this comment.
This test says response_id should fall back to a UUID, but the assertions only check non-emptiness and inequality with the message_id. Please validate the value is actually a UUID (e.g., UUID(response.response_id) succeeds) so the test would fail if the fallback regressed.
| mock_a2a_client.add_message_response( | ||
| "msg-unique", "Hello", task_id="task-parent" | ||
| ) |
There was a problem hiding this comment.
This call’s multiline formatting doesn’t match Ruff’s formatter conventions and may fail formatting checks. Please reformat (or run ruff format).
| mock_a2a_client.add_message_response( | |
| "msg-unique", "Hello", task_id="task-parent" | |
| ) | |
| mock_a2a_client.add_message_response("msg-unique", "Hello", task_id="task-parent") |
- Collapse short multiline calls to single-line (3 instances) - Reformat mixed-args call to one-arg-per-line with trailing commas - Replace len() > 0 assertion with UUID() parse for proper validation
Fixes
response_idinconsistency when processing A2AMessage vs Task-based pathsChanges
response_id consistency (#5263)
The A2AMessage path was using
message_idasresponse_id, while all Task-based paths usetask.id. This caused inconsistentresponse_idvalues across response types.Fix: Use
task_idforresponse_id(with UUID fallback) and setmessage_idas a separate field, matching the issue reporter's suggested approach.metadata forwarding (#5240)
Part-level metadata was correctly forwarded via
_parse_contents_from_a2a(), but message/event-level metadata was dropped in three places:item.metadatawas not forwardedupdate_event.artifact.metadatawas not forwardedupdate_event.status.message.metadatawas not forwardedFix: Add
additional_properties=to eachAgentResponseUpdateconstructor.Tests
Added 7 new tests covering:
response_idusestask_idwhen presentresponse_idfalls back to UUID whentask_idabsentmessage_idpreserved separately fromresponse_idUpdated 2 existing tests to reflect the new
response_idbehavior.