跳到主内容
@wquguru
精选88Hacker News Best(web_list)技巧与观点

Agent记忆系统的苦涩教训:基于事件日志搜索优于专用存储

The bitter lesson for agent memory

原文
发到 X
推荐理由

Agent开发者必读,这篇深度复盘揭示了用通用搜索替代专用记忆存储的工程实践,给出了可落地的架构取舍建议。

Time is a river which sweeps me along, but I am the river.

时间是一条将我裹挟前行的河流,但我就是这条河流。

Jorge Luis Borges, A New Refutation of Time

豪尔赫·路易斯·博尔赫斯,《时间的再次反驳》

In Christopher Nolan's Memento, Leonard Shelby is set upon a seemingly impossible task. To find the man who killed his wife, despite the anterograde amnesia caused by a blow to his head. To maintain context with a memory that resets every so often, he uses polaroids, notes and tattoos.

在克里斯托弗·诺兰的电影《记忆碎片》中,伦纳德·谢尔比被置于一个看似不可能的任务之中:寻找杀害他妻子的凶手,尽管他因头部受击而患有顺行性遗忘症。为了在记忆不断重置的情况下维持上下文连贯性,他使用宝丽来照片、笔记和纹身。

This reminds me of how we do agent memory. Models have anterograde amnesia. They can't form long term memories, and their state of the world is frozen to a training cutoff. To maintain context across sessions, we engineer memory systems that encode and retrieve information from the past.

这让我想起了我们是如何处理智能体记忆的。模型具有顺行性遗忘症。它们无法形成长期记忆,其对世界的状态被冻结在训练截止日期之前。为了跨会话维持上下文,我们设计了能够编码和检索过去信息的记忆系统。

But how much engineering does a memory system need? Richard Sutton famously stated in The Bitter Lesson that general methods such as search and learning outperform systems built with human domain knowledge.

但是,一个记忆系统究竟需要多少工程化工作?理查德·萨顿在《苦涩的教训》一文中著名地指出,搜索和学习等通用方法的表现优于基于人类领域知识构建的系统。

We found this to be the case with agent memory.

我们发现代理记忆的情况也是如此。

Allowing an agent to run SQL queries and search over its own event log beats or matches specialised memory systems in all major memory benchmarks and scales with model intelligence.

允许智能体运行 SQL 查询并搜索其自身的事件日志,在所有主要记忆基准测试中均胜过或匹敌专用的记忆系统,并且随着模型智能的提升而扩展。

We argue that memory systems lose valuable task-relevant information during compression. In contrast, agentic search over an event log defers compression until query time. We propose a design for memory systems that aims to maximise the epistemic value of searching past events, using a hierarchy of derived views over an immutable event log.

我们认为,记忆系统在压缩过程中丢失了有价值的任务相关信息。相比之下,对事件日志进行代理式搜索将压缩推迟到查询时进行。我们提出了一种旨在最大化搜索过去事件的认识论价值的记忆系统设计,该设计使用基于不可变事件日志的分层派生视图。

A survey of memory systems

记忆系统综述

Anthropic recently described memory as knowledge an agent gains from experience and retains between sessions. Information theory offers us a sharper lens: memory is information from the past that reduces uncertainty in the future. A memory system is what encodes, consolidates, and retrieves that information.

Anthropic 最近将记忆描述为智能体从经验中获得并在会话之间保留的知识。信息论为我们提供了一个更清晰的视角:记忆是来自过去的、能够减少未来不确定性的信息。记忆系统是编码、巩固和检索这些信息的东西。

pastnowfutureground truthwithout memoryhigh uncertaintywith memorylow uncertainty

过去现在未来事实真相无记忆高不确定性有记忆低不确定性

With memory, plausible futures narrow around ground truth; without it, they spread into a wide cone.

有了记忆,合理的可能性会围绕事实真相收窄;没有记忆,它们则会扩散成一个宽大的锥形区域。

Decades of research from cognitive neuroscience give us a systematic framework to understand memory systems: encoding, consolidating, and retrieving experience.

认知神经科学数十年的研究为我们提供了一个理解记忆系统的系统框架:编码、巩固和检索经验。

agent actsEncodingexperience → storeConsolidationstore → better storeRetrievalstore → context

智能体行动编码经验 → 存储巩固存储 → 更好的存储检索存储 → 上下文

Memory systems encode, consolidate, and retrieve experience in a continuous cycle.

记忆系统在连续的循环中编码、巩固和检索经验。

Within each process, we can further classify systems in terms of whether it's done in an open-loop or closed-loop. In control theory, closed-loop systems act, measure their outputs and adjust their inputs to reduce errors. Open-loop systems are more rigid: they act on commands and models without adjusting to feedback.

