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.
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
- Ensure your gcloud project is enabled with Firestore. See the Firestore documentation
- Install dependencies:
uv pip install agno openai google-cloud-firestore agno - Make sure your gcloud project is set up and you have the necessary permissions to access Firestore
Params
| Parameter | Type | Default | Description |
|---|---|---|---|
id | Optional[str] | - | Database ID. Derived deterministically from project or client when omitted. |
db_client | Optional[Client] | - | The Firestore client to use. |
project_id | Optional[str] | - | The GCP project ID for Firestore. |
session_collection | Optional[str] | - | Name of the collection to store sessions. |
runs_collection | Optional[str] | None | Storage name for individual runs. Defaults to agno_runs, or <session_collection>_runs when a custom session name is supplied. |
memory_collection | Optional[str] | - | Name of the collection to store memories. |
metrics_collection | Optional[str] | - | Name of the collection to store metrics. |
eval_collection | Optional[str] | - | Name of the collection to store evaluation runs. |
knowledge_collection | Optional[str] | - | Name of the collection to store knowledge documents. |
traces_collection | Optional[str] | - | Name of the collection to store traces. |
spans_collection | Optional[str] | - | Name of the collection to store spans. |