feat: add pagination support to DatabaseSessionService.list_sessions#1
Open
feat: add pagination support to DatabaseSessionService.list_sessions#1
Conversation
Add page_size and page_token parameters to list_sessions across all session service implementations (DatabaseSessionService, InMemorySessionService, SqliteSessionService, VertexAiSessionService). - page_size defaults to 20, clamped to max 100 - page_token is base64-encoded offset for stateless cursor pagination - Results ordered by update_time DESC (most recent first) - ListSessionsResponse gains next_page_token field - Fully backward compatible: existing callers without pagination args get the first page (up to 20 sessions) Closes google#4621
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.
Summary
Resolves google#4621
DatabaseSessionService.list_sessions()(and all other session service implementations) now support pagination viapage_sizeandpage_tokenparameters.Changes
base_session_service.pynext_page_token: Optional[str]field toListSessionsResponselist_sessionsabstract signature withpage_sizeandpage_tokenkwargs_resolve_page_size,_encode_page_token,_decode_page_tokendatabase_session_service.pyORDER BY update_time DESC+LIMIT/OFFSETto the SQL querypage_size + 1rows to detect next page without a separate COUNT querynext_page_tokenwhen more results existin_memory_session_service.pylast_update_timedescendingsqlite_session_service.pyORDER BY update_time DESC LIMIT ? OFFSET ?approach as DatabaseSessionServicevertex_ai_session_service.pyTests
Backward Compatibility
All parameters are optional with sensible defaults:
page_sizedefaults to 20 (max 100)page_tokendefaults toNone(first page)next_page_token=Nonewhen there are ≤20 resultsAll 88 existing + new tests pass.