# 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="https://4233234616-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5h7XvlMFgKMtRboLGG1i%2Fuploads%2FYS5uwcZ2azGmLs7ENGtp%2Fmemory.png?alt=media&#x26;token=6195960e-0695-4010-b6c8-a9620b03fac0" 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.
