feat(sessions): add get_user_state(app_name, user_id) to BaseSessionService#5596
Open
nicolasmota wants to merge 1 commit intogoogle:mainfrom
Open
feat(sessions): add get_user_state(app_name, user_id) to BaseSessionService#5596nicolasmota wants to merge 1 commit intogoogle:mainfrom
nicolasmota wants to merge 1 commit intogoogle:mainfrom
Conversation
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
Closes: #5592
Problem:
BaseSessionServicehas no public method to read user-scoped state without an activesession_id. Callers that need to bootstrap user context before a new session exists are forced to call the expensivelist_sessionsor maintain a separate process-level cache as a workaround.Solution:
Add
get_user_state(app_name, user_id) -> dict[str, Any]toBaseSessionService. Implemented inInMemorySessionService,DatabaseSessionService, andSqliteSessionService.VertexAiSessionServiceraisesNotImplementedErrorbecause the Vertex AI Agent Engine API does not expose user state independently of a session. The default inBaseSessionServicealso raisesNotImplementedErrorto preserve backward compatibility for existing custom subclasses.Keys are returned without the
user:prefix, consistent with how user state is stored internally (the prefix is applied by the state-merging layer).Testing Plan
Unit Tests:
New test file:
tests/unittests/sessions/test_get_user_state.py— 19 test cases parameterised acrossIN_MEMORY,DATABASE, andSQLITEbackends covering:{}when no state exists{}{}session_idis createdVertexAiSessionServiceraisesNotImplementedErrorplatform darwin -- Python 3.11.12, pytest-9.0.2 19 passed in 2.33s
Manual E2E Tests:
Not applicable for this change — the method is a read-only query on existing storage with no behavioural side-effects on session or event handling. Existing E2E tests are unaffected.
Checklist