← 总览
文章Anthropic· 11-11 · 15:07

智能体记忆的组成部分

The components of agent memory

打开原文约 59 分钟读

Søren Kierkegaard wrote that life can only be understood *backward* , but it must be lived *forward* . We’ve encountered a similar bind when designing memory for AI agents.

As humans, we encode memory constantly as we go about our lives. The hippocampus plays a central role in this, capturing experiences in the moment so that memories form quickly and are immediately available. But only some experiences are consolidated into long-term knowledge.

Much of that consolidation appears to happen when our brains are offline. As we sleep, and during quiet rest , the hippocampus replays our recent experiences. This is thought to gradually distill those experiences and integrate them into the neocortex—the part of our brains that stores most of what we think of as knowledge.

Agent memory can use a similar division of labor. Agents capture much of their work in logs or transcripts. Researchers at Letta and UC Berkeley proposed sleep-time compute as a way for models to use idle time between interactions to reorganize their existing context. The same idea can help agents organize their memory by reflecting on logs to fix mistakes or produce new notes and representations. This process is often called *dreaming* (Figure 1).

We’ve found that dreaming has been a useful tool for helping us give Claude effective memory. In this post, we share how we’ve come to think about agent memory and walk through several evaluations we’ve used to explore agent memory, including the use of dreaming, and what each component contributes to memory organization.

Diagram of a memory hierarchy between one session and the next. From bottom to top: transcripts (a searchable event log), memory notes written by Claude, memory representations such as wikis, and injected context loaded into every session. Inside a box labeled “Dreaming,” arrows run from transcripts up to each layer, and in both directions between neighboring upper layers.

Claude can use dreaming to organize memory. This can correct mistakes, create notes, build new memory representations, or shape what’s preemptively loaded into future sessions.

Memory notes

By “agent memory,” we mean knowledge that Claude gains from experience—including interactions with users and tasks it’s been assigned—and that it retains between sessions, saved as context it can read later. It excludes other ways models can learn or manage context, such as changes to their *weights* (the internal parameters set during training), *in-context learning* (knowledge gained within a single conversation), and *compaction* (summaries written by Claude that replace its older turns so it can continue working in a new context window).

In the human brain, chemical signals released before, during, or after an experience can mark a memory as important. Marked memories tend to be replayed more often than unmarked ones during offline periods. This process, called *replay* , helps stabilize and integrate them into long-term memory.

Similarly, Claude can tag salient events in a session log as they happen, so they’re easier to find later, or it can write them to a memory store, such as a folder of memory notes (Figure 2). But how can Claude tell what’s salient in the moment, before it knows what’s coming next?

The same memory hierarchy, with the memory notes layer highlighted. An arrow runs from the session directly to the memory notes, described as salient observations written by Claude.

Claude can write notes to memory.

Memory can be a prediction about what the future will need

Memory is, occasionally, a prediction. By writing down a rule, an agent predicts that the pattern it’s describing will be relevant again. For instance, writing down a verified fact is a prediction that an agent in a future session will want to rely on that fact without double-checking it. Over time, Claude has become much better at making these kinds of predictions.

Consider a task from Continual Learning Bench (CL-Bench) 1.0 , a benchmark that measures an agent’s ability to use memory in order to tackle long-horizon tasks. One particular task asks Claude to answer a series of questions by looking up information in a database. After Claude gives an answer, it’s told the correct solution and can write a memory to help answer future questions.

Memory can support a learning loop here. If Claude gets a question wrong, it can record the failure, come up with theories about what went wrong, test those theories, and turn what it finds into a rule about how to answer in the future.

We ran the CL-Bench 1.0 task using Claude Managed Agents . Claude started each question in a fresh session, with one exception: it could retrieve files from a memory directory that persisted from one session to the next.

Different models achieved different levels of success at creating their own learning loops. Claude Sonnet 4.6 got as far as generating theories about why an answer was wrong. Its memory directory contained a scattering of files, each listing several untested guesses.

Left: bar chart of mean reward on the CL-Bench database task, stateless baseline versus memory store. Opus 5.5: 0.655, 0.838. Sonnet 5.5: 0.644, 0.833. Opus 5: 0.564, 0.828. Opus 4.7: 0.383, 0.700. Sonnet 5: 0.306, 0.610. Sonnet 4.6: 0.330, 0.364. Right: line chart of running-mean reward over 30 questions for the same models, with and without memory.

CL-Bench database task, comparing memory with a stateless baseline across models.

Claude Opus 4.7 consolidated its notes into a single reference document and began marking which facts it had checked and which were still unconfirmed. Claude Sonnet 5 marked each answer as confirmed after the grader had checked it, and wrote a correction when it had answered wrong.

Claude Opus 5 was the first of these models to close the loop. Most of its entries included a rule (and also how it knew the rule was true), answers to earlier questions, and clear warnings about traps it had discovered along the way (Figure 3).

Like Opus 5, Claude Opus 5.5 and Claude Sonnet 5.5 both closed the loop, using memory to capture validated rules about how to best answer future questions. With memory, both scored about the same as Opus 5, though their baseline performance without memory was slightly higher.

Claude has learned to judge salience

We also evaluated Claude’s ability to play *Pokémon Red* , a game that challenges Claude to navigate complex long-horizon tasks, as a test of Claude’s judgment about *what* to save to memory. At the start of each run, we gave each model a folder of memory files that it could read from and write to while it played (Figure 4).

We compared the memory folders from one run each of Claude Sonnet 3.7 and Claude Fable 5, when each was about 10,000 steps into the game. A key difference we noticed was what each model thought was worth remembering. Sonnet 3.7 assumed everything might matter and wrote to memory indiscriminately. Its memory folder contained an archive of encounters, often with a separate file for each battle it fought, each item it found, and each non-player character it met. Ultimately, Sonnet 3.7 wrote 413 memory files across 225 folders and earned one badge (badges mark a player’s progress through the game).

Fable 5, by comparison, wrote nine files in two folders, plus a single top-level file called global.md , and earned four badges.

