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

Using pip

pip install google-adk-firestore-session

Using uv

uv add google-adk-firestore-session

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.7.tar.gz (173.2 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.7-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for google_adk_firestore_session-0.1.7.tar.gz
Algorithm Hash digest
SHA256 45edd3abd34cbf3772c358e921dde6d208edc026af1d08fc44d7f608b1ce0436
MD5 01c77e4580c22924dd3276eed635c365
BLAKE2b-256 288011cbf544f76955aff563bbeb0c57a71af13f9118d971ac2134b86d2b2ebf

See more details on using hashes here.

Provenance

The following attestation bundles were made for google_adk_firestore_session-0.1.7.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.7-py3-none-any.whl.

File metadata

File hashes

Hashes for google_adk_firestore_session-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 bdcb8649ba7d02361703a77d430346559e8477fb260cea2802fb898ec38440e9
MD5 2d0e85d57175909c8137884177a0e398
BLAKE2b-256 20cc04b5e34386b362ac67f12922fa046892c2f79ff3e7fc14d9ad0481c10b9f

See more details on using hashes here.

Provenance

The following attestation bundles were made for google_adk_firestore_session-0.1.7-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