> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Firestore for Agent

> Store agent sessions in a Firestore database.

```python firestore_for_agent.py theme={null}
"""
This recipe shows how to store agent sessions in a Firestore database.

Steps:
1. Ensure your gcloud project is enabled with Firestore. Reference https://cloud.google.com/firestore/docs/create-database-server-client-library ?
2. Run: `uv pip install openai google-cloud-firestore agno` to install dependencies
3. Make sure your gcloud project is set up and you have the necessary permissions to access Firestore
4. Run: `python cookbook/06_storage/firestore/firestore_for_agent.py` to run the agent
"""

from agno.agent import Agent
from agno.db.firestore import FirestoreDb
from agno.tools.websearch import WebSearchTools

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

# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
# The only required argument is the collection name.
# Firestore will connect automatically using your google cloud credentials.
# The class uses the (default) database by default to allow free tier access to firestore.
# You can specify a project_id if you'd like to connect to firestore in a different GCP project
db = FirestoreDb(project_id=PROJECT_ID)

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
    db=db,
    tools=[WebSearchTools()],
    add_history_to_context=True,
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    agent.print_response("How many people live in Canada?")
    agent.print_response("What is their national anthem called?")
```

## Run the Example

<Snippet file="create-venv-step.mdx" />

**1. Install dependencies**

```bash theme={null}
uv pip install -U agno ddgs google-cloud-firestore openai
```

**2. Export your OpenAI API key**

```bash Mac/Linux theme={null}
export OPENAI_API_KEY="your_openai_api_key_here"
```

```bash Windows theme={null}
$Env:OPENAI_API_KEY="your_openai_api_key_here"
```

**3. Authenticate with Google Cloud**

Sign in with Application Default Credentials:

```bash theme={null}
gcloud auth application-default login
```

**4. Configure Firestore**

Enable Firestore in your Google Cloud project and replace `PROJECT_ID` in `firestore_for_agent.py` with your own project ID before running.

**5. Run the example**

Save the code above as `firestore_for_agent.py`, then run:

```bash theme={null}
python firestore_for_agent.py
```

Full source: [cookbook/06\_storage/firestore/firestore\_for\_agent.py](https://github.com/agno-agi/agno/blob/v3.0.4/cookbook/06_storage/firestore/firestore_for_agent.py)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.