fix: restore event metadata in A2A inbound converters#5222
Open
giulio-leone wants to merge 1 commit intogoogle:mainfrom
Open
fix: restore event metadata in A2A inbound converters#5222giulio-leone wants to merge 1 commit intogoogle:mainfrom
giulio-leone wants to merge 1 commit intogoogle:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
The inbound converters (convert_a2a_message_to_event, convert_a2a_task_to_event, convert_a2a_status_update_to_event, convert_a2a_artifact_update_to_event) only restored 'actions' from A2A metadata. Other event metadata fields (custom_metadata, usage_metadata, error_code) serialized by the outbound converter were silently dropped. Additionally, _create_event() returned None for metadata-only messages (no parts, no actions) even when valid event metadata was present. Changes: - Add _extract_event_metadata() to restore custom_metadata, error_code, and usage_metadata from A2A metadata. - Update _create_event() to accept and set these fields, and preserve events that carry only metadata (no parts/actions). - Update all four converter functions to extract and forward metadata. - Add 9 regression tests covering metadata restoration across all converter functions and the metadata-only event case. Fixes google#5185
484aee4 to
bc8a9d6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5185 — A2A inbound converters now restore
custom_metadata,usage_metadata, anderror_codefrom A2A message metadata, and metadata-only messages no longer returnNone.Root Cause
The outbound converter (
from_adk_event.py) serializes event metadata fields (custom_metadata,usage_metadata,error_code, etc.) into A2A metadata using theadk_key prefix. The inbound converter (to_adk_event.py) only extractedactions— all other fields were silently dropped.Additionally,
_create_event()returnedNonewhen there were no parts and no actions, even if event metadata was present, causing metadata-only messages to be discarded.Changes
src/google/adk/a2a/converters/to_adk_event.py_extract_event_metadata()(new): Extractscustom_metadata,error_code, andusage_metadatafrom A2A metadata, mirroring what_add_event_metadata()serializes outbound._create_event(): Accepts new optional params (custom_metadata,error_code,usage_metadata), sets them on theEvent, and fixes the None-gate to preserve events that carry only metadata.convert_a2a_message_to_event,convert_a2a_task_to_event,convert_a2a_status_update_to_event,convert_a2a_artifact_update_to_event) now extract and forward event metadata.tests/unittests/a2a/converters/test_to_adk.pyEvent(notNone)custom_metadatarestoration (standalone and with content)error_coderestorationusage_metadatarestorationNone(existing behavior preserved)Test Results
All 151 converter tests pass (14 pre-existing + 9 new + 128 others).