> ## 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.

# Memory

> Give agents persistent memory across sessions with pluggable backends

Memory lets agents remember past conversations, user preferences, and context across sessions.

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

agent = Agent(
    name="Assistant",
    instructions="You are a helpful personal assistant.",
    memory=True,
)

agent.start("My name is Alice and I prefer concise answers.")
```

The user shares preferences in chat; the agent recalls them in later sessions via the configured memory backend.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    subgraph "Memory Flow"
        Input[💬 User Input] --> Store[💾 Memory Store]
        Store --> Recall[🔍 Recall Context]
        Recall --> Response[✅ Contextual Response]
    end

    classDef input fill:#6366F1,stroke:#7C90A0,color:#fff
    classDef process fill:#F59E0B,stroke:#7C90A0,color:#fff
    classDef output fill:#10B981,stroke:#7C90A0,color:#fff

    class Input input
    class Store,Recall process
    class Response output
```

## Quick Start

<Steps>
  <Step title="Level 1 — Bool (simplest)">
    Turn on memory with a single flag — the agent remembers across turns using the default file backend.

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

    agent = Agent(
        name="Assistant",
        instructions="You are a helpful assistant.",
        memory=True,
    )
    agent.start("Remember that I work in software engineering.")
    ```
  </Step>

  <Step title="Level 2 — String (pick a backend)">
    Pass a backend name to choose where memories are stored.

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

    agent = Agent(
        name="Assistant",
        instructions="You are a helpful assistant.",
        memory="sqlite",
    )
    agent.start("Remember that I prefer concise answers.")
    ```
  </Step>

  <Step title="Level 3 — Config class (full control)">
    Use `MemoryConfig` to scope memory per user and auto-extract facts.

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

    agent = Agent(
        name="Assistant",
        instructions="You are a helpful assistant.",
        memory=MemoryConfig(
            backend="sqlite",
            user_id="alice",
            auto_memory=True,
        ),
    )
    agent.start("What do you know about my preferences?")
    ```
  </Step>

  <Step title="Level 4 — Config with continuous learning">
    Add `LearnConfig` to build a long-term persona alongside session memory.

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

    agent = Agent(
        name="Assistant",
        instructions="You are a helpful assistant.",
        memory=MemoryConfig(
            backend="redis",
            user_id="alice",
            learn=LearnConfig(persona=True, insights=True, mode="agentic"),
        ),
    )
    agent.start("I always want answers formatted as bullet points.")
    ```
  </Step>
</Steps>

***

## How It Works

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant Agent
    participant Memory

    User->>Agent: Message
    Agent->>Memory: Store conversation turn
    Agent->>Memory: Retrieve relevant context
    Memory-->>Agent: Past context
    Agent-->>User: Context-aware response
```

| Phase       | What happens                                          |
| ----------- | ----------------------------------------------------- |
| 1. Store    | Each conversation turn is saved to the memory backend |
| 2. Retrieve | Relevant past context is recalled before responding   |
| 3. Respond  | Agent answers with full historical context available  |

***

## Which Backend to Choose?

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph TB
    Q{What's your setup?}
    Q -->|Prototype / single server| F[file backend\ndefault, zero deps]
    Q -->|Single server, persistent| S[sqlite backend\nnpm install...]
    Q -->|Multi-instance / production| R[redis or valkey]
    Q -->|Multi-agent shared memory| M[mem0 or mongodb]
    Q -->|Self-hosted decay-weighted memory| D[dakera]
    Q -->|Anthropic model with long context| C[claude_memory=True]

    classDef decision fill:#F59E0B,stroke:#7C90A0,color:#fff
    classDef backend fill:#6366F1,stroke:#7C90A0,color:#fff

    class Q decision
    class F,S,R,M,D,C backend
```

***

## Configuration Options

<Card icon="code" href="/docs/sdk/reference/python/MemoryConfig">
  Full list of options, types, and defaults — `MemoryConfig`
</Card>

The most common options at a glance:

| Option        | Type                          | Default  | Description                                                               |
| ------------- | ----------------------------- | -------- | ------------------------------------------------------------------------- |
| `backend`     | `str`                         | `"file"` | Storage backend: `file`, `sqlite`, `redis`, `postgres`, `mem0`, `mongodb` |
| `user_id`     | `str \| None`                 | `None`   | User identifier for scoped memory                                         |
| `auto_memory` | `bool`                        | `False`  | Auto-extract and store key facts                                          |
| `learn`       | `bool \| LearnConfig \| None` | `None`   | Enable continuous learning                                                |
| `history`     | `bool`                        | `False`  | Auto-inject session history into context                                  |

***

## Common Patterns

### Pattern 1 — User-scoped memory

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

agent = Agent(
    instructions="You are a personal assistant.",
    memory=MemoryConfig(user_id="user_alice", backend="sqlite"),
)
response = agent.start("What have I told you about my work preferences?")
print(response)
```

### Pattern 2 — History injection for conversation continuity

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

agent = Agent(
    instructions="You are a support agent.",
    memory=MemoryConfig(history=True, history_limit=5),
)
agent.start("Continue from where we left off.")
```

***

## Best Practices

<AccordionGroup>
  <Accordion title="Always set user_id for multi-user apps">
    Without `user_id`, all users share the same memory store. Set `user_id` to a unique identifier per user to keep memories properly scoped and private.
  </Accordion>

  <Accordion title="Use auto_memory for fact extraction">
    Enable `auto_memory=True` to have the agent automatically identify and store important facts from each conversation — names, preferences, decisions — without extra code.
  </Accordion>

  <Accordion title="Combine memory with learning">
    Set `learn=True` inside `MemoryConfig` to enable continuous learning alongside session memory. This gives agents both short-term context (memory) and long-term pattern recognition (learn).
  </Accordion>

  <Accordion title="Backend scaling path">
    Start with `file`, move to `sqlite` when you need durability, then `redis` when you deploy multiple agent instances that share memory.
  </Accordion>
</AccordionGroup>

***

## Related

<CardGroup cols={2}>
  <Card title="Learn" icon="graduation-cap" href="/docs/features/learn">
    Learn — continuous learning from conversations
  </Card>

  <Card title="Knowledge" icon="book" href="/docs/features/knowledge">
    Knowledge — add documents and URLs as agent knowledge
  </Card>
</CardGroup>
