fix(events): exclude state-only events from final responses - #7095
Open
Epsilon006 wants to merge 1 commit into
Open
fix(events): exclude state-only events from final responses#7095Epsilon006 wants to merge 1 commit into
Epsilon006 wants to merge 1 commit into
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. |
A callback state mutation is persisted as a content-less framework event. Exclude that state-only event from final-response detection while preserving legitimate content-less agent responses. Fixes google#7078
Epsilon006
force-pushed
the
fix/7078-state-only-event-final-response
branch
from
September 11, 2026 17:35
6ca8072 to
6bb1f0b
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.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
A
before_agent_callbackorafter_agent_callbackthat only mutates statecauses
BaseAgentto emit a content-less event carrying the state delta. Thedefault branch of
Event.is_final_response()currently classifies that eventas final, so consumers can finish the turn before the actual agent response.
Solution:
Treat events with no
contentor structuredoutputand a non-emptystate_deltaas non-final. This reuses the event's existing shape instead ofadding framework-event metadata. Empty
Content(parts=[])events remain final,preserving legitimate content-less model completion semantics.
Testing Plan
Unit Tests:
Added regression coverage for state-only events, empty
Contentcompatibility,and both before/after agent callback state-delta paths.
Relevant tests, including A2A converters/executor, pass on every supported
Python version:
pre-commit run --filespasses all applicable hooks. Fulltoxwas also run;the Windows host has unrelated existing platform/environment failures (GBK
encoding, Unix shell/path assumptions, network-dependent tests, and telemetry
snapshots). None of those failures are in the changed files or relevant test
set.
Manual End-to-End (E2E) Tests:
Ran a deterministic agent through
InMemoryRunner. Itsbefore_agent_callbacksetscallback_state, then the agent emits its response.The state-only event is observable and persisted but is not final; the following
agent response is final.
Checklist
Additional context
The patch intentionally does not add a new public event field. Existing
priority semantics for terminal errors and
skip_summarizationremainunchanged, and plain empty events retain their historical final-response
behavior.