Firestore

Use Firestore for agent session storage and persistence.

Agno supports using Firestore as a database with the FirestoreDb class.

You can get started with Firestore following their Get Started guide.

Usage

Start in a virtual environment and set the model key before running the example.

Set OpenAI Key

Set your OPENAI_API_KEY as an environment variable. You can get one from OpenAI.

export OPENAI_API_KEY=sk-***

You need to provide either project_id or db_client to the FirestoreDb class. Configure Application Default Credentials (gcloud auth application-default login locally, or GOOGLE_APPLICATION_CREDENTIALS for a service account). The project must already have a Firestore database and your identity must have data access. The client does not provision the project or database.

firestore_for_agent.py
from agno.agent import Agent
from agno.db.firestore import FirestoreDb

PROJECT_ID = "agno-os-test"  # Use your project ID here

# Setup the Firestore database
db = FirestoreDb(project_id=PROJECT_ID)

# Setup your Agent with the Database
agent = Agent(db=db)

Prerequisites

  1. Ensure your gcloud project is enabled with Firestore. See the Firestore documentation
  2. Install dependencies: uv pip install agno openai google-cloud-firestore agno
  3. Make sure your gcloud project is set up and you have the necessary permissions to access Firestore

Params

ParameterTypeDefaultDescription
idOptional[str]-Database ID. Derived deterministically from project or client when omitted.
db_clientOptional[Client]-The Firestore client to use.
project_idOptional[str]-The GCP project ID for Firestore.
session_collectionOptional[str]-Name of the collection to store sessions.
runs_collectionOptional[str]NoneStorage name for individual runs. Defaults to agno_runs, or <session_collection>_runs when a custom session name is supplied.
memory_collectionOptional[str]-Name of the collection to store memories.
metrics_collectionOptional[str]-Name of the collection to store metrics.
eval_collectionOptional[str]-Name of the collection to store evaluation runs.
knowledge_collectionOptional[str]-Name of the collection to store knowledge documents.
traces_collectionOptional[str]-Name of the collection to store traces.
spans_collectionOptional[str]-Name of the collection to store spans.