Two treemaps of Pokémon memory directories at the same scale, where area shows characters of memory. Claude Sonnet 3.7’s is large and crowded, with 413 files and 977,930 characters across folders such as locations, main, battles, and several “consolidated” folders. Claude Fable 5’s is small, with 10 files and 43,406 characters in locations, gameplay, and global.md.

Claude’s memory directories for Sonnet 3.7 versus Fable 5 while playing Pokémon.

Sonnet 3.7’s approach was a problem mainly because the game state of Pokémon changes constantly—Sonnet 3.7’s detailed record was continuously going out of date. As a result, as Claude progressed, it had to spend more time and resources combing through its memories rather than playing the game. Around step 10,000, for example, Sonnet 3.7 started its fourth folder of “master” memory files. Over the next 17 steps, it created six files, deleted nine others, and took no actions in the game itself.

Fable 5’s approach used memory for things the game didn’t explicitly tell it. Some of the kinds of information Sonnet 3.7 wrote to memory—such as how much money the player has or where the player is on the map—can be read off the screen every turn, so storing it is redundant. By contrast, memory files about strategy, plans, and tested rules exist only if Claude works them out, and they disappear unless Claude writes them down.

Fable 5 organized its memory accordingly. Its global.md file acted as a dashboard, holding the current goal, a prewritten plan for tackling gyms (the challenges where badges are won), and the model’s own rules for using memory. A locations folder held plans for navigating particular routes, and a gameplay folder held strategies based on what it had learned about how the game works. For example, after seven Poké Balls in a row failed to catch a Magikarp (one of the easiest Pokémon to catch), Claude wrote, “If 3+ balls fail in a row, VARY the timing (insert extra ‘wait’ presses between menu steps) - the catch landed right after doing this.”

With a much smaller memory folder, Fable 5 progressed much further in the game than Sonnet 3.7. Opus 5.5 took a similar approach: it kept a small folder of memory notes that tracked its current goal and next steps, rewrote them as it played, and beat the game.

Steering Claude to write memory

We’ve found that it helps to tell Claude what memory is for, but not *how* to use it. On CL-Bench, we simply told Claude that a memory folder was available. That general guidance was enough for Opus 4.7 and Opus 5 to use memory effectively, and it gave both a noticeable boost in performance (Figure 3).

We also tested giving the models specific rules about what they should write to memory, with one rule per test. We compared how much each model gained from memory with each rule against how much it gained without it. When we set a rule to “record only failures,” both Opus 5 and Opus 4.7 lost much of the performance boost that memory gave them (Figure 5, right). For stronger models, giving them freedom to judge salience was more effective than setting fixed rules in advance, and those rules could end up weakening performance.

Left: bar chart of Sonnet 4.6’s mean reward on the CL-Bench database task: 0.330 at baseline, 0.364 with memory, and 0.641 with memory and refined instruction. Reference lines mark Opus 4.7 with memory at 0.700 and Opus 5 with memory at 0.828. Right: change in memory gain when told to record only failures: Opus 5, −0.234; Opus 4.7, −0.150; Sonnet 4.6, −0.020.

Left: Sonnet 4.6 on the CL-Bench database task with and without prompting to guide memory usage. Right: how much each model’s gain from memory changed when it was told to record only failures.

We also noticed that steering helped older models the most. For instance, Sonnet 4.6 often didn’t read files from its memory directory and failed to test its theories about why an answer was wrong.

In this case, prompting Claude to read its memory files before answering—and then to explicitly test its theories—nearly doubled its benchmark score (Figure 5, left). Sonnet 5 does this on its own. Without being prompted to, it read its memory before answering 9 out of 10 times. By comparison, Sonnet 4.6 did this less than half of the time.

With frontier Claude models, we typically give simple guidance to create memory notes when a person asks them to or when something is clearly worth remembering, and we leave that judgment up to Claude.

Dreaming can correct memory

Since Claude writes to memory based on what it judges to be salient in-session, a note that’s wrong from the start or that drifts as the environment changes can be read, and trusted, by Claude in a later session.

Dreaming gives Claude a way to test its notes against the original transcripts (Figure 6). We saw a positive example of this when Claude played Pokémon using Managed Agents with a mounted directory for its memories.

The memory hierarchy with dreaming, highlighting an arrow from the transcripts layer up to the memory notes layer, which shows dreaming correcting notes against transcripts.

Dreaming can correct mistakes in memory.

In one part of the game, the player has to get through Mt. Moon, a cave system with its entrance on the west side of the map and its exit on the east. Near the entrance is a trap: a one-way ledge that drops the player onto the route they came from, with no clear way to climb back up. Claude was using the PokéCenter, a building at the mountain’s entrance, as a landmark, so whether it walked off the ledge depended on which side of the mountain it thought the PokéCenter was on.

At one point, Claude wrote down (incorrectly) that the PokéCenter was on the east side. When it walked out of the PokéCenter, it announced, “Mt Moon is behind me,” and updated its notes: “Mt Moon DONE.” But Mt. Moon was not behind it. A few actions later, Claude went over the ledge and landed back on the route it had come from (Figure 7). Its navigation tool didn’t show the drop, so Claude concluded, “I overshot far west,” and that it had been on the correct side all along. It hadn’t.

Two Pokémon map panels with the agent next to a ledge. Left, “Raw memory,” where the stored note is wrong: an arrow shows the agent heading for the next city. Right, “Memory + dreaming,” where an offline pass corrected the note: an arrow shows the agent heading back to the cave entrance.

A corrected memory note changed the outcome in Pokémon. With the uncorrected note, Claude says, “Mt Moon is behind me,” heads for the next city, and ends up back on the route it came from. With the note corrected by dreaming, it says, “Now I need to find the Mt Moon cave entrance to re-enter,” and goes back into the cave.

We then tested whether dreaming could help Claude avoid this trap. We ran dreaming on the memory folder that contained the wrong location for the PokéCenter: Claude checked the note against the session transcript, caught its error, and rewrote it. The transcript gave Claude a ground truth to validate its memory against. With the corrected memory note, Claude went straight back into Mt. Moon and eventually reached Cerulean City.

