fix(agents): skip live after callbacks when invocation ends - #7081
Open
jaywang172 wants to merge 1 commit into
Open
fix(agents): skip live after callbacks when invocation ends#7081jaywang172 wants to merge 1 commit into
jaywang172 wants to merge 1 commit into
Conversation
Honor end_invocation after live agent execution, matching the async lifecycle for plugin and agent after callbacks. Fixes google#7080
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
Fixes #7080
Companion documentation: google/adk-docs#2216
(should land with or after this runtime fix).
When a live agent sets
end_invocation, its after-agent callbacks still runand can emit another response or modify state. The async entry point already
skips those callbacks in the same situation.
Add the same post-execution check to
BaseAgent.run_live(). The change is threeruntime lines and covers both plugin and agent-defined after callbacks. Normal
completion and the runner-level after-run hook retain their existing behavior.
Testing Plan
Full
toxmatrix (Python 3.10 completed sequentially; remaining versions ranwith
tox -e py311,py312,py313,py314 -p 4):All five full-suite runs passed. The initial Homebrew 3.14 run had two
allowlisted-import failures caused by its startup
sitecustomizemodule;both reproduced on unmodified
main. Recreating the environment withtox -r -e py314 -x testenv.uv_python_preference=only-managedused Python3.14.6 and passed the complete suite. No tests, allowlists, or repository
configuration were changed to suppress the failures.
A local ignored
uv.lockwas generated because the repository's tox runneruses
uv sync --locked; no dependency files are included in this PR.pre-commit run --files src/google/adk/agents/base_agent.py tests/unittests/agents/test_base_agent.py: passed.git diff --check: passed.uv build: passed. Installed the resulting wheel into a clean Python 3.11environment and ran the same Runner smoke test outside the source checkout;
both cases passed.
_run_callbacksargument-type errors on both the unchanged baseline and this patch; no new
diagnostics. This check is not clean on the baseline.
Manual E2E: ran
Runner.run_live()with a localBaseAgent, plugin, andInMemorySessionService. Normal completion emitted the agent and after-agentresponses and invoked both after-agent hooks. With
end_invocation=True, onlythe agent response was emitted, both after-agent hooks were skipped, and
after_run_callbackstill ran. No model request or Google credentials were needed.Reproducible Runner smoke test and output
Save the following as
live_lifecycle_smoke.py, then runPYTHONPATH=src python live_lifecycle_smoke.pyfrom the checkout with ADK'sruntime dependencies installed.
Checklist