> For the complete documentation index, see [llms.txt](https://docs.aios.foundation/aios-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aios.foundation/aios-docs/aios-kernel/memory.md).

# Memory

### Two-Tier Memory Architecture for Agents

The system employs a two-tier memory architecture consisting of:

1. **Memory Manager (RAM-based):** Handles transient, session-specific data for active agents. Memory is cleared when the agent session ends.
2. **Storage Manager (Persistent Storage):** Ensures long-term storage for evicted or overflowed memory blocks.

### **Memory Manager**

The Memory Manager is responsible for managing temporary memory stored in RAM during an agent's active tasks or sessions.

**Components**

* **Compressed Block:** Primary unit of memory, containing interaction history in a compressed format.
* **Memory Limit:** Defines the maximum amount of memory an agent can use in RAM.
* **Eviction Strategy:** Implements a policy to evict blocks to persistent storage when memory usage exceeds the limit, ensuring efficient memory management.

<figure><img src="/files/6bPObWXwkIFoussLjUWM" alt="" width="375"><figcaption><p>How data swap occurs between memory and storage manager</p></figcaption></figure>

**Memory Flow**

1. Interaction data is compressed into blocks and stored in the agent's memory.
2. Each agent's memory operates within a predefined limit.
3. When the accumulated memory reaches the limit:
   * Blocks are evicted based on the eviction strategy.
   * Evicted blocks are moved to the Storage Manager for persistent storage.

#### Key Modules

| Module                | Purpose                 | Key Classes                                   |
| --------------------- | ----------------------- | --------------------------------------------- |
| **Memory Processing** | Core memory operations  | `BaseMemoryManager`, `MemoryNote`             |
| **Vector Retrieval**  | Semantic search backend | `ChromaRetriever`, `SimpleEmbeddingRetriever` |
| **Content Analysis**  | Cognitive processing    | `execute_memory_content_analyze`              |
| **Memory Evolution**  | Autonomous adaptation   | `execute_memory_evolve`                       |

#### **TODO**

* **Privacy Mechanism:** Add a system to restrict agents from accessing the memory of other agents, ensuring data privacy.
* **Memory Optimization:** Improve the structure and efficiency of the memory management system.
