The Components of Agent Memory

agent research-components-of-agent-memory
agent-memorycontext-engineeringcontinual-learningdreamingsalience

The Components of Agent Memory #

1. TL;DR #

Agent memory = retained cross-session knowledge, reframed as prediction about future needs. A four-layer hierarchy (transcripts → notes → representations → injected context), consolidated by a background "dreaming" pass, lets stronger models convert raw experience into validated rules — raising CL-Bench reward and wiki-task criteria while cutting ~20k tokens/question.

2. Q1 / Q2 / Q3 #

Q1 — 痛点 (Problem) #

An agent that treats every session as a cold start repeats mistakes, re-derives known facts, and cannot accumulate expertise. Naive logging fails in the opposite direction: an agent that records everything drowns in stale, redundant notes whose maintenance cost grows as the environment changes. The objective is not storage but salience — deciding, at write time, which observations a future and unknowable session will actually need. This is a prediction problem under uncertainty: the write happens now, the payoff is realized (or not) in a session that does not yet exist.

The article scopes "memory" narrowly to knowledge retained between sessions from user interactions and assigned tasks, explicitly excluding weight updates, in-context learning, and context compaction. That scoping matters: it isolates memory as a data/representation strategy layered on a frozen policy, not a training-time intervention.

Q2 — 方法 (Method) #

