fix: temp-scoped state now visible to subsequent agents in same invocation#4618
fix: temp-scoped state now visible to subsequent agents in same invocation#4618stakeswky wants to merge 3 commits intogoogle:mainfrom
Conversation
…ation When using output_key with a temp: prefix (e.g. output_key='temp:result') in a SequentialAgent, the output was lost because: 1. _trim_temp_delta_state removed temp keys from the event delta BEFORE _update_session_state could apply them to the in-memory session 2. _update_session_state also explicitly skipped temp-prefixed keys This meant agent-2 in a sequential pipeline could never read temp state written by agent-1's output_key. Fix: introduce _apply_temp_state() which writes temp-scoped keys to the in-memory session.state BEFORE the event delta is trimmed. This ensures: - Temp state is available to subsequent agents within the same invocation - Temp state is still stripped from event deltas (not persisted to storage) - All three session services (InMemory, Database, SQLite) behave consistently Fixes google#4564
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
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. |
|
Response from ADK Triaging Agent Hello @stakeswky, thank you for creating this PR! It looks like the Contributor License Agreement (CLA) check has failed. Before we can merge this PR, you'll need to sign the CLA. You can do so at https://cla.developers.google.com/. Thanks! |
5a416ef to
65c59ed
Compare
|
Hi @stakeswky , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Your PR has been received by the team and is currently under review. We will provide feedback as soon as we have an update to share. |
|
Hi @xuanyang15 , can you please review this. |
|
@DeanChensj Could you please help review? |
Signed-off-by: stakeswky <stakeswky@gmail.com>
40ab9d3 to
6d1a3f2
Compare
…ation Merge #4618 ## Summary Fixes #4564 When using `output_key` with a `temp:` prefix (e.g. `output_key='temp:result'`) in a `SequentialAgent`, the output was silently lost. Agent-2 could never read the temp state written by agent-1. ## Root Cause Two issues in `append_event`: 1. `_trim_temp_delta_state()` removed temp keys from the event delta **before** `_update_session_state()` could apply them to the in-memory session 2. `_update_session_state()` also explicitly skipped `temp:`-prefixed keys ```python # Before (broken ordering): async def append_event(self, session, event): event = self._trim_temp_delta_state(event) # temp keys gone! self._update_session_state(session, event) # nothing to apply ``` ## Fix Introduce `_apply_temp_state()` which writes temp-scoped keys to the in-memory `session.state` **before** the event delta is trimmed: ```python # After: async def append_event(self, session, event): self._apply_temp_state(session, event) # temp keys → session.state event = self._trim_temp_delta_state(event) # temp keys removed from delta self._update_session_state(session, event) # non-temp keys applied ``` This ensures: - ✅ Temp state is available to subsequent agents within the same invocation - ✅ Temp state is still stripped from event deltas (not persisted to storage) - ✅ All three session services (InMemory, Database, SQLite) behave consistently ## Files Changed - `src/google/adk/sessions/base_session_service.py`: Added `_apply_temp_state()`, reordered `append_event` logic, removed temp-skip in `_update_session_state` - `src/google/adk/sessions/database_session_service.py`: Added `_apply_temp_state()` call before trim - `src/google/adk/sessions/sqlite_session_service.py`: Added `_apply_temp_state()` call before trim - `tests/unittests/sessions/test_session_service.py`: Updated existing test + added new test for sequential agent scenario ## Testing All 67 session service tests pass across InMemory, Database, and SQLite backends. COPYBARA_INTEGRATE_REVIEW=#4618 from stakeswky:fix/temp-state-output-key b9fc737 PiperOrigin-RevId: 878499263
|
Thank you @stakeswky for your contribution! 🎉 Your changes have been successfully imported and merged via Copybara in commit 2780ae2. Closing this PR as the changes are now in the main branch. |
Summary
Fixes #4564
When using
output_keywith atemp:prefix (e.g.output_key='temp:result') in aSequentialAgent, the output was silently lost. Agent-2 could never read the temp state written by agent-1.Root Cause
Two issues in
append_event:_trim_temp_delta_state()removed temp keys from the event delta before_update_session_state()could apply them to the in-memory session_update_session_state()also explicitly skippedtemp:-prefixed keysFix
Introduce
_apply_temp_state()which writes temp-scoped keys to the in-memorysession.statebefore the event delta is trimmed:This ensures:
Files Changed
src/google/adk/sessions/base_session_service.py: Added_apply_temp_state(), reorderedappend_eventlogic, removed temp-skip in_update_session_statesrc/google/adk/sessions/database_session_service.py: Added_apply_temp_state()call before trimsrc/google/adk/sessions/sqlite_session_service.py: Added_apply_temp_state()call before trimtests/unittests/sessions/test_session_service.py: Updated existing test + added new test for sequential agent scenarioTesting
All 67 session service tests pass across InMemory, Database, and SQLite backends.