Skip to content

fix(a2a): don't emit agent messages with empty parts for action-only events - #8372

Open
08raviyadav wants to merge 2 commits into
google:mainfrom
08raviyadav:fix/a2a-empty-message-parts-8357
Open

08raviyadav wants to merge 2 commits into
google:mainfrom
08raviyadav:fix/a2a-empty-message-parts-8357

Conversation

@08raviyadav

Copy link
Copy Markdown

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

2. Or, if no issue exists, describe the change:

Problem:
With the new A2A executor, an ADK event carrying only actions (for example the state change from a before_agent_callback) is converted into a TASK_STATE_WORKING status update whose status.message has an empty parts list. The a2a-sdk task manager appends that message to task.history, so GetTask and the SendMessage response return an agent message with no parts. A2A v1.0 marks Message.parts REQUIRED (§5.7: required arrays MUST contain at least one element). The legacy executor does not produce this message for the same agent.

The old branch fired for every content-less event, not just action-carrying ones: a default EventActions() serializes to {'stateDelta': {}}, so _serialize_value(event.actions) is not None was always true.

Solution:

  • Content-less events carrying only actions no remote peer honors back (state delta, artifact delta, transfer, auth configs, usage metadata) or nothing at all now emit no A2A event — matching the legacy executor.
  • Content-less events carrying escalate or skip_summarization (the only actions the reader rebuilds from peer metadata) emit a message-less WORKING TaskStatusUpdateEvent with the full event metadata on the update's own metadata field — never a Message with empty parts.
  • convert_a2a_status_update_to_event now falls back to the update's own metadata for actions and metadata fields when there is no status message. Message metadata keeps precedence when a message exists.
  • _add_event_metadata was refactored to extract a shared _build_event_metadata(event) helper.

Two deliberate scope notes: usage-metadata-only events are skipped like legacy, so usage info for content-less events is dropped on the wire; convert_a2a_task_to_event (task-level) is intentionally untouched.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

pytest tests/unittests/a2a/converters/test_from_adk.py tests/unittests/a2a/converters/test_to_adk.py tests/unittests/a2a/converters/test_event_round_trip.py: 131 passed. New tests: escalate-only and skip-summarization-only each emit one message-less WORKING update with adk_actions on the update metadata; state-only, artifact-delta-only and bare empty events emit nothing; the reader rebuilds escalate from a message-less update and returns None for a state-delta-only one; round-trip tests cover both directions. The previously buggy-behavior test (test_convert_event_to_a2a_events_with_actions) now expects 0 events, and test_grounding_metadata_round_trip_message builds its message directly instead of relying on the removed empty-parts message.

Control run: the new/updated tests fail on unpatched code (8 of 9; the state-only reader test passes on both by design) and pass with the fix.

Full tests/unittests/a2a/: 994 passed, 22 failed, 17 errors — the 22 failures + 17 errors are pre-existing environment failures (httpx InvalidURL: Invalid port: ':1]' in client-factory tests), identical on unpatched code. Full tests/unittests under tox -e py311: 26,008 passed, 539 failed, 17 errors; zero failures in the touched converter tests, and sampled failures elsewhere (model, telemetry, auth, flows) fail identically on unpatched code with the same httpx signature. tox -e py312/py313/py314 were not run locally; CI is the gate for those versions. ruff check, pyink --check, isort --check and mypy are clean on the changed files.

Manual End-to-End (E2E) Tests:

Reproduced the issue's exact scenario (EchoAgent + before_agent_callback mutating state, to_a2a() with A2aAgentExecutor(force_new_version=True), one SendMessage and one SendStreamingMessage):

  • Before the fix: task.history contained an agent message with 0 parts and adk_actions: {'stateDelta': {'turns': 1.0}} in both modes.
  • After the fix: history holds only the user message; the echo: hi reply is still delivered as a task artifact; the callback still runs.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes. — See Testing Plan: the touched converter suite passes (131/131) and the full A2A suite matches unpatched results; the full repo suite has pre-existing environment failures (httpx InvalidURL) unrelated to this change.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules. — N/A, no dependent changes.

Additional context

None.

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 (new executor): a state-only event becomes a status update whose agent message has no parts, and it lands in task history

1 participant