> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Persistence Module

> Database persistence and session management for PraisonAI

# Persistence Module

The Persistence module provides database adapters and session management for storing agent conversations, runs, and traces.

## Installation

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
pip install praisonai

# For specific database support
pip install "praisonai[postgres]"
pip install "praisonai[redis]"
```

## Quick Start

The recommended way to enable persistence is via the `memory={}` parameter:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent

agent = Agent(
    name="Assistant",
    instructions="You are helpful.",
    memory={
        "db": "postgresql://localhost/mydb",
        "session_id": "my-session"
    }
)

response = agent.start("Hello!")
```

## Supported Databases

### Conversation Stores

| Database   | Install                             | URL Format                       |
| ---------- | ----------------------------------- | -------------------------------- |
| PostgreSQL | `pip install "praisonai[postgres]"` | `postgresql://user:pass@host/db` |
| MySQL      | `pip install "praisonai[mysql]"`    | `mysql://user:pass@host/db`      |
| SQLite     | Built-in                            | `sqlite:///path/to/db.sqlite`    |
| JSON       | Built-in                            | `json:///path/to/data.json`      |

### Knowledge Stores (Vector)

| Database | Install                             |
| -------- | ----------------------------------- |
| Qdrant   | `pip install "praisonai[qdrant]"`   |
| Chroma   | `pip install "praisonai[chroma]"`   |
| Pinecone | `pip install "praisonai[pinecone]"` |
| PGVector | `pip install "praisonai[pgvector]"` |

### State Stores

| Database | Install                            |
| -------- | ---------------------------------- |
| Redis    | `pip install "praisonai[redis]"`   |
| MongoDB  | `pip install "praisonai[mongodb]"` |

## Database Examples

### PostgreSQL

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent

agent = Agent(
    name="Assistant",
    memory={
        "db": "postgresql://user:pass@localhost/mydb",
        "session_id": "user-123"
    }
)
```

### SQLite

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent

agent = Agent(
    name="Assistant",
    memory={
        "db": "sqlite:///./agent.db",
        "session_id": "local-session"
    }
)
```

### Redis

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent

agent = Agent(
    name="Assistant",
    memory={
        "backend": "redis",
        "db": "redis://localhost:6379",
        "session_id": "redis-session"
    }
)
```

## Session Management

Sessions allow you to maintain conversational context:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent

# Create agent with session
agent = Agent(
    name="Assistant",
    memory={"db": "sqlite:///data.db", "session_id": "user-123"}
)

# Conversations persist across runs
response1 = agent.start("Remember my name is Alice")
# Later...
response2 = agent.start("What's my name?")  # Remembers "Alice"
```

## Data Models

### DbMessage

Stored message format:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
{
    "id": "msg-uuid",
    "session_id": "session-123",
    "agent_id": "agent-name",
    "role": "user",  # or "assistant"
    "content": "Message content",
    "timestamp": "2024-01-01T00:00:00Z"
}
```

### DbRun

Execution run record:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
{
    "id": "run-uuid",
    "session_id": "session-123",
    "agent_id": "agent-name",
    "status": "completed",
    "started_at": "2024-01-01T00:00:00Z",
    "completed_at": "2024-01-01T00:00:01Z"
}
```

### DbToolCall

Tool execution record:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
{
    "id": "tool-uuid",
    "run_id": "run-uuid",
    "tool_name": "search",
    "arguments": {"query": "AI news"},
    "result": "Search results...",
    "timestamp": "2024-01-01T00:00:00Z"
}
```

## See Also

* [Database Module](/docs/sdk/praisonaiagents/db/db) - Core database adapters
* [Session Module](/docs/sdk/praisonaiagents/session) - Session management
* [Memory Module](/docs/sdk/praisonaiagents/memory/memory) - Agent memory