In the run with the uncorrected note, Claude dropped back onto that earlier route three times. After the third failure, Claude seemed to give up, writing, “I’m going to stop rather than keep looping.” Our setup’s automatic reply instructed it to continue. So it did, all the way back to Pewter City, the town before the mountain, where it hoped to heal and restock. The run ended without Claude ever reaching Cerulean City.

Line chart of progress toward Cerulean over 3,000 cumulative actions. The memory plus dreaming run reaches Cerulean at action 1,935. The raw memory run falls off the ledge and backtracks to Pewter. The run with no memory never reaches Cerulean.

Dreaming corrects the memory, and Claude goes back into the cave and reaches the next city. The run with the uncorrected note (“Raw memory”) never gets past the mountain, and neither does the run with no memory.

Dreaming can build new memory representations

With dreaming, Claude can build representations to help navigate memory (Figure 9). One type of memory representation it uses is called a *wiki* , a collection of pages written and maintained by Claude that gathers what Claude knows about one subject and links it to other notes. These links effectively provide Claude with a map it can use to sift through its memory and efficiently locate memories when they’re needed.

The memory hierarchy with dreaming, highlighting arrows from transcripts and from memory notes up to the memory representations layer, such as wikis.

Dreaming can build memory representations.

Representations like wikis can help Claude traverse its ever-growing knowledge base. We explored the benefit of wikis as a memory representation using a corpus of internal documents—about 350,000 files, roughly 420M tokens—from Stainless, a software company we acquired in May. We created an evaluation set of 25 questions about this corpus and gave Claude a search tool to explore it. We also instructed Claude to build a wiki based on these files using dreaming. Over 128 sessions, we prompted Opus 5 agents to explore the files, write or correct linked wiki pages, merge duplicates, and check claims against the sources.

Each session built on the progress that agents made in prior sessions, using a shared log to coordinate work. As we scaled dreaming from two sessions to 128, performance on the 25 questions grew from 13% to 48% of graded criteria (Figure 10).

Claude builds its wikis incrementally. After creating an initial wiki, it uses subsequent rounds of dreaming to add to, edit, or prune it. In the early rounds of dreaming, Claude’s knowledge is like that of a new employee, and its ability to answer questions based on the wiki alone is limited. The more it dreams, the richer its knowledge map grows, like that of a seasoned employee. In our tests, we found that the wiki helped Claude the most when we also gave it access to a search tool. When it used both search and the wiki, Claude’s aggregate score rose from 54% to 61% as that wiki grew, compared with 53% when it had access to the search tool alone. Claude’s best score was 48% when it used only the wiki to answer questions. Using search and the wiki also saved about 20,000 tokens per question.

Center: line chart of graded criteria met as wiki generation grows from 2M to 128M dreaming tokens. Wiki plus search tool rises from 54% to 61%, wiki alone rises from 13% to 48%, and the search tool with no wiki is flat at 53%. Left and right: network graphs of an example wiki, with 103 pages and 766 links after 2 sessions and 222 pages and 12,893 links after 128 sessions.

Center: scores on 25 questions about a corpus of documents from a company as Claude built wikis over sequential sessions. Left and right: an example wiki after two and 128 sessions; each dot is a page, and lines join linked pages.

We wanted to test which kinds of tasks benefited from Claude having a wiki. To do this, we used the Harvey LAB benchmark along with a collection of documents about a merger. The benchmark gives Claude a set of documents and asks Claude to generate a legal brief based on their content. The benchmark then grades the brief against a list of criteria. While a tad less engaging, perhaps, than a Pokémon run, these evaluations give us diverse collections of documents to build wikis from.

We instructed Claude to build a wiki from the documents. We then asked Claude to answer questions (about the merger) or generate legal briefs (the LAB benchmark) both from the wiki and from a direct file search. One test asked 24 questions about the merger (Figure 11, left), more than half of which needed Claude to find information across several documents, and many of which also needed Claude to use judgment or do math. On those items (red and orange lines), Claude scored 87% when it consulted the wiki, compared with 73% when it used search alone.

Two diagrams linking graded criteria to source documents. Left, the task where the wiki showed more benefit: most of the 24 criteria connect to two or more of 10 documents, and nine need judgment or arithmetic. Right, the task where the wiki showed less benefit: most of the 57 criteria can be found by text search in a single document, usually the deal overview memo.

Each panel lists what was graded (left) and the source documents needed to meet each one (right). Left: 24 questions about a merger, which can be answered by looking at mostly public filings. More than half of the criteria required combining information from several documents. Right: a LAB task where the wiki showed no clear gain. Most criteria could be met from a single document.

In other cases, the wiki was less useful. On one LAB task (Figure 11, right), brief criteria often could be retrieved with a text search from a single document, and the wiki showed no clear gain in performance relative to search. On another LAB task, the wiki grew larger than the documents themselves (Figure 12). Like the mapmakers in Borges’s one-paragraph short story “On Exactitude in Science,” who drafted a map so detailed it was as large as the empire it represented, Claude had made an extremely detailed wiki that effectively abstracted nothing.

Diagram of a wiki build and second pass. On the left, a circle holds the corpus: 10 documents, 115 KB of text. An arrow leads to a larger circle holding the wiki built from it: 68 pages, 255 links, and 203 KB, or 1.77 times the corpus. Some of the wiki’s pages have no links.

The wiki grew to be larger than the raw files.

Dreaming can promote notes up the memory hierarchy

Dreaming can also float notes to the top of the memory hierarchy, and the agent harness can preemptively load them into Claude’s context at the start of every session (Figure 13). This means Claude doesn’t need to search for them, or even to know there’s something to search for.

Promoting memories into a new session (a form of *context injection* ) must be done carefully. Injected memories use up valuable tokens, and an incorrect note can be carried into every session. Loading a note also doesn’t guarantee that Claude acts on it: our documentation on Claude Code warns that longer instruction files reduce adherence. So the top layer of the memory hierarchy has to stay relatively small, and much of dreaming’s work here is keeping it that way—by moving some details down the hierarchy and leaving links behind.

Claude Code’s auto memory keeps its injected layer small in the same way, with Claude maintaining it during the session. Claude doesn’t load all of its auto memory into every session’s context window. It loads only the first 200 lines or 25 KB of MEMORY.md . This header serves as an index, which shows Claude what it knows and where to find it.

