Repository navigation
fix(a2a): don't emit agent messages with empty parts for action-only events - #8372
08raviyadav wants to merge 7 commits into
Conversation
Shay-Deng
left a comment
There was a problem hiding this comment.
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_actionsis{"stateDelta": {}, "escalate": true} - PR: the WORKING update has no message, and its
metadataholds onlyadk_app_name,adk_session_id,adk_user_idand the extension marker;adk_actionsis 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
artifactUpdatenamedreport.txtwith the saved content (the interceptor fires on the parts-less WORKING update) - PR: no
report.txtartifact
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.
…port callback artifacts
…port callback artifacts
…port callback artifacts
…port callback artifacts
…port callback artifacts
|
Re-ran the same checks on 16dda83, and both cases are fixed end to end:
The issue's repro still shows only the user message in |
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 abefore_agent_callback) is converted into aTASK_STATE_WORKINGstatus update whosestatus.messagehas an emptypartslist. The a2a-sdk task manager appends that message totask.history, soGetTaskand theSendMessageresponse return an agent message with no parts. A2A v1.0 marksMessage.partsREQUIRED (§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 Nonewas always true.Solution:
escalateorskip_summarization(the only actions the reader rebuilds from peer metadata) emit a message-lessWORKINGTaskStatusUpdateEventwith the full event metadata on the update's ownmetadatafield — never aMessagewith emptyparts.WORKINGupdate: it is the vehicle the after-event interceptors run on, so artifacts saved by a callback are exported asTaskArtifactUpdateEvents instead of being dropped. (Review follow-up on fix(a2a): don't emit agent messages with empty parts for action-only events #8372.)adk_actionsmetadata 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_eventnow falls back to the update's ownmetadatafor actions and metadata fields when there is no status message. Message metadata keeps precedence when a message exists._add_event_metadatawas 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:
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 withadk_actionson the update metadata; state-only and bare empty events emit nothing; the reader rebuildsescalatefrom a message-less update and returnsNonefor 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, andtest_grounding_metadata_round_trip_messagebuilds its message directly instead of relying on the removed empty-parts message. Review follow-up: 2 new executor-level tests drivingA2aAgentExecutorwithforce_new_version=True— an escalate-only event keeps bothadk_actionsand 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 aTaskArtifactUpdateEvent; 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 (httpxInvalidURL: Invalid port: ':1]'in client-factory tests), identical on unpatched code. Fulltests/unittestsundertox -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/py314were not run locally; CI is the gate for those versions.ruff check,pyink --check,isort --checkandmypyare clean on the changed files.Manual End-to-End (E2E) Tests:
Reproduced the issue's exact scenario (EchoAgent +
before_agent_callbackmutating state,to_a2a()withA2aAgentExecutor(force_new_version=True), oneSendMessageand oneSendStreamingMessage):task.historycontained an agent message with 0 parts andadk_actions: {'stateDelta': {'turns': 1.0}}in both modes.echo: hireply is still delivered as a task artifact; the callback still runs.Checklist
InvalidURL) unrelated to this change.Additional context
None.