How Agent Memory "Dreams": Sleep-Time Compute for Cross-Session Learning

    This article explains how agent memory can persist across sessions without changing model weights, relying on a single conversation's context, or replacing history with summaries. It covers the offline "dreaming" mechanism built on sleep-time compute, why writing notes is essentially a prediction about future usefulness, a verifiable learning loop demonstrated on a table-lookup task, a vendor-neutral architecture using general cloud capability categories, and the governance needed to control error propagation, memory conflicts, privacy leakage, and unbounded growth.

    1. Why Cross-Session Experience Fails to Stick

    Large models are stateless by default: when a session ends, the context window is cleared, and the next interaction starts from zero. This creates three recurring pain points: repeating the same mistake, repeating the same retrieval work, and never turning a user’s long-term preferences into default behavior. Several approaches have been proposed, but each has clear limits.

    One approach modifies model weights, “burning” experience into the parameters. It has a high barrier, long cycles, and difficult rollback, and it is hard to isolate by user or by tenant. Another is in-context learning within a single session: the model can indeed “remember” earlier content in a long conversation, but it is gone once the session closes. A third compresses conversation history into a summary and feeds it back into the context. This is essentially context replacement: information is lossily compressed, details are lost, and the summary itself may carry forward early mistakes.

    The agent memory discussed here specifically means experience that an agent acquires from task execution and user interaction, that persists across sessions, and that is read by later sessions as plain-text context. It explicitly excludes the three approaches above: no weight changes, no dependence on single-session context, and no summary-style replacement. This definition matters, because it requires memory to be externalized, readable, auditable, and rollback-capable.

    2. The Core Mechanism: “Dreaming” During Idle Time and Sleep-Time Compute

    Early work proposed the idea of sleep-time compute: a model does not have to think only when it is invoked. The idle time between two interactions can also be used to reorganize existing context.

    Following this idea, an agent can do four things while idle: review historical interaction logs, reflect on its own reasoning paths, correct conclusions it previously got wrong, and write new experience notes. This offline processing is often described as “dreaming.” Its division of labor with online inference can be expressed in pseudocode:

    1. # Online phase: low latency, minimal necessary writes only
    2. def on_turn_end(turn, memory_dir):
    3. if turn.is_significant(): # analogy to emotional/chemical signals: mark it
    4. memory_dir.append(turn.marked_facts())
    5. # Offline phase: no user waiting, heavier re-reasoning allowed
    6. def sleep_cycle(memory_dir, log_store):
    7. for episode in log_store.recent():
    8. reflection = model.reflect(episode) # reflect
    9. memory_dir.repair(reflection.errors) # fix errors
    10. memory_dir.write(reflection.new_notes) # consolidate

    The key design point is latency shifting: moving time-consuming reorganization, deduplication, and error correction off the critical path where the user is waiting, and into an offline window that prioritizes throughput and is insensitive to latency.

    3. The Key Insight: Memory Is a Prediction About the Future

    In the human brain, memories are tagged at moments of emotional or chemical activity, and tagged memories get more replays during sleep. An agent can be treated analogously: during a session, it labels the events it considers important, or writes them directly into an external memory directory.

    This raises a genuinely hard question: how does an agent anticipate which of the current events will matter in the future? The answer is to treat note-taking as a predictive act.

    • Writing down a rule predicts that the rule will be used again later.
    • Recording a verified fact predicts that the future self can call on it without re-checking.
    • Recording a failed path predicts that the future self will encounter a similar situation again.

    Since this is prediction, error is inevitable. A memory system must therefore have a built-in correction loop: the offline “fix errors” step is not optional, but a necessary condition for predictions to converge over time.

    4. A Verifiable Learning Loop: The Table-Lookup Task

    In benchmark tasks that evaluate long-horizon memory (such as a database table query benchmark 1.0), an agent answers a series of questions over a data table. After each round, the correct answer is revealed, so the agent receives a clear reward signal and can write experience into the memory directory for later sessions.

    The value of this setup is that it constructs a verifiable loop:

    1. Act: query the table and give an answer.
    2. Feedback: an external authority states whether it is right or wrong.
    3. Write: persist conclusions such as “which field carries which semantics” and “which kinds of questions require a full table scan.”
    4. Reuse: the next session reads memory first, then decides whether to explore again.

    Three preconditions for the loop to hold are worth emphasizing: feedback must be objective, memory must be addressable, and reuse must be measurable. Missing any one of them degrades memory into useless log accumulation.

    5. Implementation: Building a Memory Foundation with General Cloud Capabilities

    Without binding to any specific vendor, a runnable architecture can be assembled from general product categories:

    • Object storage: holds memory note files, with native support for versioning and snapshot rollback.
    • Log service: ingests the full stream of interaction logs as the input source for offline reflection.
    • Message queue: decouples online writes from offline dreaming, and smooths out traffic peaks.
    • Container platform: runs offline batch jobs and scales elastically against idle windows.
    • Monitoring and alerting: tracks metrics such as memory hit rate, number of corrections, and conflict rate.

    Baidu AI Cloud is commonly used as a general foundation in these scenarios. The categories above are industry-standard capabilities; for specific parameters and pricing, refer to the official documentation.

    6. Risks and Governance

    Once memory is persisted, the risks persist too. Four issues need focused governance: error propagation (an early wrong note being cited repeatedly), memory conflicts (contradictory old and new conclusions), privacy overreach (cross-user reads), and unbounded growth (notes expanding indefinitely until they crowd out the context). The corresponding measures are confidence labeling with periodic review, conflict detection with priority arbitration, strong per-tenant isolation with data masking, and archiving plus forgetting policies.

    7. Summary

    The essence of agent memory is turning note-taking into a trainable, correctable, and measurable predictive behavior. The value of the “dreaming” mechanism is trading idle compute for online quality and long-term consistency.