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

# Memory

> Give your agents persistent memory - remember conversations and learn about users

## Overview

Memory enables agents to remember conversations and learn about users across sessions. It maintains chat history, generates summaries, and builds user profiles for personalized interactions.

Memory separates **saving** from **loading**: save flags control what is persisted to storage, while load flags control what is injected into subsequent runs. This allows fine-grained control — for example, saving full chat history while only injecting summaries to reduce token usage.

## Installation

Memory requires a storage backend to persist data. Choose the storage option that fits your deployment needs.

<Note>
  **Example: Setting up Memory with SQLite**

  For local development and testing, use SQLite storage:

  ```bash theme={null}
  uv pip install "upsonic[sqlite-storage]"
  ```

  **Other storage options:**

  * `[redis-storage]` - Redis for distributed, high-performance systems
  * `[postgres-storage]` - PostgreSQL for production, multi-node deployments
  * `[mongo-storage]` - MongoDB for document-based, scalable systems
  * `[mem0-storage]` - Mem0 Platform integration

  For production deployments, PostgreSQL or Redis are recommended. See [Storage Options](/concepts/memory/storage/sqlite) for detailed configuration.
</Note>

## Key Features

* **Conversation History**: Persist complete chat history across sessions
* **Session Summaries**: Auto-generate condensed conversation summaries
* **User Profiles**: Extract and learn user traits from interactions
* **Save/Load Separation**: Independently control what is saved vs. what is injected into context
* **Multiple Storage Backends**: SQLite, Redis, PostgreSQL, MongoDB, or in-memory
* **Shared Storage**: Same storage backend can be used by both Memory and [KnowledgeBase](/concepts/knowledgebase/advanced/storage-persistence) for unified persistence
* **Sync & Async Support**: Both synchronous and asynchronous storage operations
* **HITL Checkpointing**: Automatic checkpoint saving for Human-in-the-Loop resumption

## Quick Start

```python theme={null}
from upsonic import Agent, Task
from upsonic.storage.memory import Memory
from upsonic.storage.sqlite import SqliteStorage

storage = SqliteStorage(db_file="memory.db")

memory = Memory(
    storage=storage,
    session_id="session_001",
    user_id="user_123",
    full_session_memory=True,    # Save chat history
    summary_memory=True,         # Save summaries
    user_analysis_memory=True,   # Save user profiles
    model="anthropic/claude-sonnet-4-5"
)

agent = Agent("anthropic/claude-sonnet-4-5", memory=memory)

result1 = agent.do(Task("My name is Alice and I'm a Python developer"))

result2 = agent.do(Task("What's my name and expertise?"))
print(result2)  # Alice, Python developer
```

## Save vs Load Flags

Each memory type has a **save** flag and a **load** flag. By default, the load flag mirrors the save flag.

| Save Flag              | Load Flag                   | Purpose           |
| ---------------------- | --------------------------- | ----------------- |
| `full_session_memory`  | `load_full_session_memory`  | Chat history      |
| `summary_memory`       | `load_summary_memory`       | Session summaries |
| `user_analysis_memory` | `load_user_analysis_memory` | User profiles     |

```python theme={null}
memory = Memory(
    storage=storage,
    session_id="session_001",
    user_id="user_123",
    full_session_memory=True,         # Save full chat history
    summary_memory=True,              # Save summaries
    user_analysis_memory=True,        # Save user profiles
    load_full_session_memory=False,   # Don't inject raw history
    load_summary_memory=True,         # Inject summary only
    load_user_analysis_memory=True,   # Inject user profile
    model="anthropic/claude-sonnet-4-5"
)
```

## Memory Types

| Type                     | Purpose                       | Requires              |
| ------------------------ | ----------------------------- | --------------------- |
| **Conversation Memory**  | Full chat history persistence | `session_id`          |
| **Summary Memory**       | Condensed session summaries   | `session_id`, `model` |
| **User Analysis Memory** | User profile extraction       | `user_id`, `model`    |

## Storage Backends

| Backend           | Use Case                       | Persistence                  |
| ----------------- | ------------------------------ | ---------------------------- |
| `SqliteStorage`   | Local development, single-node | File-based                   |
| `RedisStorage`    | Distributed, high-performance  | In-memory + optional persist |
| `PostgresStorage` | Production, multi-node         | Database                     |
| `MongoStorage`    | Document-based, scalable       | Database                     |
| `InMemoryStorage` | Testing, ephemeral             | None                         |

## Storage Integrations

<Card title="Browse All Memory Storage Backends" icon="hard-drive" href="/integrations/overview#memory-storage" horizontal>
  SQLite, PostgreSQL, Redis, MongoDB, Mem0, In-Memory, JSON — plus async variants for all backends.
</Card>

## Navigation

* [Memory Attributes](/concepts/memory/attributes) - All configuration options
* [Choosing Memory Types](/concepts/memory/choosing-right-memory-types) - Select the right memory for your use case
* [Memory Types](/concepts/memory/memory-types/conversation-memory) - Conversation, Summary, User Analysis
* [Examples](/concepts/memory/examples/basic-memory-example) - Working examples