The memory hierarchy with dreaming, highlighting arrows from transcripts and from memory representations up to the injected context layer at the top, which feeds into the next session.

Dreaming can write to the top of the memory hierarchy. Injected context is loaded into every session, and the layers below it are read or searched when Claude needs them.

Dreaming can focus memory on a specific goal

Dreaming can also shape how memory grows. An assistant like Claude Duet , for example, often benefits from having memories that are organized around the person it’s helping, and dreaming can be tuned to build memory in service of a particular goal.

The instructions that guide how memory grows differ by task and tell Claude what information actually matters. For example, one task in the LAB benchmark simulates a company acquisition and provides a set of contracts. The brief is graded on whether it correctly describes the contract terms.

We started with basic instructions for generating the wiki that didn’t tell Claude *how* to use the wiki. This task relied heavily on contract terms. While the wiki was being built, several agents wrote to a shared table of contract terms at the same time (Figure 14, left).

Two diagrams. Before: four agents write to the same shared page, provisions.md, and one agent’s save erases another’s lines; 41 of 57 graded facts survived. After: four agents each write their own contract’s page, with terms copied word for word; all 57 of 57 graded facts survived.

How many graded contract facts made it into the wiki, before and after instructions changed. Left: several agents writing to one shared page; 41 of 57 facts survived. Right: one agent per contract, each writing its own page and quoting terms word for word; 57 of 57 facts survived.

The result was a wiki that was missing key facts. When we graded a brief generated from the wiki, Claude had included only 41 of the 57 facts (72%). When we looked at what had gone wrong, we found that the shared table summarized the contract terms poorly and was missing some of them altogether, because agents had overwritten one another’s work.

The contract terms were the most important part of the wiki, but the instructions didn’t say that. To find better instructions, we ran a loop in which Claude reflected on its failures, proposed a change to the instructions, and rebuilt the wiki. This loop allowed Claude to discover how important it was to follow the contract terms, and it rewrote the instructions for building the wiki accordingly.

Each contract got its own page in the wiki, written by a single agent, which quoted the terms word for word rather than summarizing them into a shared table. When we graded the brief generated from this improved wiki, 100% of the criteria could be met, up from 72%.

Dreaming can fill in gaps a session leaves behind

When Claude writes memory notes, it sees only the context in *that* particular session. Dreaming can search across many sessions to find common patterns or correct common mistakes.

When building the wikis for the LAB benchmark (as an example, see Figure 14), sometimes Claude would link to pages that hadn’t yet been created. A second dreaming pass closed many of these gaps. On one task (Figure 15), dreaming found nine links to a missing page in the wiki and repointed them to an existing page for the same document. It also added three new pages, including an index, to improve the wiki.

Two network graphs of a wiki. Before the second pass: 38 entries and 225 links, with nine links from six pages pointing to “escrow-agreement,” a page that doesn’t exist. After: 41 entries and 278 links, with all nine links pointing to “buyer-form-escrow-agreement” and three new pages: index, instructions email, and escalations.

The wiki before and after a second dreaming pass.

Thinking backward, looking forward

There are many open questions about how to design memory systems for agents. One is when Claude should create memory. When Claude works on a task, it can write to a memory store (e.g., a folder, file, or database), capturing salience at the source and making important details immediately available for future turns or sessions. But logging notes in the moment inevitably draws Claude’s attention away from its main task. In contrast, dreaming can push memory creation to the background, but any outputs from dreaming may not be immediately accessible to Claude.

Another question is how to keep memory reliably up to date. Claude can make incorrect predictions or write rules to memory that are wrong from the start. Memory can also drift and become irrelevant as the environment changes. Dreaming is one way to fix these mistakes (Figure 8), but it requires compute. Directing Claude to continuously check *all* its memories might not be practical. It may be important instead to focus dreaming on information that’s likely to change or to carefully tune the cadence of dreaming (e.g., based on how often memories are accessed).

It’s also reasonable to consider transcript search as the foundation of Claude’s memory. Combining representations (e.g., wikis) with search (Figure 10) can sometimes be effective. But Claude needs to use compute to maintain memory representations and make sure they don’t accumulate errors or hallucinations.

Even though Claude’s judgment about salience has improved, no model can really know what will happen in future turns. Dreaming gives Claude an opportunity to look *backward* and use compute to organize its memory, correct mistakes, and maintain representations that allow future sessions to access memory more readily. Memory systems will evolve as Claude gets more capable, and we still have a lot to learn about designing Claude’s memory systems.

See our cookbooks for getting started with dreaming and knowledge wikis .

索伦·克尔凯郭尔写道,生活只有 *回望* 才能理解,但必须 *向前* 生活。我们在为 AI 智能体设计记忆时,也遇到了类似的困境。

作为人类,我们在日常生活中会不断编码记忆。 海马体 在此过程中发挥核心作用,它会在当下捕捉经历,使记忆快速形成并可立即调用。但只有 某些经历 会被巩固为长期知识。

这种巩固似乎大多发生在我们的大脑离线时。当我们睡觉以及处于安静 休息 状态时,海马体会重放我们近期的经历。人们认为,这会逐渐提炼 这些经历并将其整合 进新皮层——我们大脑中储存大部分我们视作知识的部分。

智能体记忆可以采用类似的分工。智能体会把大量工作记录在日志或转录记录中。Letta 与 UC Berkeley 的研究人员提出了 睡眠时间计算 ,让模型利用交互之间的空闲时间重新组织现有上下文。同样的思路可以帮助智能体通过反思日志来整理记忆,以修正错误或生成新的笔记和记忆表示。这个过程通常 被称作 *梦境整理* (图 1)。

我们发现,梦境整理是一个有用的工具,能帮助我们为 Claude 提供有效的记忆。在本文中,我们将分享我们对智能体记忆的思考方式,并介绍我们用来探索智能体记忆的若干评估,包括梦境整理的使用,以及每个组成部分对记忆组织的贡献。