在每个进程中,我们可以根据系统是开环还是闭环来进一步对系统进行分类。在控制理论中,闭环系统执行动作、测量其输出并调整其输入以减少误差。开环系统更为僵化:它们仅依据指令和模型执行操作,而不会根据反馈进行调整。

open-loopgoalresultactionControllerharness · agentProcessmemory systemclosed-loopgoalresulterroractionmeasurefeedbackΣ+−Controllerharness · agentProcessmemory system

开环目标结果动作控制器工具包 · 智能体进程记忆系统闭环目标结果误差动作测量反馈Σ+−控制器工具包 · 智能体进程记忆系统

Open-loop systems act without observing outputs; closed-loop systems feed error back to adjust.

开环系统在未观察输出的情况下执行动作;闭环系统将误差反馈回来以进行调整。

Encoding experience

经验编码

The goal of encoding is to extract information from experience into a representation that reduces uncertainty during an unknown future task. The following diagram shows this in the context of a typical agent loop.

编码的目标是从经验中提取信息,形成一种表示形式,以降低未来未知任务中的不确定性。下图展示了这一过程在典型智能体循环背景下的体现。

recent turnsappends turnextractwrite toolHistorysql · jsonContextmodel windowAgentanswers turnUser messageturn inputMemoryfacts · graph · notes

最近的轮次追加轮次提取写入工具历史sql · json上下文模型窗口智能体回答轮次用户消息轮次输入记忆事实 · 图 · 笔记

Encoding writes experience to memory via background extraction or an in-loop write tool.

编码通过后台提取或循环内的写入工具将经验写入记忆。

The major forms of memory stores are vector embeddings, graphs and ontologies, or summaries and notes. Open-loop systems use conditions and handcrafted domain models to decide when to write to the memory store. Mem0, Supermemory, and Mastra are examples.

主要的记忆存储形式包括向量嵌入、图和本体,或者摘要和笔记。开环系统使用条件和手工设计的领域模型来决定何时向记忆存储写入数据。Mem0、Supermemory 和 Mastra 是其中的例子。

Supermemory batches multiple turns asynchronously by default, allowing for an optional per turn extraction. Extracted facts are encoded into temporal graphs. In Mem0, the harness sends every new turn to an extraction model that distills them into atomic facts, which are embedded into a vector store.

Supermemory 默认异步批量处理多个轮次,允许进行可选的逐轮提取。提取的事实被编码到时序图中。在 Mem0 中,工具包将每个新轮次发送给一个提取模型,将其提炼为原子事实,然后嵌入到向量存储中。

embed querytop-k lookupmemory.add()extractwrite factsINGEST-TIME (LOSSY EXTRACTION)User messageturn inputContexttop-k facts injectedAgentanswers from contextVector storeextracted facts onlyTurn historyraw wording droppedLLM fact extractorsingle-call additive extract

嵌入查询top-k查找memory.add()提取写入事实摄取时(有损提取)用户消息轮次输入上下文注入的top-k事实智能体来自上下文的回答向量存储仅提取的事实轮次历史原始措辞被丢弃LLM事实提取器单次调用增量提取

Mem0 extracts standalone facts at ingest time and injects top-k vector matches at query time.

Mem0 在摄取时提取独立事实,并在查询时注入 top-k 向量匹配结果。

Compaction could be viewed as a form of memory encoding too. It triggers at context window boundaries and extracts goal-relevant information from one context window into the next.

压缩也可以被视为一种记忆编码形式。它在上下文窗口边界处触发,并将与目标相关的信息从一个上下文窗口提取到下一个上下文窗口中。

older turnsrecent tailcompactsummaryrecent tail

较旧的轮次最近的尾部压缩摘要最近的尾部

Compaction summarises older turns, keeps the recent tail, and frees window space.

压缩会对较旧的轮次进行总结,保留最近的尾部,并释放窗口空间。

In contrast, closed-loop systems use the agent to update information in the memory store through tool calls. It comes with variable costs and latency since it adds inference compute within a turn.

相比之下,闭环系统利用智能体通过工具调用来更新记忆存储中的信息。由于它在一个轮次内增加了推理计算,因此会带来可变成本和延迟。

In practice, systems like Claude, Codex and Letta use a hybrid approach. During latency-sensitive tasks, agents use general shell and file tools to make small closed-loop updates to their memory stores. In idle time between interactions, deeper consolidation and cleanup cycles run as open-loop background processes.

在实践中,Claude、Codex 和 Letta 等系统采用混合方法。在延迟敏感的任务中,智能体使用通用的 shell 和文件工具对记忆存储进行小型闭环更新。在交互之间的空闲时间,更深层的整合与清理周期作为开环后台进程运行。

Consolidating experience

经验整合

