Skip to main content

Firestore Session Manager for Google ADK

Project description

Python Tests Python 3.11+ License: Apache 2.0

Google ADK Firestore Session

A specialized implementation of the BaseSessionService that uses Google Cloud Firestore for persisting application sessions, user states, and event logs.

Overview

This package provides the FirestoreSessionService class, which handles the lifecycle of sessions within the Google ADK (Agent Development Kit) framework. It organizes data in a hierarchical Firestore structure:

  • apps/{app_name}: Global application state.
  • apps/{app_name}/users/{user_id}: Persistent user-specific state.
  • apps/{app_name}/users/{user_id}/sessions/{session_id}: Individual session data and state.
  • apps/{app_name}/users/{user_id}/sessions/{session_id}/events/{event_id}: Historical event logs for the session.

Installation

You can include this package in your project's dependencies using the Git URL.

Using pip

pip install git+https://github.com/mohammadshamma/google-adk-firestore-session.git

Using uv (pyproject.toml)

dependencies = [
    "google-adk-firestore-session @ git+https://github.com/mohammadshamma/google-adk-firestore-session.git"
]

Configuration

The FirestoreSessionService can be configured via constructor arguments, environment variables, or through the built-in ADK factory.

Precedence

  1. Constructor Arguments: Explicit project and database passed to the class.
  2. Environment Variables: GOOGLE_CLOUD_PROJECT and GOOGLE_DATABASE.
  3. Default Credentials: Standard Google Cloud application default credentials.

Usage with Google ADK

To use the FirestoreSessionService with Google ADK, register the provided factory with the ADK ServiceRegistry. This allows you to point your agents to Firestore using a simple URI.

1. Register the Service

In your main entry point (e.g., serving.py), import and register the factory.

from google.adk.cli.service_registry import get_service_registry
from firestore_session import firestore_session_service_factory

# Register the "firestore" scheme
get_service_registry().register_session_service(
    "firestore", 
    firestore_session_service_factory
)

2. Configure the ADK App

Pass the URI to get_fast_api_app. The URI format is firestore://[project-id]/[database-name].

from google.adk.cli.fast_api import get_fast_api_app

app = get_fast_api_app(
    agents_dir="path/to/agents",
    # Connect to a specific project and database instance
    session_service_uri="firestore://my-project-id/my-database", 
    web=True
)

Standalone Usage

from firestore_session import FirestoreSessionService

# Explicitly passing project/database
session_service = FirestoreSessionService(
    project="my-project-id",
    database="my-database"
)

# Or use environment variables (GOOGLE_CLOUD_PROJECT, etc.)
session_service = FirestoreSessionService()

Dependencies

  • google-adk: Core agent framework.
  • google-cloud-firestore: Official Firestore client.

Development

Running Tests

Tests use pytest. Ensure you have a Firestore emulator or a project configured for testing.

pytest tests/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

google_adk_firestore_session-0.1.5.tar.gz (172.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

google_adk_firestore_session-0.1.5-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file google_adk_firestore_session-0.1.5.tar.gz.

File metadata

File hashes

Hashes for google_adk_firestore_session-0.1.5.tar.gz
Algorithm Hash digest
SHA256 b0faceeccc1240a6b3e0cad095a300b5cac50fc7003d2b46350c5f3a9898f8f5
MD5 735b0aa26cfb2ee64b19eb1be915e434
BLAKE2b-256 b479a74f4a5b00e918e94a004b6ff7f8e6842047b216ba7c49fe55387ad567ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for google_adk_firestore_session-0.1.5.tar.gz:

Publisher: release.yml on mohammadshamma/google-adk-firestore-session

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file google_adk_firestore_session-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for google_adk_firestore_session-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 00335f570a0fefa00b859f0ddb3704f555e7caf90e1c26325db85fb88da81cbc
MD5 3568e0a9deaebaa11b5db0e8b4d68c0b
BLAKE2b-256 265cb8aeb2bd69a492b8b7aee033b53a459e8abb4fe107a9139df9e48104b9d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for google_adk_firestore_session-0.1.5-py3-none-any.whl:

Publisher: release.yml on mohammadshamma/google-adk-firestore-session

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page