Diagram of a memory hierarchy between one session and the next. From bottom to top: transcripts (a searchable event log), memory notes written by Claude, memory representations such as wikis, and injected context loaded into every session. Inside a box labeled “Dreaming,” arrows run from transcripts up to each layer, and in both directions between neighboring upper layers.

Claude 可以使用梦境整理来组织记忆。这可以修正错误、创建笔记、构建新的记忆表示,或塑造预先加载到未来会话中的内容。

记忆笔记

所谓“智能体记忆”,我们指的是 Claude 从经验中获得的知识——包括与用户的交互以及它被分配的任务——并且会在会话之间保留,保存为之后可读取的上下文。它不包括模型学习或管理上下文的其他方式,例如改变其 *权重* (训练期间设置的内部参数)、 *上下文学习* (在单次对话中获得的知识),以及 *压缩* (由 Claude 撰写、用于替换较早轮次以便它能在新的上下文窗口中继续工作的摘要)。

在人脑中,一次经历之前、之中或之后释放的化学信号可以 将一段记忆标记 为重要。被标记的记忆在离线期间往往比未被标记的记忆更频繁地被重放。这个过程被称为 *重放* ,有助于稳定这些记忆并将它们整合到长期记忆中。

同样,Claude 可以在会话日志中标记当下发生的显著事件,以便之后更容易找到,或者它可以 将它们写入 记忆存储,例如记忆笔记文件夹(图 2)。但 Claude 如何在当下、在尚不知道接下来会发生什么之前,判断什么才是显著的?

The same memory hierarchy, with the memory notes layer highlighted. An arrow runs from the session directly to the memory notes, described as salient observations written by Claude.

Claude 可以将笔记写入记忆。

记忆可以是对未来需求的预测

记忆偶尔也是一种预测。通过写下一条规则,智能体是在预测它所描述的模式会再次变得相关。例如,写下一个已验证的事实,就是在预测未来会话中的智能体会希望依赖该事实,而无需再次核实。随着时间推移,Claude 在这类预测上已经变得更加擅长。

以 持续学习基准(CL-Bench)1.0 中的一项任务为例,该基准测试衡量智能体利用记忆完成长时程任务的能力。其中一项具体任务要求 Claude 通过在数据库中查找信息来回答一系列问题。Claude 给出答案后,会被告知正确解法,并且可以写入一条记忆,以帮助回答未来的问题。

在这里,记忆可以支撑一个学习循环。如果 Claude 答错了一个问题,它可以记录这次失败,提出关于哪里出错的假设,验证这些假设,并将发现转化为未来如何回答的规则。

我们使用 Claude Managed Agents 运行了 CL-Bench 1.0 任务。Claude 对每个问题都从全新的会话开始,只有一个例外:它可以从一个 记忆目录 中检索文件,该目录会从一个会话持续保留到下一个会话。

不同模型在创建自己的学习循环方面取得了不同程度的成功。Claude Sonnet 4.6 只做到生成关于答案为何错误的假设。它的记忆目录中散落着一些文件,每个文件都列出了若干未经检验的猜测。

Left: bar chart of mean reward on the CL-Bench database task, stateless baseline versus memory store. Opus 5.5: 0.655, 0.838. Sonnet 5.5: 0.644, 0.833. Opus 5: 0.564, 0.828. Opus 4.7: 0.383, 0.700. Sonnet 5: 0.306, 0.610. Sonnet 4.6: 0.330, 0.364. Right: line chart of running-mean reward over 30 questions for the same models, with and without memory.

CL-Bench 数据库任务,比较记忆与无状态基线在不同模型上的表现。

Claude Opus 4.7 将其笔记整合为一份参考文档,并开始标记哪些事实已经核实、哪些仍未确认。Claude Sonnet 5 在评分器检查后,将每个答案标记为已确认;当它回答错误时,会写下更正。

Claude Opus 5 是这些模型中第一个完成闭环的。它的大多数条目都包含一条规则(以及它如何知道该规则为真)、对先前问题的答案,以及对沿途发现陷阱的明确警告(图 3)。

与 Opus 5 一样,Claude Opus 5.5 和 Claude Sonnet 5.5 也都完成了闭环,利用记忆来记录关于如何最好地回答未来问题的已验证规则。有记忆时,两者的得分与 Opus 5 大致相同,不过它们无记忆时的基线表现略高。

Claude 已学会判断显著性

我们还评估了 Claude 游玩 *《宝可梦 红》* 的能力,这款游戏 要求 Claude 应对 复杂的长时程任务,以此测试 Claude 对 *哪些内容* 应保存到记忆中的判断。每次运行开始时,我们给每个模型一个装有记忆文件的文件夹,它可以在游玩时读取和写入这些文件(图 4)。

我们比较了 Claude Sonnet 3.7 和 Claude Fable 5 各自一次运行中的记忆文件夹,当时两者都大约进行到游戏的第 10,000 步。我们注意到的一个关键差异是,每个模型认为什么值得记住。Sonnet 3.7 假设一切都可能重要,并不加区分地写入记忆。它的记忆文件夹中存有遭遇档案,通常为每场战斗、每件找到的物品和每个遇到的非玩家角色分别建立文件。最终,Sonnet 3.7 在 225 个文件夹中写入了 413 个记忆文件,并获得了一枚徽章(徽章标志着玩家在游戏中的进度)。

相比之下,Fable 5 在两个文件夹中写了九个文件,外加一个名为 global.md 的单一顶层文件,并获得了四枚徽章。

Two treemaps of Pokémon memory directories at the same scale, where area shows characters of memory. Claude Sonnet 3.7’s is large and crowded, with 413 files and 977,930 characters across folders such as locations, main, battles, and several “consolidated” folders. Claude Fable 5’s is small, with 10 files and 43,406 characters in locations, gameplay, and global.md.

Claude 在游玩宝可梦时,Sonnet 3.7 与 Fable 5 的记忆目录对比。

Sonnet 3.7 的方法之所以成为问题,主要是因为宝可梦的游戏状态不断变化——Sonnet 3.7 的详细记录在不断过时。因此,随着 Claude 推进,它不得不花更多时间和资源梳理记忆,而不是游玩游戏。例如,在第 10,000 步左右,Sonnet 3.7 启用了它的第四个“主”记忆文件文件夹。在接下来的 17 步中,它创建了六个文件,删除了另外九个文件,并且没有在游戏中采取任何行动。