The goal of consolidation is to improve an existing encoded memory representation to optimise retrieval during an unknown future task. Notice the contrast with encoding which was focused on extracting information.

整合的目标是改进现有的编码记忆表示,以优化未来未知任务中的检索。注意这与侧重于提取信息的编码过程形成对比。

between sessions · idlesession boundaryreads logsreads existing storemerges & refinesMemoryfacts · graph · notesConsolidatorsleep-time · idleHistorypast sessions

会话间 · 空闲会话边界读取日志读取现有存储合并并精炼记忆事实 · 图谱 · 笔记整合器休眠时间 · 空闲历史过去会话

Idle-time consolidation reads existing memory and past logs to write back a refined store.

空闲时间的整合会读取现有的记忆和过去的日志,以写回一个精炼后的存储。

As a nod to its parallels in the brain, researchers from Letta introduced the term sleep time compute to describe this process.

为了致敬其在人脑中的平行机制,Letta 的研究人员引入了“睡眠时计算”(sleep time compute)一词来描述这一过程。

Claude, Codex, and Letta use different variations of memory consolidation. For example, Claude managed agents use idle periods between interactions to reflect on the past and update their memory store, a process they described as dreaming. Their blog gives a great write-up about their approach and findings.

Claude、Codex 和 Letta 使用不同的记忆整合变体。例如,Claude 的管理型智能体会利用交互之间的空闲时间来反思过去并更新其记忆存储,他们将该过程描述为“做梦”。他们的博客文章对其方法和发现进行了精彩的阐述。

Codex asynchronously summarises idle past sessions into markdown files in a /memories directory, linked to their raw transcripts. The directory also contains a summary markdown file with information about the user and a ranked index to the session summaries.

Codex 异步地将空闲的过去会话总结为 /memories 目录中的 markdown 文件,并与原始转录文本链接。该目录还包含一个带有用户信息摘要的 markdown 文件以及指向会话总结的排名索引。

static injectgrep / read · citesonly if a summary misses detailappendsextractspoints topoints toSLEEP-TIME (ASYNC ON STARTUP)User messageturn inputContextmodel windowSessions DBstate sqliteAgentanswers & citesmemory_summary.mdalways loadedrollout_summaries/skills/Raw transcriptssessions/*.jsonlPhase 1: Extractuser-first · no-op gatePhase 2: Consolidateusage_count · git diff

静态注入 grep / 读取 · 引用仅在摘要遗漏细节时追加提取要点至要点SLEEP-TIME (启动时异步)用户消息输入上下文模型窗口会话数据库状态 sqlite智能体回答并引用memory_summary.md始终加载rollout_summaries/skills/原始转录会话/*.jsonl阶段 1:提取用户优先 · 无操作门控阶段 2:整合使用次数 · git diff

Codex injects memory_summary.md and links to rollout summaries and raw transcripts, rebuilt on startup.

Codex 在启动时重建 memory_summary.md 及其对 rollout 总结和原始转录文件的链接,并将其注入。

In the context of consolidation, a closed-loop system would actively use feedback from historical events to improve the memory store. For example, one approach is to create variations of a memory store and iteratively test them on different checkpoints to score outcomes. The variation that produces the least error is then promoted.

在整合的背景下,闭环系统会主动利用历史事件的反馈来改进记忆存储。例如,一种方法是创建记忆存储的变体,并在不同的检查点上迭代测试它们以评估结果。产生最小误差的变体随后会被提升。

forkreplay past checkpointserrort1t2t3t1t2t3t1t2t3lowest errorpromoteMemory storecurrentVariant Amerged duplicatesVariant Brewrote summariesVariant Cdropped stale facts

分叉重放过去检查点错误t1t2t3t1t2t3t1t2t3最低误差提升记忆存储当前变体A合并重复项变体B重写摘要变体C丢弃过时事实

Closed-loop consolidation forks the store, replays past checkpoints, and promotes the lowest-error variant.

闭环整合会分叉存储库,重播历史检查点,并提升错误率最低的变体。

Retrieving experience

检索经验

The goal of retrieval is to find task-relevant information from the past to reduce uncertainty for a known query.

检索的目标是从过去找到与任务相关的信息,以降低对已知查询的不确定性。

recent turnsappends turnlookupinjectquery toolquery toolHistorysql · jsonContextmodel windowAgentanswers turnUser messageturn inputMemoryfacts · graph · notes

最近的轮次应用追加轮次查找注入查询工具查询工具历史sql · json上下文模型窗口代理回答轮次用户消息轮次输入记忆事实 · 图 · 笔记

Retrieval either injects memory via the harness or queries memory and raw history through tools.

检索要么通过框架注入记忆,要么通过工具查询记忆和原始历史记录。

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

关联信息,但可能不是同一事件