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

# Memory

> Persistent agent memory that works across sessions

The `--memory` flag and `memory` command enable persistent memory for agents, allowing them to remember context across sessions.

## Quick Start

### Show Memories

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai memory show
```

<Frame>
  <img src="https://mintcdn.com/praisonai/SX0Y8_-DRBjzOTnt/docs/cli/memory-show-stored-memories.gif?s=1fa814c9e2deed2457911d9e9c7b4cfc" alt="Show stored memories example" width="1497" height="1104" data-path="docs/cli/memory-show-stored-memories.gif" />
</Frame>

### Use Memory Flag

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Enable memory for agent
praisonai "count to 5" --memory
```

<Frame>
  <img src="https://mintcdn.com/praisonai/aAYxXsQWSI9rL4cN/docs/cli/memory-with-memory.gif?s=1e1bc5120272309dabb72bf0ced787eb" alt="With memory flag example" width="1216" height="897" data-path="docs/cli/memory-with-memory.gif" />
</Frame>

## Usage

<img src="https://mintcdn.com/praisonai/fT4nF3hY6KPMOPvS/docs/cli/memory-manage-persistent-memory-for-a.gif?s=0de9f00485accb290722aebe91139376" alt="Manage Persistent Memory" width="1497" height="1104" data-path="docs/cli/memory-manage-persistent-memory-for-a.gif" />

### Enable Memory

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Enable memory for agent (persists across sessions)
praisonai "My name is John" --memory

# Memory with user isolation
praisonai "Remember my preferences" --memory --user-id user123
```

**Expected Output:**

```
🧠 Memory enabled

╭─ Agent Info ─────────────────────────────────────────────────────────────────╮
│  👤 Agent: DirectAgent                                                       │
│  Role: Assistant                                                             │
│  Memory: Enabled (user: user123)                                            │
╰──────────────────────────────────────────────────────────────────────────────╯

╭────────────────────────────────── Response ──────────────────────────────────╮
│ Nice to meet you, John! I'll remember your name for future conversations.   │
╰──────────────────────────────────────────────────────────────────────────────╯

💾 Memory saved: name="John"
```

## Memory Commands

### Show Memory

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai memory show
```

**Output:**

```
╭─ Memory Statistics ──────────────────────────────────────────────────────────╮
│  Short-term: 5 items                                                        │
│  Long-term: 12 items                                                        │
│  Entities: 3 items                                                          │
│  Episodic: 8 items                                                          │
╰──────────────────────────────────────────────────────────────────────────────╯
```

### Add Memory

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai memory add "User prefers Python"
```

### Search Memory

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai memory search "Python"
```

### Clear Memory

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Clear short-term memory
praisonai memory clear

# Clear all memory
praisonai memory clear all
```

### Session Management

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Save session
praisonai memory save my_session

# Resume session
praisonai memory resume my_session

# List saved sessions
praisonai memory sessions
```

### Checkpoints

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Create checkpoint
praisonai memory checkpoint

# Restore checkpoint
praisonai memory restore <checkpoint_id>

# List checkpoints
praisonai memory checkpoints
```

### Help

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai memory help
```

## Memory Types

| Type       | Description                          | Persistence  |
| ---------- | ------------------------------------ | ------------ |
| Short-term | Rolling buffer of recent context     | Auto-expires |
| Long-term  | Important facts sorted by importance | Persistent   |
| Entity     | People, places, organizations        | Persistent   |
| Episodic   | Date-based interaction history       | Persistent   |

## How It Works

1. **Capture**: Agent extracts important information from conversations
2. **Categorize**: Information is sorted into memory types
3. **Store**: Memories are persisted to storage
4. **Inject**: Relevant memories are injected into future conversations

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
flowchart LR
    A[Conversation] --> B[Extract Info]
    B --> C{Categorize}
    C -->|Facts| D[Long-term]
    C -->|Context| E[Short-term]
    C -->|Entities| F[Entity]
    C -->|Events| G[Episodic]
    D --> H[Storage]
    E --> H
    F --> H
    G --> H
    H --> I[Future Conversations]
```

## Storage Options

| Option              | Dependencies | Description                       |
| ------------------- | ------------ | --------------------------------- |
| `memory=True`       | None         | File-based JSON storage (default) |
| `memory="file"`     | None         | Explicit file-based storage       |
| `memory="sqlite"`   | Built-in     | SQLite with indexing              |
| `memory="chromadb"` | chromadb     | Vector/semantic search            |

## Programmatic Usage

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

# Enable memory with a single parameter
agent = Agent(
    name="Personal Assistant",
    instructions="You are a helpful assistant that remembers user preferences.",
    memory={"user_id": "user123"}  # Enables memory with user isolation
)

# Memory is automatically injected into conversations
result = agent.start("My name is John and I prefer Python")
# Agent will remember this for future conversations
```

### Advanced Features

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

memory = FileMemory(memory={"user_id": "user123"})

# Session Save/Resume
memory.save_session("project_session", conversation_history=[...])
memory.resume_session("project_session")

# Context Compression
memory.compress(llm_func=lambda p: agent.chat(p), max_items=10)

# Checkpointing
memory.create_checkpoint("before_refactor", include_files=["main.py"])
memory.restore_checkpoint("before_refactor", restore_files=True)

# Slash Commands
memory.handle_command("/memory show")
memory.handle_command("/memory save my_session")
```

## Best Practices

<Tip>
  Use `--user-id` to isolate memory per user in multi-user applications.
</Tip>

<Warning>
  Memory storage grows over time. Use `memory clear` periodically to manage storage.
</Warning>

| Do                                     | Don't                     |
| -------------------------------------- | ------------------------- |
| Use user isolation for multi-user apps | Share memory across users |
| Clear short-term memory regularly      | Let memory grow unbounded |
| Use checkpoints before major changes   | Skip backups              |
| Search before adding duplicates        | Add redundant memories    |

## Related

* [Memory Concept](/concepts/memory)
* [Auto Memory CLI](/cli/auto-memory)
* [Session CLI](/cli/session)
