Skip to content

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

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

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

Conversation

@08raviyadav

@08raviyadav 08raviyadav commented Nov 26, 2026 •

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, 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.
  • Content-less events carrying a non-empty artifact delta also emit a message-less WORKING update: it is the vehicle the after-event interceptors run on, so artifacts saved by a callback are exported as TaskArtifactUpdateEvents instead of being dropped. (Review follow-up on fix(a2a): don't emit agent messages with empty parts for action-only events #8372.)
  • The legacy executor now merges invocation metadata into an event's existing metadata instead of replacing it, so the adk_actions metadata the converter put on a message-less update survives to the wire. (Review follow-up on fix(a2a): don't emit agent messages with empty parts for action-only events #8372.)
  • 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 tests/unittests/a2a/executor/test_a2a_agent_executor_impl.py tests/unittests/a2a/integration/test_client_server_v1.py: 181 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 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. Review follow-up: 2 new executor-level tests driving A2aAgentExecutor with force_new_version=True — an escalate-only event keeps both adk_actions and the invocation metadata on the message-less WORKING update with no empty-parts message in the stream, and an artifact-delta-only event exports the artifact as a TaskArtifactUpdateEvent; the artifact-delta-only converter test now expects one message-less WORKING update.

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. The 3 new/updated review-follow-up tests fail on the PR baseline and pass with the fix.

Full tests/unittests/a2a/: 996 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 affected suites pass (181 passed: converters + executor impl + integration artifact tests) 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.

@Shay-Deng Shay-Deng left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking this up. I reported #8357, so I ran the change locally against the issue's repro and the A2A conformance suite. It fixes the reported shape: with the PR (5b87b79), task.history holds only the user message on both SendMessage and GetTask, the stream no longer carries a WORKING update with a parts-less message, and the echo: hi artifact is unchanged. tests/unittests/a2a passes (1033 passed, versus 1025 on 03725e8; the difference is the new tests), and the a2a-itk ACTS corpus gives the same results as on the base for the new executor.

Two things break on the executor path, though. The converter-level tests don't reach either one. I reproduced both with to_a2a(..., agent_executor_factory=lambda r: A2aAgentExecutor(runner=r, force_new_version=True)) and SendStreamingMessage:

1. escalate / skip_summarization don't reach the wire. The converter now puts the metadata on the status update itself, but the new executor then overwrites it. a2a_agent_executor_impl.py L239–241 calls _compat.set_event_metadata(a2a_event, self._get_invocation_metadata(executor_context)) for every converted event, and set_event_metadata replaces rather than merges (CopyFrom on 1.x, assignment on 0.3). With an agent that yields a text event and then Event(actions=EventActions(escalate=True)):

  • base: the WORKING update's status.message.metadata.adk_actions is {"stateDelta": {}, "escalate": true}
  • PR: the WORKING update has no message, and its metadata holds only adk_app_name, adk_session_id, adk_user_id and the extension marker; adk_actions is gone

So the reader fallback in to_adk_event.py has nothing to read, and the round trip from the PR description doesn't happen end to end. Merging the invocation metadata into the event's existing metadata in the executor would keep both.

2. Artifacts saved from a callback stop being exported by include_artifacts_in_a2a_event_interceptor. After-event interceptors run only inside the for a2a_event in self._config.adk_event_converter(...) loop (L232–242), so an ADK event that converts to no A2A event never reaches them. An after_agent_callback that calls callback_context.save_artifact('report.txt', ...) produces such an event (only artifact_delta). With A2aAgentExecutorConfig(execute_interceptors=[include_artifacts_in_a2a_event_interceptor]):

  • base: the stream carries an artifactUpdate named report.txt with the saved content (the interceptor fires on the parts-less WORKING update)
  • PR: no report.txt artifact

Keeping a message-less WORKING update when artifact_delta is non-empty, or running the after-event interceptors for an ADK event even when it converts to nothing, would cover this. I'll leave the choice to you.

A test through A2aAgentExecutor with force_new_version=True for each case (escalate-only, and artifact_delta-only with the interceptor) would catch both. Happy to share the two small apps I used.

@Shay-Deng

Copy link
Copy Markdown
Contributor

Re-ran the same checks on 16dda83, and both cases are fixed end to end:

  • Escalate-only: the WORKING update now carries adk_actions ({"escalate": true, ...}) next to the invocation metadata, with no message.
  • Callback-saved artifact with include_artifacts_in_a2a_event_interceptor: report.txt is exported as an artifactUpdate again, from a message-less WORKING update.

The issue's repro still shows only the user message in task.history, and tests/unittests/a2a passes (1035 passed). Thanks for the quick turnaround and the executor-level tests.

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

2 participants