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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aios.foundation/aios-docs/aios-kernel/memory.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
