Repository navigation
fix(agents): record artifact_delta from before/after agent callbacks - #7479
Open
AkshayShah03 wants to merge 1 commit into
Open
AkshayShah03 wants to merge 1 commit into
AkshayShah03 wants to merge 1 commit into
Conversation
_handle_agent_callbacks only emitted an event when a callback returned content or changed state, so an artifact saved via callback_context.save_artifact() in before_agent_callback or after_agent_callback was stored but never recorded in a session event. Rewind and event-based artifact surfacing therefore missed it. Also emit the event when the callback context carries an artifact_delta. Fixes google#7478
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:
BaseAgent._handle_agent_callbacksonly returns an event when a callback returns content orcallback_context.state.has_delta()is true. An artifact saved viacallback_context.save_artifact()in abefore_agent_callback/after_agent_callbackthat returnsNoneis stored by the artifact service, but itsartifact_deltais never put on any event. The session has no record of it, soRunner.rewind_asynccannot revert it and event-based artifact surfacing (web UI, A2A) never sees it.Solution:
Also emit the event when
callback_context._event_actions.artifact_deltais non-empty. This matches the workflow node runner, which already checks both state and artifact deltas, and the model/tool callback paths, which already record artifacts saved there.Testing Plan
Unit Tests:
Added to
tests/unittests/agents/test_base_agent.py:test_run_async_before_agent_callback_records_artifact_deltatest_run_async_after_agent_callback_records_artifact_deltaEach saves an artifact from the callback (returning
None) and asserts an event carriesartifact_delta == {'<name>': 0}. Both fail onmain(only the agent's own response event is produced) and pass with this change.The 4 failures are in
tests/unittests/models/test_litellm.pylog-level assertions; they pass when run alone or as their own file, and with this change stashed, so they are unrelated to this PR.pyinkandisortreport no changes.Manual End-to-End (E2E) Tests:
Ran the reproduction script from #7478 through a real
RunnerwithInMemorySessionServiceandInMemoryArtifactService:main:artifact_delta in session events: []artifact_delta in session events: [{'report.txt': 0}]Checklist