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

# Storage

> Persist agent sessions, chat history, and state with 13 database backends.

Storage backends persist agent sessions, chat history, and state. Use any database that fits your infrastructure.

```python theme={null}
from agno.agent import Agent
from agno.db.postgres import PostgresDb

agent = Agent(
    db=PostgresDb(db_url="postgresql://ai:ai@localhost:5532/ai"),
    add_history_to_context=True,
)

agent.print_response("Hello!")
# Chat history persists across sessions
agent.print_response("What did I just say?")
```

## Supported Databases

| Database    | Import                                          | Best For          |
| ----------- | ----------------------------------------------- | ----------------- |
| PostgreSQL  | `from agno.db.postgres import PostgresDb`       | Production, teams |
| SQLite      | `from agno.db.sqlite import SqliteDb`           | Local development |
| MongoDB     | `from agno.db.mongodb import MongoDb`           | Document stores   |
| Redis       | `from agno.db.redis import RedisDb`             | Caching, speed    |
| DynamoDB    | `from agno.db.dynamodb import DynamoDb`         | AWS serverless    |
| Firestore   | `from agno.db.firestore import FirestoreDb`     | GCP serverless    |
| MySQL       | `from agno.db.mysql import MysqlDb`             | MySQL users       |
| SingleStore | `from agno.db.singlestore import SingleStoreDb` | Real-time         |
| SurrealDB   | `from agno.db.surrealdb import SurrealDb`       | Multi-model       |
| GCS         | `from agno.db.gcs import GCSDb`                 | Cloud storage     |
| JSON        | `from agno.db.json import JsonDb`               | Simple files      |
| In-Memory   | `from agno.db.memory import InMemoryDb`         | Testing           |

## Examples by Database

### PostgreSQL

Production-ready persistence.

```python cookbook/06_storage/postgres/postgres_for_agent.py theme={null}
from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.tools.duckduckgo import DuckDuckGoTools

db = PostgresDb(db_url="postgresql+psycopg://ai:ai@localhost:5532/ai")

agent = Agent(
    db=db,
    tools=[DuckDuckGoTools()],
    add_history_to_context=True,
)

agent.print_response("How many people live in Canada?")
agent.print_response("What is their national anthem called?")
```

### SQLite

Simple local persistence.

```python cookbook/06_storage/sqlite/sqlite_for_agent.py theme={null}
from agno.agent import Agent
from agno.db.sqlite import SqliteDb

agent = Agent(
    db=SqliteDb(db_file="agent.db"),
    add_history_to_context=True,
)

agent.print_response("Remember: My favorite color is blue")
agent.print_response("What is my favorite color?")
```

### MongoDB

Document-based storage.

```python cookbook/06_storage/mongo/mongodb_for_agent.py theme={null}
from agno.agent import Agent
from agno.db.mongodb import MongoDb

agent = Agent(
    db=MongoDb(
        uri="mongodb://localhost:27017",
        database="agno",
        collection="agents",
    ),
    add_history_to_context=True,
)
```

### Redis

High-speed caching.

```python cookbook/06_storage/redis/redis_for_agent.py theme={null}
from agno.agent import Agent
from agno.db.redis import RedisDb

agent = Agent(
    db=RedisDb(url="redis://localhost:6379"),
    add_history_to_context=True,
)
```

### DynamoDB

AWS serverless storage.

```python cookbook/06_storage/dynamodb/dynamo_for_agent.py theme={null}
from agno.agent import Agent
from agno.db.dynamodb import DynamoDb

agent = Agent(
    db=DynamoDb(
        table_name="agno-agents",
        region="us-east-1",
    ),
    add_history_to_context=True,
)
```

### Firestore

GCP serverless storage.

```python cookbook/06_storage/firestore/firestore_for_agent.py theme={null}
from agno.agent import Agent
from agno.db.firestore import FirestoreDb

agent = Agent(
    db=FirestoreDb(
        project_id="your-project",
        collection="agents",
    ),
    add_history_to_context=True,
)
```

### In-Memory

For testing and development.

```python cookbook/06_storage/in_memory/in_memory_storage_for_agent.py theme={null}
from agno.agent import Agent
from agno.db.memory import InMemoryDb

agent = Agent(
    db=InMemoryDb(),
    add_history_to_context=True,
)
```

## Storage for Teams and Workflows

Storage works the same way for teams and workflows.

### Team Storage

```python cookbook/06_storage/postgres/postgres_for_team.py theme={null}
from agno.team import Team
from agno.db.postgres import PostgresDb

team = Team(
    agents=[...],
    db=PostgresDb(db_url="postgresql://..."),
)
```

### Workflow Storage

```python cookbook/06_storage/postgres/postgres_for_workflow.py theme={null}
from agno.workflow import Workflow
from agno.db.postgres import PostgresDb

workflow = Workflow(
    db=PostgresDb(db_url="postgresql://..."),
)
```

## Run Examples

```bash theme={null}
git clone https://github.com/agno-agi/agno.git
cd agno/cookbook/06_storage

# PostgreSQL
python postgres/postgres_for_agent.py

# SQLite (no deps)
python sqlite/sqlite_for_agent.py

# In-Memory (no deps)
python in_memory/in_memory_storage_for_agent.py
```
