← 返回 Dashboard

📄 MemGPT: Towards LLMs as Operating Systems

📅 2023 📎 arXiv: 2310.08560
👤 Charles Packer, Sarah Wooders, Kevin Lin, Vivian Fang, Shishir G. Patil, Ion Stoica, Joseph E. Gonzalez
agent memory virtual-memory long-context OS-analogy
一句话总结: 提出 MemGPT —— 受操作系统虚拟内存启发的 LLM Agent 系统,通过分层存储(Main Context + External Context)和自主内存管理函数,让有限上下文窗口的 LLM 获得"无限记忆"的幻觉。

💡 核心洞察:Memory-as-OS 类比

操作系统 (OS)MemGPT说明
RAM(物理内存)Main Context(LLM prompt)快速访问但容量有限
Disk(磁盘)External Context(外部数据库)容量无限但需要检索
Virtual Memory(虚拟内存)Virtual Context Management自动在两层间调度数据
OS Memory ManagerMemGPT 控制流自主决定 paging/eviction
Page Fault需要的信息不在 main context 中触发 archival_memory_search

🏆 核心贡献

  1. Virtual Context Management — 虚拟上下文管理,让有限 context window 的 LLM 获得"无限记忆"
  2. 分层存储架构 — Main Context (system + working context + FIFO queue) + External Context (recall + archival)
  3. Self-directed Memory — Agent 自主决定何时读写记忆,无需人工干预
  4. Inner Thoughts — 私有推理链条,决定下一步记忆操作
  5. 两个应用验证 — 多会话对话 + 超长文档 QA,均显著超越固定上下文基线

🏗️ MemGPT 架构解析

Main Context(= LLM 的 prompt tokens)

组件类型说明
System Instructions只读MemGPT 控制流描述、函数 schema、角色设定
Working Context读写Agent 的"便签本"。存储关键事实 (如用户偏好、当前任务状态)
FIFO Message QueueFIFO最近对话消息。满时自动将最旧消息 evict 到 recall storage
Function Results临时最近一次函数调用的返回结果

External Context(= 外部存储)

📝 Recall Storage

内容:完整对话历史(从 FIFO 队列 evict 出的消息)

访问:按日期/关键词搜索

用途:恢复过去的对话上下文

类比:OS 的 swap space

🗄️ Archival Storage

内容:任意持久数据(文档、长期知识)

访问:embedding-based retrieval (insert/search)

用途:超大文档 QA、跨会话知识

类比:OS 的 disk/filesystem

控制流:Self-directed Memory Management

MemGPT 的核心创新:Agent 自己决定何时执行内存操作。具体流程:

  1. 收到用户消息 → 追加到 FIFO 队列
  2. LLM 生成 inner thoughts(私有推理,用户不可见)
  3. 基于推理决定执行函数:core_memory_append, archival_memory_search, send_message
  4. 函数结果写回 main context → 循环,直到 Agent 选择 send_message
  5. 当 FIFO 队列接近上限 → 自动 evict 最旧消息到 recall storage

关键函数列表

函数作用类比
core_memory_append向 working context 追加信息写入 RAM 缓存
core_memory_replace更新 working context 中的信息修改 RAM 缓存
recall_memory_search搜索对话历史从 swap 读取
archival_memory_insert向归档存储写入数据写入磁盘
archival_memory_search从归档存储检索数据磁盘读取
send_message向用户发送回复I/O 输出

📊 实验结果

任务基线MemGPT提升
多会话对话
(MSC dataset)
固定 context LLM
丢失历史信息
通过 recall/archival 保持
跨会话记忆
显著提升
知识保留率
文档 QA
(超长文档)
截断 context
或 RAG 一次检索
自主迭代检索
archival storage
显著提升
回答准确率

💪 优势

⚠️ 局限性

🔗 与其他论文的关联

连接到关系说明
TransformerusesMemGPT 使用 Transformer-based LLM 作为处理器
Memory Module (Agent Survey)improvesMemGPT 是 Memory Module 概念的具体 OS 级实现
Short-term MemoryrelatedMain Context = Short-term Memory 的实现
Long-term MemoryrelatedExternal Context = Long-term Memory 的实现
Memory RetrievalrelatedArchival Storage Search = Memory Retrieval 的具体化
LLM-based Agent ArchitectureinstanceMemGPT 是 Agent 架构的一个聚焦 Memory 的实例

🕸️ 知识图谱录入

类型新增示例
Method3MemGPT, Virtual Context Management, Self-directed Memory Management
Concept8Main/External Context, FIFO Queue, Recall/Archival Storage, Inner Thoughts, Memory-as-OS Analogy
Dataset2Multi-Session Chat, MemGPT Document QA
Author5Packer, Wooders, Stoica, Gonzalez...
跨论文连接6→ Transformer, → Memory Module, → Short/Long-term Memory, → LLM Agent Architecture

图谱增长: 59→78 节点, 69→93 关系 | 查看交互式图谱