A layered knowledge store plus a background consolidation process:

  1. Four-layer hierarchy — transcripts (searchable event logs) → memory notes (salient observations written during/after tasks) → memory representations (structured artifacts such as wikis) → injected context (preloaded into every new session).
  2. Dreaming — an idle-time background process that reorganizes memory: cross-session synthesis, error correction against original transcripts, and promotion of notes up the hierarchy.
  3. Steering over rules — task-specific guidance (not rigid prescriptive rules) directs what gets written; the agent itself reflects on failures and proposes instruction changes.
  4. 核心技术壁垒 (the single hardest-to-replicate insight): memory value is gated by model capability, and inversely gated by rule rigidity. The same memory substrate yields +0.034 reward for a weak model and +0.264 for a strong one; imposing a prescriptive rule ("record only failures") costs a strong model −0.234 while barely touching a weak one. The hard-to-copy asset is therefore not the wiki format or the dreaming loop — those are mechanically simple — but the calibration that lets a frontier model self-direct salience from loose guidance. A replicator with a weaker base model cannot recover the headline numbers by copying the pipeline.

    Q3 — 结果 (Results) #

    • CL-Bench 1.0 (database lookup): memory lifts every model; the strongest absolute gains land on mid-tier models (Opus 4.7 +0.317, Sonnet 5 +0.304), while the ceiling models rise from already-high baselines (Opus 5.5 0.655 → 0.838).
    • Pokémon Red (salience): Fable 5 earned 4 badges with 10 memory files / 43k chars; Sonnet 3.7 earned 1 badge with 413 files / 978k chars — more logging, worse play.
    • Dreaming correction: on the Mt. Moon case, dreaming drove ledge falls from 3 → 0 and turned a failed run into a completed one.
    • Wiki representations (Stainless, 350k files / 420M tokens): wiki + search reached 61% criteria vs. 53% flat for search-only, saving ~20k tokens/question.

    3. 方法图 (Architecture / Flow) #

    No original figures were published with an extractable asset, so the hierarchy and the dreaming loop are redrawn below.

    Four-layer memory hierarchy (bottom = raw, top = always-loaded) #

    flowchart BT T["Transcripts
    searchable event logs"] N["Memory Notes
    salient observations"] R["Memory Representations
    structured wikis"] I["Injected Context
    preloaded every session"] T -->|salience judgment| N N -->|synthesis / structuring| R R -->|promotion| I D["Dreaming
    idle-time consolidation"] D -.->|verify against source| T D -.->|correct & merge| N D -.->|grow & repair links| R D -.->|promote| I

    The vertical axis is an abstraction gradient: each upward step trades fidelity for retrievability, and each step is also a risk step — an error promoted to injected context is paid on every future session. Dreaming is the only edge that reads downward against transcripts, which is why it is the mechanism that can un-poison the upper layers.

    Dreaming consolidation cycle #

    sequenceDiagram participant S as Live Session participant Mem as Memory Store participant Dream as Dreaming (idle) participant Tx as Transcripts S->>Mem: write notes (predicted-useful) S->>Tx: append full event log Note over S,Mem: session ends Dream->>Tx: re-read original transcript Dream->>Mem: cross-check notes vs. ground truth Dream->>Mem: correct false entries / merge dupes Dream->>Mem: promote confirmed notes upward Mem-->>S: injected context for next session

    4. 作者证明 (Formal Analysis) #

    无形式化作者证明 — 仅实证.

    This is an engineering research article; it states no theorem, convergence proposition, or sample-complexity bound. All claims are supported by benchmark deltas rather than analysis. What would have strengthened it:

    • A formal salience objective — e.g. writing memory to maximize expected future-task reward, $\max_{m}\ \mathbb{E}_{q\sim\mathcal{Q}}[R(q \mid m)] - \lambda\,\lvert m\rvert$, where $m$ is the retained note set, $\mathcal{Q}$ the distribution of future queries, and $\lambda$ a token/maintenance penalty — would make the "over-logging hurts" finding fall out of the $\lambda\lvert m\rvert$ term rather than being purely observed.
    • A capability–guidance interaction model: the inverse relationship between rule rigidity and gain (strong models lose most from prescriptive rules) is presented as an empirical regularity with no mechanism or bound on when it flips.
    • No variance / stability characterization of dreaming: how many dreaming passes are needed, and whether repeated passes converge or can degrade (the article shows one case where a wiki grew larger than its 115 KB source to 203 KB and became net-negative — evidence that the process is not monotone, but this is not formalized).

    Given the absence of formalism, the load-bearing evidence is the §5 data, which must be read as association, not guarantee.

    5. 实验与数据 (Experiments & Data) #

    CL-Bench 1.0 — memory delta scales with (but is not monotone in) capability #

    ModelBaseline+MemoryΔ
    Opus 5.50.6550.838+0.183
    Sonnet 5.50.6440.833+0.189
    Opus 50.5640.828+0.264
    Opus 4.70.3830.700+0.317
    Sonnet 50.3060.610+0.304
    Sonnet 4.60.3300.364+0.034

    The weakest model (Sonnet 4.6) barely moves (+0.034) — it read memory files <50% of the time and generated untested theories. Mid-tier models show the largest absolute lift because they have headroom and the behavioral discipline to use notes (Sonnet 5 independently read memory 9/10 times, marked confirmed answers, wrote corrections). Top models start high and still gain. The takeaway is not "memory helps proportionally to capability" but "memory requires a minimum capability threshold to pay off at all."

    Steering: refined instructions vs. prescriptive rules #

    ConditionMean Reward
    Sonnet 4.6 baseline0.330
    Sonnet 4.6 + memory + refined instructions0.641
    Opus 4.7 + memory0.700
    Opus 5 + memory0.828

    Refined, task-specific instructions nearly doubled the weak model's reward (0.330 → 0.641) — more than generic memory alone delivered. Yet the rule "record only failures" subtracted value, and subtracted it most from the strongest model:

    ModelLoss from "record only failures"
    Opus 5−0.234
    Opus 4.7−0.150
    Sonnet 4.6−0.020

    This is the sharpest single result: rigidity is a tax that scales with the model's own judgment. Guidance > rules, increasingly so at the frontier.

    Salience in the wild — Pokémon Red #

    MetricSonnet 3.7Fable 5
    Memory files41310
    Folders2252
    Total characters977,93043,406
    Badges earned14

    A ~22× smaller memory footprint produced 4× the game progress. Fable 5 stored only off-screen strategic knowledge (global.md dashboard, locations/ nav plans, gameplay/ learned rules like varying catch timing after failures) and ignored redundant state the game already displayed. Volume is anti-correlated with usefulness here.

    Dreaming as error correction — Mt. Moon #

    ConditionLedge fallsReached Cerulean
    Raw memory (uncorrected)3No
    Memory + dreaming0Yes
    No memory—No

    A single false note (wrong PokéCenter location) caused repeated failures; raw memory was worse than useful until dreaming cross-referenced the transcript and repaired it. This is the clearest demonstration that an unverified upper layer is a liability, and that the downward-reading dreaming edge is what makes the hierarchy safe.

    Representations — wiki vs. search (Stainless, 350k files / 420M tokens, 25 Qs) #

    Condition% Criteria Met
    Wiki alone — 2 dreaming sessions13%
    Wiki alone — 128 dreaming sessions48%
    Wiki + search (early)54%
    Wiki + search (mature wiki)61%
    Search tool only53% (flat)

    Search-only is a flat baseline (53%) that does not improve with time; the wiki grows (103 pages/766 links → 222 pages/12,893 links over 2→128 dreaming passes) and, combined with search, overtakes it while saving ~20k tokens/question. But the advantage is task-dependent: on Harvey LAB Merger Questions (multi-doc synthesis) wiki hit 87% vs. 73% search; on LAB Brief Generation (single-doc retrieval) wiki showed no advantage, and one LAB task produced a 203 KB wiki over a 115 KB corpus — abstraction failure.

    6. 论证链 (Argument Chain) #

    #ClaimSupport within the article
    1Memory is a prediction problem, not a storage problem.Notes are written now for an unknowable future session; the human hippocampus→neocortex consolidation metaphor frames it.
    2Therefore salience (what to keep) dominates capacity (how much to keep).Pokémon Red: 22× less memory, 4× more badges; over-logging created maintenance overhead as state changed.
    3Salience quality rises with model capability.CL-Bench: weak model gains +0.034 and reads memory <50% of the time; stronger models gain 0.18–0.32 and exhibit confirm/correct behaviors.
    4Capable models want guidance, not rules."Record only failures" costs Opus 5 −0.234 but Sonnet 4.6 only −0.020; refined instructions nearly double the weak model.
    5Unverified upper layers are a liability without a correction mechanism.Mt. Moon: one false note → 3 ledge falls and task failure under raw memory.
    6Dreaming supplies that mechanism by reading downward against transcripts.Mt. Moon with dreaming: 0 ledge falls, task completed; wikis repair dead links and fill gaps across passes.
    7Structured representations beat flat search only when tasks need cross-document synthesis.Merger (synthesis) 87% vs 73%; Brief (single-doc) no advantage; one wiki exceeded its corpus and became net-negative.

    7. 实现 cross-reference (Implementation) #

    [实现未公开] — the article is a research narrative; CL-Bench 1.0, the Harvey LAB tasks, the Stainless corpus harness, and the dreaming scheduler are described but not released as code. The one concrete, inspectable implementation referenced is Claude Code auto-memory, which operationalizes the injected context layer:

    • Loads the first 200 lines or 25 KB of MEMORY.md at session start.
    • Treats that file as an index that points Claude to where fuller knowledge lives, rather than inlining the knowledge itself — directly addressing the injected-context trade-off ("injected memories use up valuable tokens, and an incorrect note can be carried into every session").

    核心技术壁垒 (reprise): the replicable parts — a four-tier store, a wiki, a MEMORY.md index, a nightly consolidation job — are all straightforward. What does not transfer is the capability-calibrated self-direction: the finding that a frontier model, given loose guidance, writes better memory than the same pipeline driven by explicit rules, and that this gap widens with model strength. Anyone reproducing this on a weaker base model will see the Sonnet-4.6 regime (+0.034, ignored files), not the Opus regime.

    关键实现细节 (easy-to-miss tricks):

    1. Index-not-inline injection. Claude Code loads MEMORY.md as a pointer index, not the knowledge body — this bounds the per-session token tax (25 KB cap) while keeping deep knowledge reachable. Naively injecting the full representation would both blow the budget and make every stale entry a recurring cost.
    2. Correction reads the original transcript, not the note. Dreaming's error-fixing power comes from cross-referencing against the raw transcript (ground truth), not from re-reading the possibly-wrong note. Skipping the transcript round-trip would let false memories self-reinforce — exactly the Mt. Moon failure mode.