Fable 5 的方法则将记忆用于游戏没有明确告知它的事项。Sonnet 3.7 写入记忆的某些信息——例如玩家有多少钱或玩家在地图上的位置——每回合都能从屏幕上读到,因此存储这些信息是多余的。相比之下,关于策略、计划和经过测试的规则的记忆文件,只有在 Claude 推导出来后才存在,而且除非 Claude 将它们写下来,否则就会消失。

Fable 5 相应地组织了自己的记忆。它的 global.md 文件充当仪表盘,保存当前目标、预先写好的攻克道馆计划(赢得徽章的挑战),以及模型自己使用记忆的规则。一个 locations 文件夹保存了在特定路线中导航的计划,还有一个 gameplay 文件夹保存了基于它对游戏运作方式所学内容而形成的策略。例如,在连续七个精灵球都没能抓住鲤鱼王(最容易捕捉的宝可梦之一)后,Claude 写道:“如果连续 3 个以上的球失败,就改变时机(在菜单步骤之间额外按下‘等待’)——这样做之后立刻就抓到了。”

凭借小得多的记忆文件夹,Fable 5 在游戏中取得的进展远超 Sonnet 3.7。Opus 5.5 采用了类似的方法:它维护一个小型记忆笔记文件夹,用来跟踪当前目标和后续步骤,在游玩过程中重写这些笔记,并最终通关了游戏。

引导 Claude 写入记忆

我们发现,告诉 Claude 记忆的用途会有帮助,但不要告诉它 *如何* 使用记忆。在 CL-Bench 上,我们只是告诉 Claude 有一个可用的记忆文件夹。这一通用指导足以让 Opus 4.7 和 Opus 5 有效使用记忆,并使两者的表现都有明显提升(图 3)。

我们还测试了给模型设定关于应写入记忆内容的具体规则,每项测试一条规则。我们比较了每个模型在每种规则下从记忆中获得的提升,与没有规则时获得的提升。当我们把规则设为“只记录失败”时,Opus 5 和 Opus 4.7 都失去了记忆带来的大部分性能提升(图 5,右)。对于更强的模型,让它们自由判断显著性比预先设定固定规则更有效,而那些规则最终可能会削弱性能。

Left: bar chart of Sonnet 4.6’s mean reward on the CL-Bench database task: 0.330 at baseline, 0.364 with memory, and 0.641 with memory and refined instruction. Reference lines mark Opus 4.7 with memory at 0.700 and Opus 5 with memory at 0.828. Right: change in memory gain when told to record only failures: Opus 5, −0.234; Opus 4.7, −0.150; Sonnet 4.6, −0.020.

左:Sonnet 4.6 在 CL-Bench 数据库任务中,使用和不使用提示引导记忆使用的情况。右:当被告知只记录失败时,每个模型从记忆中获得的提升变化了多少。

我们还注意到,引导对较旧的模型帮助最大。例如,Sonnet 4.6 常常不读取其记忆目录中的文件,也未能验证其关于答案为何错误的假设。

在这种情况下,提示 Claude 在回答前读取其记忆文件——然后明确验证其假设——几乎使它的基准测试得分翻倍(图 5,左)。Sonnet 5 会自行这样做。在未被提示的情况下,它每 10 次回答中有 9 次会在回答前读取记忆。相比之下,Sonnet 4.6 这样做的次数不到一半。

对于前沿 Claude 模型,我们通常只给出简单指引:当用户要求创建记忆笔记,或某件事显然值得记住时,就创建记忆笔记;具体判断留给 Claude。

梦境整理可以纠正记忆

由于 Claude 会根据它判断在会话中显著的内容写入记忆,一条从一开始就错误、或随着环境变化而逐渐偏离的笔记,可能会在之后的会话中被 Claude 读取并信任。

梦境整理让 Claude 能对照原始转录记录检验自己的笔记(图 6)。当 Claude 使用 Managed Agents,并通过挂载目录存放记忆来游玩《宝可梦》时,我们看到了一个正面例子。

The memory hierarchy with dreaming, highlighting an arrow from the transcripts layer up to the memory notes layer, which shows dreaming correcting notes against transcripts.

梦境整理可以纠正记忆中的错误。

在游戏的一个环节中,玩家必须穿过月见山,这是一片洞穴系统,入口位于地图西侧,出口位于东侧。入口附近有一个陷阱:一处单向断崖,会让玩家掉回先前来时的路线,而且没有明确的办法爬回去。Claude 把位于山入口的宝可梦中心建筑当作地标,因此它是否会走下断崖,取决于它认为宝可梦中心位于山的哪一侧。

有一次,Claude(错误地)记下宝可梦中心在东侧。当它走出宝可梦中心时,它宣称:“月见山在我身后”,并更新笔记:“月见山已完成。”但月见山并不在它身后。几个动作之后,Claude 越过断崖,落回了它来时的路线(图 7)。它的导航工具没有显示这处落差,于是 Claude 得出结论:“我往西走得太远了”,并认为自己一直就在正确的一侧。事实并非如此。

Two Pokémon map panels with the agent next to a ledge. Left, “Raw memory,” where the stored note is wrong: an arrow shows the agent heading for the next city. Right, “Memory + dreaming,” where an offline pass corrected the note: an arrow shows the agent heading back to the cave entrance.

一条经过纠正的记忆笔记改变了《宝可梦》中的结果。使用未纠正的笔记时,Claude 会说“月见山在我身后”,朝下一座城市前进,结果却回到来时的路线。而经梦境整理纠正笔记后,它会说“现在我得找到月见山的洞穴入口,才能重新进入”,然后返回洞穴。

随后我们测试了梦境整理能否帮助 Claude 避开这个陷阱。我们对包含宝可梦中心错误位置的记忆文件夹运行梦境整理:Claude 对照会话转录记录检查笔记,发现了自己的错误并重写了它。这份转录记录为 Claude 提供了一个可用于验证记忆的真实基准。借助纠正后的记忆笔记,Claude 直接返回月见山,并最终抵达华蓝市。

