Skip to content

feat(sessions): add get_user_state(app_name, user_id) to BaseSessionService#5594

Closed
nicolasmota wants to merge 3 commits intogoogle:mainfrom
nicolasmota:feat/get-user-state
Closed

feat(sessions): add get_user_state(app_name, user_id) to BaseSessionService#5594
nicolasmota wants to merge 3 commits intogoogle:mainfrom
nicolasmota:feat/get-user-state

Conversation

@nicolasmota
Copy link
Copy Markdown

@nicolasmota nicolasmota commented May 5, 2026

deleted

nicolasmota and others added 2 commits May 5, 2026 13:19
Adds a public get_user_state(app_name, user_id) method so callers can
read user-scoped state directly without requiring an active session_id.

This closes the API gap that forced callers to either (a) call
list_sessions just to access user state or (b) maintain a separate
process-level cache as a workaround.

Implementations:
- InMemorySessionService: reads from self.user_state dict
- DatabaseSessionService: queries StorageUserState by (app_name, user_id)
- SqliteSessionService: delegates to existing _get_user_state helper
- VertexAiSessionService: raises NotImplementedError (Vertex AI Agent
  Engine API does not expose user state independently of a session)
- BaseSessionService: default raises NotImplementedError so existing
  custom subclasses continue to compile

Returns raw keys without the user: prefix, consistent with how user
state is stored internally (the prefix is applied by the state-merging
layer when building the merged session view).

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 5, 2026

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.

@adk-bot adk-bot added the services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc label May 5, 2026
@adk-bot
Copy link
Copy Markdown
Collaborator

adk-bot commented May 5, 2026

Response from ADK Triaging Agent

Hello @nicolasmota, thank you for your contribution!

It looks like the Contributor License Agreement (CLA) has not been signed yet. Before we can merge this PR, please make sure to sign the CLA. You can find more information and sign it at https://cla.developers.google.com/.

Thanks!

@nicolasmota
Copy link
Copy Markdown
Author

@adk-bot assigned

- base_session_service: fix NotImplementedError message that incorrectly
  suggested list_sessions returns user state; now describes the correct
  workaround (list_sessions + get_session)
- database_session_service: defensive dict(state or {}) guard against NULL
  state column values from legacy migrations
- vertex_ai_session_service: replace inline comment with proper docstring
  explaining why the method is not supported
- tests: add app-level isolation test, add VertexAiSessionService
  NotImplementedError test, remove redundant @pytest.mark.asyncio
  markers (asyncio_mode=auto), add return type annotation to _make_service

Co-authored-by: Cursor <cursoragent@cursor.com>
@nicolasmota nicolasmota closed this May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants