题记与说明
- 日期:2026-10-27
- 类型:主题研究(多来源精读 + 架构对比 + 选型建议)
- 检索方式说明:本次通过 WebFetch 直接抓取一手来源完成。DuckDuckGo HTML 搜索接口连接超时(
Connect Timeout Error),故未走通用搜索引擎,改为基于领域知识直接选取一手来源(论文原文、官方文档、官方仓库、厂商博客),共 6 组来源,全部抓取成功。所有数据均为 2026-10-27 抓取时的页面内容。
来源清单
| # | 来源 | 链接 | 用途 |
|---|---|---|---|
| 1 | MemGPT 论文(Packer et al., arXiv:2310.08560, 2023-10 首发 / 2024-02 v2) | https://arxiv.org/abs/2310.08560 、全文 https://arxiv.org/html/2310.08560v2 | 架构与实验数据 |
| 2 | Letta 官方 GitHub README + 博客《Agent Memory》+ 文档 memory-blocks 页 | https://github.com/letta-ai/letta 、https://www.letta.com/blog/agent-memory 、https://docs.letta.com/v1-sdk/memory/memory-blocks/ | 产品化演进、memory blocks、sleep-time compute |
| 3 | Zep 论文(Rasmussen et al., arXiv:2501.13956, 2025-01) | https://arxiv.org/abs/2501.13956 、全文 https://arxiv.org/html/2501.13956v1 | Graphiti 架构、bi-temporal、基准数据 |
| 4 | Zep 官方博客《State-of-the-Art Agent Memory》 | https://www.getzep.com/blog/state-of-the-art-agent-memory/ | 厂商定位、对 MemGPT 的批评、与 GraphRAG 的区别 |
| 5 | Graphiti GitHub README | https://github.com/getzep/graphiti | 开源框架依赖、与 Zep 的关系、license |
| 6 | LangMem 文档 + 概念指南 + GitHub README | https://langchain-ai.github.io/langmem/ 、https://langchain-ai.github.io/langmem/concepts/conceptual_guide/ 、https://github.com/langchain-ai/langmem | 记忆类型学、hot path vs background、API、维护状态 |
TL;DR
三个系统代表了 agent 记忆的三条技术路线:
- MemGPT/Letta —— "LLM 即操作系统":把上下文窗口当 RAM、外部数据库当磁盘,让 agent 自己调用函数在两层之间搬运和改写记忆(self-editing memory)。产品化为 Letta 后,核心抽象是 memory blocks(带 label/description/value/limit 的可编辑文本块,可多 agent 共享),并引入 sleep-time compute(空闲时异步整理记忆)。
- Zep/Graphiti —— "时序知识图谱即记忆":记忆不是文本块而是一张 双时间轴(bi-temporal)知识图谱,事实有有效期(valid/invalid),新信息与旧事实矛盾时作废旧边而非删除。检索是 cosine + BM25 + 图遍历的混合搜索加五种重排。论文报告 DMR 94.8%(超 MemGPT 的 93.4%),LongMemEval 上比全上下文基线准确率最高 +18.5%、延迟 -90%、token 用量 <2%。
- LangMem —— "记忆是 SDK 原语":LangChain 出品的轻量库(MIT),不做服务不做数据库,提供语义/情景/程序性三类记忆的可组合原语:hot path 工具(agent 对话中即时写)+ background memory manager(异步提取合并)+ prompt optimizer(程序性记忆)。存储落在 LangGraph BaseStore(namespace 化的 JSON 文档)。
一句话选型:要"时间正确性"(事实会过期、会变化)→ Graphiti;要开箱即用的有状态 agent 运行时 + 人可直接编辑的记忆块 → Letta;已在 LangGraph 生态、想低成本起步 → LangMem。三者并不互斥,可组合(详见 §5)。
1. 问题背景:agent 为什么需要记忆系统
MemGPT 论文的出发点(摘要原文):
"LLMs are constrained by limited context windows, hindering their utility in tasks like extended conversations and document analysis."
Zep 论文则把矛头指向 RAG:
现有 RAG 框架 "limited to static document retrieval",而企业级/助手级场景要求从持续进行的对话和业务数据中动态整合知识。
两者合起来定义了这个问题域的三个子问题:
- 容量:上下文窗口装不下全部历史(对话越长越明显)。
- 持久化与个性化:跨 session 记住用户,"remember, reflect, and evolve dynamically through long-term interactions with their users"(MemGPT 摘要)。
- 时间性:事实会变(换工作、改偏好)。静态检索无法表达"X 在 3 月前为真、现在为假"。这是 Zep 强调的差异化维度。
2. 三个系统精读
2.1 MemGPT(论文)→ Letta(产品)
2.1.1 核心思想:操作系统隐喻
MemGPT 提出 virtual context management,"drawing inspiration from hierarchical memory systems in traditional operating systems"——OS 通过在快慢存储间搬运数据制造"大内存"的假象,MemGPT 对上下文窗口做同样的事,并用中断(interrupt)管理控制流。
2.1.2 内存层级(论文 §3)
Main context(= RAM,即 prompt tokens),"anything in main context is considered in-context and can be accessed by the LLM processor during inference",分三段:
| 段 | 性质 | 内容 |
|---|---|---|
| System instructions | 只读、静态 | 描述 "the MemGPT control flow, the intended usage of the different memory levels" 及函数用法 |
| Working context | 固定大小的读写文本块,"writeable only via MemGPT function calls" | 对话场景存 "key facts, preferences, and other important information about the user" |
| FIFO queue | 滚动消息历史 | 消息、系统消息、函数调用输入输出;队首是已被驱逐消息的递归摘要(recursive summary) |
External context(= 磁盘),"any information that is held outside of the LLMs fixed context window",必须"explicitly moved into main context"才能被处理:
- Recall storage:消息数据库(完整对话历史)。
- Archival storage:"a read/write database storing arbitrary length text objects",向量检索(pgvector + HNSW,cosine)。
2.1.3 自编辑记忆:函数集与自主性
"Memory edits are entirely self-directed: MemGPT autonomously updates and searches through its own memory based on the current context."
关键函数:
core_memory_append/core_memory_replace:改写 working context(persona / human 信息);archival_memory_insert/archival_memory_search:写入/查询归档向量库;conversation_search:查 recall storage,命中后 "the queue manager appends them to the back of the queue to reinsert them into the LLM's context window"。
2.1.4 内存压力与驱逐(OS 分页的对应物)
- warning token count(如上下文 70%):系统插入 "memory pressure" 警告消息,给 LLM 机会主动把重要信息存入 working context 或 archival;
- flush token count(如 100%):queue manager 驱逐约 50% 消息,"generates a new recursive summary using the existing recursive summary and evicted messages"。被驱逐消息 "stored indefinitely in recall storage",仍可检索——与 OS 换页到磁盘完全同构。
2.1.5 Heartbeat 与函数链
函数调用可带 request_heartbeat=true,输出回填 main context 后立即再次推理,实现多步操作(如翻页式多轮检索);不带该 flag 则 yield,等待下一个外部事件(用户消息、系统消息、定时事件)。这是 agent 能在一次用户输入内完成"检索→判断→再检索→回答"的机制基础。
2.1.6 实验结果(2023 论文)
DMR(Deep Memory Retrieval,多轮对话一致性):
| 模型 | 基线准确率 | +MemGPT |
|---|---|---|
| GPT-3.5 Turbo | 38.7% | 66.9% |
| GPT-4 | 32.1% | 92.5% |
| GPT-4 Turbo | 35.3% | 93.4% |
嵌套 KV 检索(最亮眼的结果):基线在 nesting level 1(GPT-3.5)或 3(GPT-4/4 Turbo)就掉到 0%,而 "MemGPT with GPT-4…is unaffected with the number of nesting levels",是 "the only approach that is able to consistently complete the nested KV task beyond 2 nesting levels"——因为它可以通过函数反复查 main context 里的 KV 对。
文档 QA:性能 "unaffected by increased context length"(对比截断类方法随压缩率上升而退化)。
Conversation opener:GPT-4+MemGPT 的开场白 SIM-1 得分 0.868,超过人工撰写的 0.800。
2.1.7 Letta:产品化演进(2024–2026)
MemGPT 作者创办 Letta,把论文系统做成 "Platform for stateful agents: AI with advanced memory that can learn and self-improve over time"(GitHub README,2026-10 抓取,25.3k stars,Apache-2.0)。
仓库现状(重要,2026-10 抓取):主仓库 letta-ai/letta 已变为指路页——"The current source code lives in letta-ai/letta-code"(含 agent harness、terminal UI、App Server、channels、runtime),V1 API server 归档在 archive 分支;安装方式变为 npm install -g @letta-ai/letta-code,支持 self-hosted App Server、chat.letta.com、Slack/Telegram/Discord 集成、TypeScript Agent SDK。这说明 Letta 在 2025–2026 从 Python 服务端框架转向了 "Letta Code" 形态(对标 Claude Code 一类产品),选型时需注意其架构仍在快速变化。
博客《Agent Memory》中的四层记忆分类:
- Message buffer:"the most recent messages in a conversation";
- Core memory:"in-context memory blocks that can be managed by the agent itself or by other agents";
- Recall memory:"the complete history of interactions that can be searched and retrieved when needed";
- Archival memory:"explicitly formulated knowledge stored in external databases"(向量或图数据库 + 专用检索工具)。
Memory blocks(文档定义):"structured sections of the agent's context window that persist across all interactions",四要素:label(唯一标识)、description("the main information used by the agent to determine how to read and write to that block")、value(内容)、limit(字符上限,示例常用 5000/4000)。默认 read-write,可设 read_only 防止 agent 破坏共享数据;多 agent 可挂同一个 block——"If multiple agents are attached to a block, they will all have the block data in their context windows",更新自动传播。注意两个坑:设置 block value 是整体替换而非 append;并发写是 last-write-wins。
Sleep-time compute:记忆管理作为 "non-blocking operations" 异步进行,空闲期做 "proactive memory refinement",产出 "higher quality memory blocks"。即:把"整理记忆"从对话关键路径上挪走——与 LangMem 的 background 形成、以及"睡眠巩固记忆"的神经科学隐喻殊途同归。
2.2 Zep / Graphiti:时序知识图谱记忆
2.2.1 定位与关系
- Graphiti(开源,Apache-2.0,32.3k stars,2026-10 抓取):"a framework for building and querying temporal context graphs for AI agents";"Zep is the unified context layer for enterprises","Graphiti is the graph construction framework inside Zep"。即:Graphiti 可自托管,Zep Cloud 加治理、托管与企业特性。
- 论文自述:"a novel memory layer service for AI agents",在 DMR 上超过 MemGPT。
2.2.2 Graphiti 三层子图
图 𝒢=(𝒩,ℰ,φ),三个层级:
- Episode subgraph:原始输入("messages, text, or JSON"),是 "non-lossy data store from which semantic entities and relations are extracted"。无损是关键卖点:episodic edges 让 "semantic artifacts can be traced to their sources for citation or quotation"(可溯源/可引用)。
- Semantic entity subgraph:实体节点("extracted from episodes and resolved with existing graph entities")+ 语义边(实体间关系/事实)。
- Community subgraph:社区节点代表 "clusters of strongly connected entities",含 "high-level summarizations of these clusters"。
设计明确对标认知心理学:"episodic memory, which represents distinct events, and semantic memory, which captures associations between concepts."
2.2.3 Bi-temporal 模型(全文最核心的架构决策)
两条时间线:
- T(event time,事件时间):事实在现实世界中何时为真——
t_valid/t_invalid; - T′(transaction time,事务时间):事实何时进入/离开系统——
t'_created/t'_expired。
论文称 "this bi-temporal approach represents a novel advancement in LLM-based knowledge graph construction."
Edge invalidation(边作废):新信息与旧事实矛盾时,"employs an LLM to compare new edges against semantically related existing edges to identify potential contradictions";发现时间上重叠的矛盾,就把旧边的 t_invalid 设为新边的 t_valid——作废旧边而非删除,且 "consistently prioritizes new information"。效果:"maintaining both current relationship states and historical records":既能回答"用户现在住哪",也能回答"用户去年住哪"。Graphiti README 的表述:"Facts have validity windows. When information changes, old facts are invalidated — not deleted."
2.2.4 图构建流水线
- Ingestion:消息作为 episode 进入,带参考时间戳
t_ref(解析"昨天/下周五"等相对时间),处理当前消息 + 最近 4 条做上下文; - Entity extraction:NER + 自动抽取说话人,用 "a reflection technique inspired by reflexion" 抑制幻觉,并生成实体摘要;
- Entity resolution(去重):实体名嵌入 1024 维向量,cosine + 全文双路召回候选,再由 LLM 判断是否同一实体;命中则 "it generates an updated name and summary";
- Fact extraction:抽取实体间事实(含 predicate);同一事实可挂多对实体,"an implementation of hyper-edges";
- Fact resolution:边去重的混合搜索 "constrained to edges existing between the same entity pairs",显著降复杂度;
- Temporal extraction:抽取绝对/相对时间,边上存全部四个时间字段;
- Community construction:用 label propagation(而非 GraphRAG 式 Leiden),因为 "straightforward dynamic extension"——新节点归入邻居中占多数的社区,定期全量刷新。
增量 vs 批处理是与 GraphRAG 的本质区别(README:"New data integrates immediately without batch recomputation";博客:Zep "maintains a rich temporal understanding of how information evolves over time")。
2.2.5 混合检索
f(α) = χ(ρ(φ(α))):三种搜索 × 五种重排 × 构造器。
- 搜索 φ:① cosine 语义相似(Neo4j Lucene 向量索引);② Okapi BM25 全文(词级);③ breadth-first graph search("contextual similarities—where nodes and edges closer in the graph appear in more similar conversational contexts",可用最近 episode 作种子节点);
- 重排 ρ:RRF(多路融合)、MMR(多样性)、episode-mentions(按实体/事实在对话中被提及频率)、node distance(按到质心节点的图距离)、cross-encoder(LLM 交叉注意力打分,最贵);
- 构造 χ:边 → 事实 + valid/invalid 日期;实体节点 → 名字 + 摘要;社区节点 → 摘要。
2.2.6 基准结果(论文,注意是厂商自评)
DMR(500 段多 session 对话,每段 5 session):
| 方法 | 模型 | 准确率 |
|---|---|---|
| Recursive summarization | gpt-4-turbo | 35.3% |
| Conversation summaries | gpt-4-turbo | 78.6% |
| MemGPT(论文报告值) | gpt-4-turbo | 93.4% |
| Full-conversation(全塞上下文) | gpt-4-turbo | 94.4% |
| Zep | gpt-4-turbo | 94.8% |
| Full-conversation | gpt-4o-mini | 98.0% |
| Zep | gpt-4o-mini | 98.2% |
作者自己承认 DMR 已过时:对话 "only 60 messages, easily fitting within current LLM context windows",问题都是 "single-turn, fact-retrieval questions"。博客进一步点破:给足全上下文,裸模型就能超过 MemGPT 当年报告分——这既是对 MemGPT 的批评,也是对 DMR 榜单的祛魅。
LongMemEval_s(平均 ~115k tokens 的长历史,更真实的时序推理基准):Zep 检索 top-20 边+实体,注入 ~1.6k tokens:
| 记忆 | 模型 | 准确率 | 延迟 | 平均上下文 |
|---|---|---|---|---|
| Full-context | gpt-4o-mini | 55.4% | 31.3s | 115k |
| Zep | gpt-4o-mini | 63.8% | 3.20s | 1.6k |
| Full-context | gpt-4o | 60.2% | 28.9s | 115k |
| Zep | gpt-4o | 71.2% | 2.58s | 1.6k |
即 +15.2%/+18.5% 准确率、约 -90% 延迟、<2% token(博客:"less than 2% of the baseline tokens")。分题型(gpt-4o):single-session-preference +184%、temporal-reasoning +38.4%、multi-session +30.7%;但 single-session-assistant -17.7%,作者承认 "suggest further research and engineering work is needed"。
与 MemGPT 的直接对比缺失:作者尝试在 LongMemEval 上跑 MemGPT 但 "were unable to achieve successful question responses",因为 MemGPT "does not support direct ingestion of existing message histories"。所以跨系统的公平横评实际上并不存在。
2.2.7 部署依赖(自托管 Graphiti 的真实成本)
README:Python 3.10+;图库 Neo4j 5.26 / FalkorDB 1.1.2 / Amazon Neptune / Kuzu(已弃用);默认 OpenAI API key(LLM + embedding),也支持 Anthropic/Gemini/Groq;"Works best with LLMs supporting Structured Output"。注意:每条 episode 的入库都要多次 LLM 调用(实体抽取、实体消解、事实抽取、时间抽取、矛盾判定),写入成本与延迟显著高于"存个向量"的方案——这是选型时最容易低估的一项。
2.3 LangMem:记忆作为 SDK 原语
2.3.1 定位
LangChain AI 出品的开源库(MIT,GitHub 显示活跃维护:154 commits / 56 open issues,无 deprecation banner,2026-10-27 抓取),"helps agents learn and adapt from their interactions over time"。它不是服务、不带数据库,而是 "both functional primitives you can use with any storage system and native integration with LangGraph's storage layer"——存储落在 LangGraph BaseStore(多级 namespace 如 ("acme_corp", "{user_id}", "code_assistant") 下的 JSON 文档),开发用 InMemoryStore("in process memory—they'll be lost on restart"),生产推荐 AsyncPostgresStore。"Available by default in all LangGraph Platform deployments."
2.3.2 记忆类型学(概念指南,借鉴认知科学三分法)
| 类型 | 定义(原文) | 形态 |
|---|---|---|
| Semantic(语义) | "essential facts and other information that ground an agent's responses" | collections(无界记录集,运行时检索)或 profiles("a single document that represents the current state",schema 约束,原位更新) |
| Episodic(情景) | "the full context of an interaction—the situation, the thought process that led to success, and why that approach worked" | 作为 few-shot 示例指导未来行为(成功交互经验) |
| Procedural(程序性) | "how an agent should behave and respond" | 系统提示词本身,随反馈持续演化 |
Profile vs collection 的取舍:只要最新状态 → profile(单一文档原位改);需要保留多条并做冲突调和 → collection("reconciliation of new information with existing beliefs")。
2.3.3 记忆形成的两条路径
- Hot path(有意识):对话进行中由 agent 调工具即时写——"immediate updates when critical context emerge",代价是延迟和工具选择复杂度;
- Background(潜意识):交互后/间隙异步进行——"deeper pattern analysis without impacting response time",更适合做回忆巩固。
Memory manager 的职责:"reconcile new information with previous beliefs, either deleting/invalidating or updating/consolidating existing memories",通过 "memory enrichment process" 平衡新增与合并,指令可由开发者定制。
2.3.4 关键 API
create_manage_memory_tool/create_search_memory_tool:hot path 下 agent 的存/取记忆工具(配create_react_agent使用);- background memory manager(
create_memory_store_manager一类):"automatically extracts, consolidates, and updates agent knowledge"; create_prompt_optimizer:程序性记忆的实现——吃进带反馈分数的对话轨迹,产出优化后的系统提示(文档示例:低分交互后,prompt 被增补了 "practical-first explanations and adaptive response styles" 一类规则)。这是三个系统里唯一把"改 prompt"明确当作记忆通道的。
2.3.5 没有的东西(同样重要)
- 无公开基准:文档与 README 均未给出任何 benchmark 数字(对比 Zep 论文的 DMR/LongMemEval、MemGPT 论文的 DMR/KV);
- 无内置时间模型:没有 valid/invalid 时间轴,事实演化靠"更新/合并覆盖",时序推理要开发者用 metadata 自己搭;
- 无检索重排体系:语义搜索 + 元数据过滤 + 直接读取,没有 Zep 那种多路混合搜索和重排器。
3. 架构对比总表
| 维度 | MemGPT / Letta | Zep / Graphiti | LangMem |
|---|---|---|---|
| 记忆表示 | 分层文本:working context / memory blocks(in-context)+ recall(消息库)+ archival(向量库) | 三层子图时序知识图谱(episode 无损层 / 实体-事实层 / 社区层),边带 4 个时间字段 | namespace 化 JSON 文档(facts / episodes / profile)+ 系统提示词 |
| 写入机制 | agent 自主调函数自编辑("entirely self-directed"),memory pressure 警告触发主动保存 | 系统流水线自动:抽取→消解→时间标注→矛盾检测→边作废,人/agent 不参与 | 双模可配:hot path 工具(agent 写)或 background manager(自动提取合并) |
| 检索机制 | agent 自主搜索(archival/conversation search)+ 常驻 in-context 直读;heartbeat 支持多步检索 | 混合搜索(cosine + BM25 + 图 BFS)× 5 种重排(RRF/MMR/提及频率/节点距离/cross-encoder) | BaseStore 语义搜索 + 元数据过滤 + 直接读取 |
| 时间性 | 无显式时间模型;靠递归摘要和文本 | 一等公民:bi-temporal(事件时间 × 事务时间),事实有有效期,作废不删除 | 无内置;靠更新覆盖,需自行加 metadata |
| 可溯源性 | block 人可读;recall 可全文搜 | 最强:任何实体/事实可回溯到源 episode,"traced to their sources for citation" | 文档可读,来源需自己存 |
| 多 agent 共享 | 原生:同一 block 挂多个 agent,更新自动传播 | 图天然共享(按 group_id 隔离) | namespace 天然共享 |
| 离线整理 | sleep-time agents(空闲期主动精炼记忆块) | 增量入图即整理;社区定期重算 | background reflection(异步提取合并) |
| 基础设施 | Letta server(App Server)+ Postgres/pgvector | Neo4j 5.26 / FalkorDB / Neptune + LLM & embedding API | 纯库 + InMemory/Postgres store |
| 写入成本 | 低(函数调用 + 摘要) | 高(每 episode 多次 LLM 调用) | 中(提取/合并各一次 LLM 调用,可挪到后台) |
| 读取成本 | 取决于 agent 检索轮数(多步函数调用往返) | 低且稳:top-k 注入 ~1.6k tokens,延迟 ~2.6-3.2s(LongMemEval 实测) | 低(向量搜索 + 直读) |
| 形态 | 开源平台 + 云(2026 已转向 letta-code) | 开源框架 Graphiti + Zep Cloud 企业服务 | 开源 SDK(MIT) |
| 基准证据 | DMR 93.4%(GPT-4 Turbo,2023);嵌套 KV 检索唯一 >2 层 | DMR 94.8%/98.2%;LongMemEval +18.5% / -90% 延迟(厂商自评) | 无公开基准 |
| License | Apache-2.0 | Apache-2.0(Graphiti) | MIT |
| 社区规模(2026-10) | 25.3k stars | 32.3k stars(Graphiti) | 较小(154 commits) |
三条路线的本质分歧:谁负责管理记忆
- Letta:agent 自己管(LLM as OS kernel)。优点是灵活、agent 有"元认知";缺点是记忆质量强依赖底模的 function calling 能力,小模型会写坏/漏写记忆,且检索轮数不可控(读取延迟方差大)。
- Zep:系统管线管(deterministic pipeline + LLM 做抽取判断)。优点是写入质量稳定、读取快而便宜、时间语义正确;缺点是写放大(每条消息多次 LLM 调用)、多一个图库要运维、检索是"被动注入"而非 agent 自主探索。
- LangMem:开发者编排(给你原语,路径自己选)。优点是轻、可组合、不锁基础设施;缺点是一切都要自己搭,无时间模型,无效果背书。
4. 证据质量评估(精读者注)
- Zep 的数据是厂商自评(论文作者全部来自 Zep 公司),且 DMR 上 MemGPT 用的是对方论文报告值而非复现值;LongMemEval 上 MemGPT 根本没跑起来("unable to achieve successful question responses"),横评缺失。数字方向可信(+18.5%、-90% 延迟的量级与"1.6k vs 115k tokens"的机制自洽),但"超过 MemGPT"的表述要打折扣。
- MemGPT 论文是 2023 年的,DMR 93.4% 在当时惊艳,但 Zep 论文显示:2024 年后给足全上下文的裸模型就有 94.4%(gpt-4-turbo)/98.0%(gpt-4o-mini)。DMR 作为基准已失效,这恰说明记忆系统的价值主张必须转向:长上下文吃不下/吃不划算的场景(115k+ tokens、成本、延迟)与时间推理。
- Zep 自己的回归项:single-session-assistant 题型 -17.7%——图谱记忆在"用户问助手刚说过的话"这类近距离场景反而不如全上下文,提示图检索不是万能的,近距离对话仍需消息缓冲兜底。
- LangMem 零基准:效果完全取决于开发者写的提取/合并 prompt 和 schema,无法先验判断上限。
- Letta 主仓库已迁移到 letta-code、V1 server 归档——产品形态剧烈变动中,评估 Letta 时文档/教程的时效性风险高。
5. 个人助手项目选型建议
5.1 先把需求拆开
个人助手(personal assistant)场景的记忆需求画像:
| 需求 | 例子 | 对应记忆类型 |
|---|---|---|
| 长期用户画像 | 姓名、职业、饮食禁忌、沟通偏好 | semantic / profile |
| 事实的时间演化 | "用户 3 月换了工作"→ 现在问职业要答新的,问"去年在哪上班"要答旧的 | bi-temporal(Zep 独有) |
| 事件史 | "上周我们讨论过的那个方案" | episodic / recall |
| 行为适应 | 助手逐渐学会"回答要先给结论" | procedural(LangMem 独有)/ Letta persona block |
| 成本与延迟敏感 | 个人项目,高频短对话,token 要省 | 读取端注入量小者优(Zep 1.6k tokens) |
| 数据主权 | 全是个隐私数据 | 自托管优先 |
| 单人维护 | 运维精力有限 | 依赖越少越好 |
5.2 四条路径
路径 A:LangMem(已在/愿意进 LangGraph 生态,想快速起步)
- 起步成本最低:
create_manage_memory_tool+create_search_memory_tool+AsyncPostgresStore,一天能跑通;background manager 把提取合并挪出关键路径;profile 模式天然适合"用户画像单文档"。 - 用
create_prompt_optimizer做程序性记忆是独家能力。 - 短板:时间演化要自己用 metadata(如
valid_from/superseded_by)搭简化版;无检索重排;效果无背书。 - 适合:先验证产品价值,记忆需求还停留在"记住偏好和事实"的阶段。
路径 B:Graphiti 自托管(把记忆当核心资产认真做)——对"时间正确性"要求高时的首选
- 三个系统中唯一在架构层面解决"事实会过期"的:bi-temporal + edge invalidation,个人助手最高频的坏 case(助手拿着旧信息答新问题)被系统性消灭。
- episode 层无损 + 可溯源,个人数据可审计、可导出。
- 读取端便宜且稳(top-k 边注入 ~1.6k tokens),符合个人助手"高频短对话"的负载形态。
- 成本:Neo4j/FalkorDB 运维 + 每条消息多次 LLM 调用的写放大(可用 gpt-4o-mini 级小模型做抽取来压成本);写入延迟高 → 必须异步化(对话结束后入图)。
- 适合:愿意为记忆质量投入、助手要陪用户跑以月/年计的时间尺度。
路径 C:Letta(不想自己搭 agent loop,要 runtime + 记忆一体)
- stateful agent 平台直接给你:持久 agent、memory blocks(人可在 ADE 里直接编辑——对个人助手是很好的"手动修正记忆"体验)、多 agent 共享 block(如一个"记忆管家 agent"专门维护用户画像块)、sleep-time agents(空闲整理记忆)。
- 风险:框架绑定重;2026 年产品形态剧烈迁移中(letta → letta-code,V1 server 归档),文档时效差;记忆质量依赖底模 function calling。
- 适合:想要"数字分身"式全托管体验、能接受跟着它的架构走。
路径 D:Zep Cloud(Graphiti 的托管版)
- 免运维 + 企业特性,但个人项目按量/按席位付费通常不划算,且数据出本地。除非不想碰图库且接受订阅费,否则个人助手选 Graphiti 自托管即可。
5.3 我的推荐
默认推荐:路径 B(Graphiti 自托管)作为记忆层 + 自备轻量 agent loop;若已在 LangGraph 生态则先 A 后 B。 理由:
- 个人助手的记忆难点排序是:时间正确性 > 长期容量 > 检索精度。容量问题在 2026 年已被长上下文大幅缓解(Zep 论文自己承认 60 条消息的 DMR 场景全上下文就能打),而"用户三个月前说的偏好现在改了"这类问题,全上下文和向量检索都给不出正确答案,只有 bi-temporal 图能。
- Graphiti 是 Apache-2.0 纯框架,不绑定 agent 框架——你可以用 LangGraph、裸 SDK 或任何 loop 调它,迁移成本远低于 Letta。
- 写放大问题可以工程化解决(异步入图 + 小模型抽取),而"没有时序模型"这个问题在 LangMem/Letta 上无法工程化补全——要补就等于自己重写一个简化版 Graphiti。
- 混合架构是可行且值得的:近期对话用消息缓冲(覆盖 Zep 回归的 single-session-assistant 场景),中长期记忆走 Graphiti 图检索;若同时用 LangGraph,可保留 LangMem 的 prompt optimizer 做程序性记忆——三者职责不冲突。
- 无论选哪条,借鉴 sleep-time compute:把记忆整理(合并、作废、摘要)放到空闲时段异步跑,别占对话关键路径。
5.4 决策树(速查)
需要"事实随时间演化且可回溯"?
├─ 是 → 自托管意愿 + 运维能力?
│ ├─ 有 → Graphiti + Neo4j/FalkorDB(路径 B)
│ └─ 无 → Zep Cloud(路径 D,付费换运维)
└─ 否 → 已在 LangGraph 生态?
├─ 是 → LangMem 起步(路径 A),需求升级再迁 Graphiti
└─ 否 → 想连 agent runtime 一起外包?
├─ 是 → Letta(路径 C,注意 letta-code 迁移期风险)
└─ 否 → LangMem / 自建 blocks + 向量库(借鉴 Letta 的 block 设计)6. 七维度提取(主题层面)
6.1 核心问题
如何让 LLM agent 在有限上下文窗口下拥有持久、可演化、可高效检索的记忆,支撑跨 session 的长期交互(扩展对话、个性化助手、动态知识整合)。
6.2 主要主张
- MemGPT/Letta:把 OS 虚拟内存思想移植到 LLM——分层存储 + agent 自主换页(函数调用自编辑记忆),即可"制造"无限上下文的假象;产品化后主张 memory blocks + sleep-time compute 是 stateful agent 的基础设施。
- Zep/Graphiti:静态 RAG 不够,agent 记忆必须是时序知识图谱:事实带有效期、矛盾时作废不删除、增量入图;混合检索让"少而准"的上下文注入胜过全量塞入(+18.5% 准确率、-90% 延迟、<2% tokens)。
- LangMem:记忆应拆成语义/情景/程序性三类原语,形成时机分 hot path 与 background,开发者按需在任意存储上组合,而非绑定某个记忆服务。
- 横向判断(本笔记综合):记忆系统的竞争焦点已从"能不能记住"(长上下文已解决大半)转向"时间正确性、写入成本、读取延迟、可溯源"四件事;时间性是当前的分水岭。
6.3 方法
- MemGPT:系统工程 + 受控实验(DMR、嵌套 KV、文档 QA、MSC opener),GPT-3.5/4/4-Turbo 多底模对照。
- Zep:架构论文 + 双基准评测(DMR 复现对比 + LongMemEval_s 全上下文基线对照),gpt-4o/4o-mini 双模型。
- LangMem:无实验方法,纯工程库 + 概念框架(借鉴认知心理学的记忆三分法)。
- 本笔记方法:一手论文全文精读(arXiv HTML)+ 官方文档/仓库/博客交叉验证,标注厂商利益冲突与数据缺失。
6.4 数据与证据
- MemGPT:DMR GPT-4 Turbo 35.3%→93.4%;嵌套 KV 唯一能过 2 层;opener SIM-1 0.868 vs 人类 0.800。
- Zep:DMR 94.8%(4-turbo)/98.2%(4o-mini);LongMemEval_s 55.4%→63.8%(4o-mini)、60.2%→71.2%(4o),延迟 31.3s→3.20s / 28.9s→2.58s,上下文 115k→1.6k tokens;分题型 preference +184%、temporal +38.4%、multi-session +30.7%、single-session-assistant -17.7%。
- LangMem:无定量证据(局限)。
- 证据充分性评估:Zep 数据最完整但厂商自评、MemGPT 横评缺失;MemGPT 数据可信但基准已过时;LangMem 无背书。没有任何第三方在 2026 年对三者做过同条件横评(本次检索未发现,DDG 超时导致搜索面有限)。
6.5 结论
三条路线各自成立且不完全互斥:Letta = 记忆内建于 agent 运行时(agent 自管),Zep/Graphiti = 记忆外置为时序图谱服务(管线自管),LangMem = 记忆拆为可组合原语(开发者编排)。对时间敏感、长期陪伴型的个人助手,Graphiti 类时序图谱是当前架构上最完备的答案;对快速起步和生态内用户,LangMem 够用;Letta 适合接受全家桶的场景。近期对话仍需消息缓冲兜底,纯图检索在近距离问答上有实测回归。
6.6 局限
- 厂商自评偏差(Zep 论文);MemGPT 无法导入既有历史导致 LongMemEval 横评缺失。
- DMR 基准失效(全上下文即可刷高分),Zep 的 DMR 优势说服力有限。
- Zep 在 single-session-assistant 题型 -17.7%,作者自认需更多研究。
- Graphiti 写入成本高(每 episode 多次 LLM 调用)+ 需图库运维,论文未量化写入开销。
- LangMem 无基准、无时间模型。
- Letta 处于 letta→letta-code 架构迁移期,公开文档碎片化、时效性差。
- 本笔记局限:未能实际运行任何系统做实测对比;DDG 搜索超时导致可能遗漏第三方横评/新玩家(如 MemOS、Mem0、OpenAI/Anthropic 原生 memory 等未在本主题范围内展开)。
6.7 对我的启发
- OS 隐喻是可迁移的设计模式:memory pressure 警告(让模型在驱逐前主动保存)和 heartbeat 函数链,是任何自研 agent loop 都可以低成本复刻的机制。
- "作废不删除"应成为个人助手记忆的默认语义:bi-temporal 的四字段(valid/invalid × created/expired)值得在任何自研记忆 schema 里预留,哪怕先用 SQLite/Postgres 简化实现。
- 写入路径与读取路径的成本要分开算:Zep 证明"写贵读贱"在助手场景是划算的(高频短对话读、异步慢慢写);sleep-time/background 整理是三家共识,异步化记忆巩固应作为默认架构决策。
- profile 与 collection 是两种画像范式:单一 profile 文档(LangMem/Letta block)适合"当前状态",collection/图适合"历史与证据";成熟系统多半两者都要(块给人看/给 agent 常驻,图给检索)。
- 警惕基准营销:DMR 的兴衰(2023 年 93.4% 惊艳 → 2024 年裸模型 94.4%)提醒我,评估记忆系统要看它在"长上下文吃不下"的场景(LongMemEval 类)与时间推理上的表现,而不是排行榜数字。
- 程序性记忆是被低估的通道:LangMem 的 prompt optimizer 把"agent 行为改进"也纳入记忆体系——个人助手长期陪伴中,"学会怎么跟你说话"可能比"记住你说过什么"更提升体验。
7. 关键原文引述辑录
MemGPT 论文(arXiv:2310.08560)
"virtual context management, a technique drawing inspiration from hierarchical memory systems in traditional operating systems"
"Memory edits are entirely self-directed: MemGPT autonomously updates and searches through its own memory based on the current context."
Working context: "A fixed-size read/write block of unstructured text, writeable only via MemGPT function calls."
"MemGPT with GPT-4…is unaffected with the number of nesting levels and is able to perform the nested lookup by accessing the key-value pairs stored in main context repeatedly via function queries."
Letta(GitHub / 博客 / 文档)
"Platform for stateful agents: AI with advanced memory that can learn and self-improve over time."
Core memory: "in-context memory blocks that can be managed by the agent itself or by other agents."
Memory blocks: "structured sections of the agent's context window that persist across all interactions."
"If multiple agents are attached to a block, they will all have the block data in their context windows."
Sleep-time compute: "proactive memory refinement" producing "higher quality memory blocks."
"The current source code lives in letta-ai/letta-code"(主仓库 README,2026-10)
Zep 论文(arXiv:2501.13956)
"a novel memory layer service for AI agents";Graphiti: "a temporally-aware knowledge graph engine"
Episode subgraph 是 "non-lossy data store from which semantic entities and relations are extracted";"semantic artifacts can be traced to their sources for citation or quotation."
"bi-temporal approach represents a novel advancement in LLM-based knowledge graph construction."
Edge invalidation: "employs an LLM to compare new edges against semantically related existing edges to identify potential contradictions";"consistently prioritizes new information."
DMR 局限:conversations "only 60 messages, easily fitting within current LLM context windows."
回归项:single-session-assistant 下降 "suggest further research and engineering work is needed."
MemGPT 对比缺失:"were unable to achieve successful question responses",因 MemGPT "does not support direct ingestion of existing message histories."
Zep 博客 / Graphiti README
Graphiti: "an open source library that builds dynamic, temporally-aware knowledge graphs";"Zep is the unified context layer for enterprises","Graphiti is the graph construction framework inside Zep."
"Facts have validity windows. When information changes, old facts are invalidated — not deleted."
"Combines semantic embeddings, keyword (BM25), and graph traversal for low-latency, high-precision queries."
"New data integrates immediately without batch recomputation."(vs GraphRAG 批处理)
LongMemEval: "aggregate accuracy improvements of up to 18.5%","less than 2% of the baseline tokens."
LangMem(文档 / 概念指南 / GitHub)
"helps agents learn and adapt from their interactions over time."
Semantic memory: "essential facts and other information that ground an agent's responses."
Episodic memory: "the full context of an interaction—the situation, the thought process that led to success, and why that approach worked."
Procedural memory: "how an agent should behave and respond."
Profile: "a single document that represents the current state."
Hot path: "immediate updates when critical context emerges";Background: "deeper pattern analysis without impacting response time."
Memory manager 职责:"reconcile new information with previous beliefs, either deleting/invalidating or updating/consolidating existing memories."
"both functional primitives you can use with any storage system and native integration with LangGraph's storage layer."
8. 参考链接汇总
- MemGPT 论文:https://arxiv.org/abs/2310.08560 (全文:https://arxiv.org/html/2310.08560v2)
- Letta GitHub:https://github.com/letta-ai/letta (主代码已迁至 letta-ai/letta-code)
- Letta 博客《Agent Memory》:https://www.letta.com/blog/agent-memory
- Letta 文档 memory blocks:https://docs.letta.com/v1-sdk/memory/memory-blocks/
- Zep 论文:https://arxiv.org/abs/2501.13956 (全文:https://arxiv.org/html/2501.13956v1)
- Zep 博客《State-of-the-Art Agent Memory》:https://www.getzep.com/blog/state-of-the-art-agent-memory/
- Graphiti GitHub:https://github.com/getzep/graphiti
- LangMem 文档:https://langchain-ai.github.io/langmem/ (概念指南:https://langchain-ai.github.io/langmem/concepts/conceptual_guide/)
- LangMem GitHub:https://github.com/langchain-ai/langmem