在使用未纠正笔记的那次运行中,Claude 三次掉回先前的路线。第三次失败后,Claude 似乎放弃了,写道:“我要停下来,不再一直循环。”我们设置的自动回复指示它继续。于是它照做了,一路回到山前的城镇深灰市,希望在那里治疗并补充物资。那次运行结束时,Claude 始终没能抵达华蓝市。

Line chart of progress toward Cerulean over 3,000 cumulative actions. The memory plus dreaming run reaches Cerulean at action 1,935. The raw memory run falls off the ledge and backtracks to Pewter. The run with no memory never reaches Cerulean.

梦境整理纠正记忆后,Claude 返回洞穴并抵达下一座城市。使用未纠正笔记(“原始记忆”)的那次运行始终没能越过这座山,完全没有记忆的那次运行也是如此。

梦境整理可以构建新的记忆表示

借助梦境整理,Claude 可以构建帮助它在记忆中导航的表示(图 9)。它使用的一种记忆表示叫作*维基*,即一组由 Claude 编写和维护的页面,汇集 Claude 关于某一主题的知识,并将其链接到其他笔记。这些链接实际上为 Claude 提供了一张地图,让它能筛选自己的记忆,并在需要时高效定位记忆。

The memory hierarchy with dreaming, highlighting arrows from transcripts and from memory notes up to the memory representations layer, such as wikis.

梦境整理可以构建记忆表示。

像维基这样的表示可以帮助 Claude 遍历其不断增长的知识库。我们利用一套内部文档语料库,探索了维基作为记忆表示的好处——这些文档来自我们于 5 月收购的软件公司 Stainless,约 35 万个文件,约 4.2 亿个 token。我们围绕该语料库创建了一套包含 25 个问题的评测集,并给 Claude 一个搜索工具来探索它。我们还指示 Claude 使用梦境整理基于这些文件构建维基。在 128 个会话中,我们提示 Opus 5 智能体探索文件、编写或纠正相互链接的维基页面、合并重复内容,并对照来源核查说法。

每个会话都建立在智能体在先前会话中取得的进展之上,并使用共享日志协调工作。随着我们将梦境整理从两个会话扩展到 128 个会话,在这 25 个问题上的评分标准达成率从 13% 升至 48%(图 10)。

Claude 会逐步构建维基。创建初始维基后,它会利用后续轮次的梦境整理来补充、编辑或修剪维基。在梦境整理的早期轮次中,Claude 的知识就像一名新员工,仅凭维基回答问题的能力有限。它进行的梦境整理越多,其知识地图就越丰富,就像一名经验丰富的员工。在测试中,我们发现,当我们同时让 Claude 使用搜索工具时,维基对它的帮助最大。当 Claude 同时使用搜索和维基时,随着维基不断扩展,其综合得分从 54% 升至 61%;而仅能使用搜索工具时为 53%。仅使用维基回答问题时,Claude 的最高得分为 48%。同时使用搜索和维基还为每个问题节省了约 20,000 个 token。

Center: line chart of graded criteria met as wiki generation grows from 2M to 128M dreaming tokens. Wiki plus search tool rises from 54% to 61%, wiki alone rises from 13% to 48%, and the search tool with no wiki is flat at 53%. Left and right: network graphs of an example wiki, with 103 pages and 766 links after 2 sessions and 222 pages and 12,893 links after 128 sessions.

中间:随着 Claude 在连续多个会话中构建维基,其在一套公司文档语料库相关 25 个问题上的得分。左图和右图:分别在两个会话和 128 个会话后的示例维基;每个点代表一个页面,连线连接相互链接的页面。

我们想测试哪些类型的任务能从 Claude 拥有维基中受益。为此,我们使用了 Harvey LAB 基准测试以及一组关于某次合并的文档。该基准测试给 Claude 一组文档,要求 Claude 根据其内容生成法律简报,然后依据一系列标准为该简报评分。虽然这些评测或许不如一次《宝可梦》游玩过程那么有趣,但它们为我们提供了多样化的文档集合来构建维基。

我们指示 Claude 根据这些文档构建维基。随后,我们要求 Claude 分别借助维基和直接文件搜索来回答(关于此次合并的)问题,或生成法律简报(LAB 基准测试)。其中一项测试提出了 24 个关于此次合并的问题(图 11 左),其中超过一半需要 Claude 跨多个文档查找信息,许多还需要 Claude 运用判断或进行计算。在这些题目上(红色和橙色线),Claude 查阅维基时得分为 87%,而仅使用搜索时为 73%。

Two diagrams linking graded criteria to source documents. Left, the task where the wiki showed more benefit: most of the 24 criteria connect to two or more of 10 documents, and nine need judgment or arithmetic. Right, the task where the wiki showed less benefit: most of the 57 criteria can be found by text search in a single document, usually the deal overview memo.

每个面板都列出了评分内容(左)以及满足每项标准所需的源文档(右)。左:24 个关于某次合并的问题,大多可以通过查阅公开申报文件来回答。超过一半的标准需要结合多个文档中的信息。右:一项 LAB 任务,维基没有表现出明显增益。大多数标准可以仅凭单一文档满足。

在其他情况下,维基的用处较小。在一项 LAB 任务中(图 11 右),简报标准通常可以通过对单个文档进行文本搜索来获取,而维基相对于搜索没有表现出明显的性能增益。在另一项 LAB 任务中,维基变得比文档本身还大(图 12)。就像博尔赫斯那篇仅一段的短篇小说《论科学的精确性》中的制图师一样——他们绘制的地图极其详尽,竟与其所代表的帝国一样大——Claude 也制作了一个极其详尽的维基,实际上没有提炼出任何内容。

Diagram of a wiki build and second pass. On the left, a circle holds the corpus: 10 documents, 115 KB of text. An arrow leads to a larger circle holding the wiki built from it: 68 pages, 255 links, and 203 KB, or 1.77 times the corpus. Some of the wiki’s pages have no links.

维基变得比原始文件还大。

