Skip to content

feat(session): add GetUserState for parity with adk-python#1159

Open
mdabydeen wants to merge 1 commit into
google:mainfrom
mdabydeen:feat/session-get-user-state
Open

feat(session): add GetUserState for parity with adk-python#1159
mdabydeen wants to merge 1 commit into
google:mainfrom
mdabydeen:feat/session-get-user-state

Conversation

@mdabydeen

Copy link
Copy Markdown

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

2. Problem / Solution:

Problem: adk-python's BaseSessionService exposes get_user_state(app_name, user_id) to read user-scoped state without requiring an active session — useful for bootstrapping context before create_session without an expensive list_sessions + get_session round trip. session.Service in adk-go has no equivalent, even though the in-memory backend already stores this data internally (inMemoryService.userState) and the database backend already has a helper (fetchStorageUserState) that could back it directly.

Solution:

  • Add GetUserState(ctx, *GetUserStateRequest) (*GetUserStateResponse, error) to the session.Service interface.
  • Implement it in session/inmemory.go using the existing userState map.
  • Implement it in session/database/service.go using the existing fetchStorageUserState helper.
  • In session/vertexai/vertexai.go, return an explicit "not supported" error, mirroring adk-python's VertexAiSessionService.get_user_state, which also doesn't support this.
  • Update the FakeSessionService test double in server/adkrest/internal/fakes to satisfy the interface.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Added a shared GetUserState battery to session/sessiontestsuite, gated behind a new SuiteOptions.SupportsGetUserState flag, covering: empty state for unknown users, reading un-prefixed keys set both at session-create time and via a later AppendEvent state delta, and per-user isolation. Opted in for the in-memory and database backends (both of which now pass it). Added a standalone unit test asserting the Vertex AI backend returns an error, since that backend's contract-test run is driven by recorded gRPC fixtures I can't regenerate without live GCP credentials.

$ go test -race -mod=readonly -count=1 -shuffle=on ./...
ok  	google.golang.org/adk/v2/session	...
ok  	google.golang.org/adk/v2/session/database	...
ok  	google.golang.org/adk/v2/session/vertexai	...
... (all other packages ok)

go build, go vet, and go mod tidy -diff are all clean.

Manual End-to-End (E2E) Tests:

N/A — internal service API addition, covered by unit/contract tests above.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end. (N/A, see above)
  • Any dependent changes have been merged and published in downstream modules. (N/A)

@google-cla

google-cla Bot commented Jul 16, 2026

Copy link
Copy Markdown

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.

Adds Service.GetUserState(app_name, user_id) to read user-scoped state
without requiring an active session, matching adk-python's
BaseSessionService.get_user_state. Implemented for InMemoryService
(backed by the existing userState map) and the database service
(backed by the existing fetchStorageUserState helper); the Vertex AI
backend returns an explicit unsupported error, matching Python's
VertexAiSessionService.

Fixes google#1158

Author: Mike Dabydeen <mdabydeen@gmail.com>
@mdabydeen
mdabydeen force-pushed the feat/session-get-user-state branch from 18ecb1e to 37ad2cd Compare July 16, 2026 00:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

session.Service is missing GetUserState (parity with adk-python)

1 participant