Skip to content

fix: restore event metadata in A2A inbound converters#5222

Open
giulio-leone wants to merge 1 commit intogoogle:mainfrom
giulio-leone:fix/a2a-inbound-metadata-restoration
Open

fix: restore event metadata in A2A inbound converters#5222
giulio-leone wants to merge 1 commit intogoogle:mainfrom
giulio-leone:fix/a2a-inbound-metadata-restoration

Conversation

@giulio-leone
Copy link
Copy Markdown

Summary

Fixes #5185 — A2A inbound converters now restore custom_metadata, usage_metadata, and error_code from A2A message metadata, and metadata-only messages no longer return None.

Root Cause

The outbound converter (from_adk_event.py) serializes event metadata fields (custom_metadata, usage_metadata, error_code, etc.) into A2A metadata using the adk_ key prefix. The inbound converter (to_adk_event.py) only extracted actions — all other fields were silently dropped.

Additionally, _create_event() returned None when 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): Extracts custom_metadata, error_code, and usage_metadata from A2A metadata, mirroring what _add_event_metadata() serializes outbound.
  • _create_event(): Accepts new optional params (custom_metadata, error_code, usage_metadata), sets them on the Event, and fixes the None-gate to preserve events that carry only metadata.
  • All four converter functions (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.py

  • 9 new regression tests covering:
    • Metadata-only message returns valid Event (not None)
    • custom_metadata restoration (standalone and with content)
    • error_code restoration
    • usage_metadata restoration
    • All metadata fields together with actions
    • Empty message still returns None (existing behavior preserved)
    • Task, status update, and artifact update metadata restoration

Test Results

All 151 converter tests pass (14 pre-existing + 9 new + 128 others).

@google-cla
Copy link
Copy Markdown

google-cla bot commented Apr 9, 2026

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.

@adk-bot adk-bot added the core [Component] This issue is related to the core interface and implementation label Apr 9, 2026
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
@giulio-leone giulio-leone force-pushed the fix/a2a-inbound-metadata-restoration branch from 484aee4 to bc8a9d6 Compare April 9, 2026 03:01
@rohityan rohityan self-assigned this Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core [Component] This issue is related to the core interface and implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A2A inbound converters do not restore custom_metadata and drop metadata-only events

3 participants