梦境整理可以将笔记提升到记忆层级的上层

梦境整理还可以将笔记上浮到记忆层级的顶层,智能体运行框架可以在每个会话开始时提前将它们加载到 Claude 的上下文中(图 13)。这意味着 Claude 无需搜索这些笔记,甚至无需知道有东西需要搜索。

将记忆提升到新会话中(一种*上下文注入*)必须谨慎进行。注入的记忆会消耗宝贵的 token,而一条错误的笔记可能被带入每个会话。加载一条笔记也不保证 Claude 会照它行动:我们关于 Claude Code 的文档警告说,较长的指令文件会降低遵循度。因此,记忆层级的顶层必须保持相对较小,而梦境整理在这里的许多工作就是维持这一点——把一些细节下移到更低层级,并留下链接。

Claude Code 的自动记忆也以同样的方式保持其注入层较小,由 Claude 在会话期间维护。Claude 不会把所有自动记忆都加载到每个会话的上下文窗口中。它只加载 MEMORY.md 的前 200 行或 25 KB。这个头部充当索引,向 Claude 展示它知道什么以及到哪里查找。

The memory hierarchy with dreaming, highlighting arrows from transcripts and from memory representations up to the injected context layer at the top, which feeds into the next session.

梦境整理可以写入记忆层级的顶层。注入的上下文会被加载到每个会话中,而更低的层级则在 Claude 需要时被读取或搜索。

梦境整理可以让记忆聚焦于特定目标

梦境整理还可以塑造记忆的增长方式。例如,像 Claude Duet 这样的助手,通常会受益于围绕它所帮助的人来组织记忆,而梦境整理可以通过调整来构建服务于特定目标的记忆。

指导记忆如何增长的指令因任务而异,并告诉 Claude 哪些信息真正重要。例如,LAB 基准测试中的一项任务模拟公司收购,并提供一组合同。法律简报的评分取决于它是否正确描述了合同条款。

我们最初用于生成维基的基本指令没有告诉 Claude*如何*使用维基。这项任务高度依赖合同条款。在构建维基期间,多个智能体同时写入一张共享的合同条款表(图 14 左)。

Two diagrams. Before: four agents write to the same shared page, provisions.md, and one agent’s save erases another’s lines; 41 of 57 graded facts survived. After: four agents each write their own contract’s page, with terms copied word for word; all 57 of 57 graded facts survived.

在指令修改前后,有多少用于评分的合同事实进入了维基。左:多个智能体写入同一个共享页面;57 条事实中有 41 条保留下来。右:每份合同由一个智能体负责,各自编写自己的页面并逐字引用条款;57 条事实全部保留。

结果是维基缺失了关键事实。当我们对根据该维基生成的法律简报评分时,Claude 只纳入了 57 条事实中的 41 条(72%)。当我们查看问题出在哪里时,发现共享表格对合同条款的概括很差,而且完全遗漏了其中一些条款,因为智能体互相覆盖了彼此的工作。

合同条款是维基中最重要的部分,但指令并没有说明这一点。为了找到更好的指令,我们运行了一个循环:Claude 反思自己的失败,提出对指令的修改,并重建维基。这个循环让 Claude 发现遵循合同条款有多么重要,它也据此重写了构建维基的指令。

每份合同在维基中都有自己的页面,由单个智能体编写;该智能体逐字引用条款,而不是将其概括进共享表格。当我们对根据这个改进后的维基生成的法律简报评分时,100% 的标准都能得到满足,高于此前的 72%。

梦境整理能填补单次会话遗留的空白

当 Claude 撰写记忆笔记时,它只能看到 *该* 特定会话中的上下文。梦境整理可以搜索多个会话,找出常见模式或纠正常见错误。

在为 LAB 基准测试构建维基时(示例见图 14),Claude 有时会链接到尚未创建的页面。第二轮梦境整理填补了许多此类空白。在一项任务中(图 15),梦境整理发现维基中有九条链接指向一个缺失页面,并将它们重新指向同一文档的现有页面。它还新增了三个页面(包括一个索引),以改进维基。

Two network graphs of a wiki. Before the second pass: 38 entries and 225 links, with nine links from six pages pointing to “escrow-agreement,” a page that doesn’t exist. After: 41 entries and 278 links, with all nine links pointing to “buyer-form-escrow-agreement” and three new pages: index, instructions email, and escalations.

第二轮梦境整理前后的维基。

回望过去,展望未来

关于如何为智能体设计记忆系统,仍有许多悬而未决的问题。其中之一是 Claude 应在何时创建记忆。当 Claude 处理任务时,它可以写入记忆存储(例如文件夹、文件或数据库),在源头捕捉显著性,让重要细节能立即供后续轮次或会话使用。但在当下记录笔记不可避免地会让 Claude 的注意力偏离主要任务。相比之下,梦境整理可以把记忆创建推到后台,但梦境整理的任何输出可能无法立即被 Claude 访问。

另一个问题是如何让记忆可靠地保持最新。Claude 可能做出错误预测,或向记忆写入从一开始就错误的规则。随着环境变化,记忆也可能发生漂移并变得无关。梦境整理是修正这些错误的一种方式(图 8),但它需要计算资源。让 Claude 持续检查 *所有* 记忆可能并不实际。相反,也许更重要的是让梦境整理聚焦于可能变化的信息,或仔细调整梦境整理的节奏(例如,根据记忆被访问的频率)。

将转录记录搜索视为 Claude 记忆的基础也是合理的。将表示形式(例如维基)与搜索结合(图 10)有时可能很有效。但 Claude 需要使用计算资源来维护记忆表示,并确保它们不会累积错误或幻觉。

尽管 Claude 对显著性的判断已经有所改善,但没有任何模型能真正预知未来轮次会发生什么。梦境整理让 Claude 有机会 *回望* 过去,并利用计算资源整理记忆、修正错误,维护表示形式,使未来会话更容易访问记忆。随着 Claude 能力增强,记忆系统也将不断演进,而关于如何设计 Claude 的记忆系统,我们仍有许多东西需要学习。

请参阅我们的 cookbook,了解 如何开始使用梦境整理 以及 知识维基 。