feat: add FirestoreSessionService for serverless session persistence#104
Open
anmolg1997 wants to merge 1 commit intogoogle:mainfrom
Open
feat: add FirestoreSessionService for serverless session persistence#104anmolg1997 wants to merge 1 commit intogoogle:mainfrom
anmolg1997 wants to merge 1 commit intogoogle:mainfrom
Conversation
Adds a BaseSessionService implementation backed by Google Cloud Firestore, providing persistent, serverless session storage suitable for Cloud Run, Cloud Functions, and other GCP environments. Key design decisions: - Events stored in Firestore subcollections to avoid 1MB doc limit - Three-tier state management (app/user/session) matching ADK conventions - Atomic state updates via Firestore transactions (race-condition safe) - Batch writes for bulk event deletion (500-doc chunks) - Server-side query limits via limit_to_last() for num_recent_events - google-cloud-firestore as an optional dependency Includes 19 unit tests with a lightweight in-memory Firestore mock. Fixes google#103 Ref: google/adk-python#3776, google/adk-python#4439
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
Adds a
FirestoreSessionService— aBaseSessionServiceimplementation backed by Google Cloud Firestore, providing persistent, serverless session storage for Cloud Run, Cloud Functions, and other GCP environments where managing a SQL database is undesirable.This was originally submitted as google/adk-python#4439, where maintainer @rohityan directed it to this community repo.
Changes
src/google/adk_community/sessions/firestore_session_service.py— full implementationtests/unittests/sessions/test_firestore_session_service.py— 19 unit tests with lightweight in-memory Firestore mock (no GCP project required)src/google/adk_community/sessions/__init__.py— exportFirestoreSessionServicepyproject.toml— addfirestoreoptional dependency groupDesign Decisions
list_sessionsAsyncWriteBatchin 500-doc chunksnum_recent_eventslimit_to_last()instead of client-side slicingcreate_sessionreuses state returned from transactional updatesgoogle-cloud-firestoreimported at runtime with clear error messageAddresses Review Feedback
All issues raised by Gemini Code Assist on the original PR have been addressed:
create_sessionandappend_event→ Firestore transactionslist_sessions→ single shared fetchlimit_to_last()AsyncWriteBatchwith chunkingTest Plan
test_session_state_managementonmain)Fixes #103
Ref: google/adk-python#3776