Agent Memory Architecture: Offline Dreaming for Cross-Session Learning
This article explains how AI agents can build long-term, cross-session memory through an offline "dreaming" mechanism inspired by how the human brain consolidates memories during sleep. It covers the idea of sleep-time compute, defines what qualifies as agent memory, presents a four-layer memory hierarchy (raw records, memory notes, memory representation, and injected context), and describes how to tag, verify, and self-correct stored knowledge to form a closed learning loop. It also contrasts how different model generations learn over time and outlines engineering practices for storage tiering, retrieval, observability, privacy, and offline scheduling so teams can build a controllable, auditable long-term memory system for agents.
1. From the Human Brain to the Agent: Why Memory Needs “Offline Consolidation”
Humans encounter a massive stream of information every day, but only a small fraction actually makes it into long-term memory. A widely accepted explanation in neuroscience is that the hippocampus rapidly captures present-moment information while we are awake, forming a transient short-term buffer. During sleep and deep rest, the brain replays recent experiences and gradually integrates the content that has been repeatedly activated and deemed important into the cortex, turning it into stable long-term knowledge. The defining characteristic of this process is that it is offline: it does not happen during real-time interaction with the world, but in the gap after information input has stopped.
Transplanting this division of labor onto an AI agent raises a natural question. As an agent runs over long periods and interacts across many tasks, it likewise accumulates dense interaction logs and intermediate artifacts. How can these “experiences” be refined, corrected, and consolidated into reusable lessons? The answer is to let the model use the idle window between two rounds of real interaction to reflect on and reorganize its history offline.
2. Sleep-Time Compute: Using the Idle Capacity Between Interactions
Research in the field has proposed the concept of sleep-time compute. Its core claim is that a model does not have to spend all of its compute responding to user requests; instead, it can use the idle compute between two interactions to reorganize existing context—reflecting on the past, correcting errors, and writing supplementary notes. This offline processing stage is often described as “dreaming.”
The difference from a conventional “instant response” approach lies in the time dimension:
- Instant response: online, focused on the current request, optimized for low latency.
- Offline dreaming: offline, oriented toward the past and the future, optimized for the accuracy and reusability of memory.
Because the two are decoupled, this approach neither slows down the response speed users perceive nor sacrifices continuous improvement in memory quality.
3. Drawing the Boundary: What Counts as Agent Memory
Before discussing agent memory, it is important to define its scope clearly, otherwise it is easy to confuse it with neighboring concepts. Here, memory specifically refers to the experience an agent gains while interacting with tasks and users—experience that can persist across sessions and be read by later sessions in the form of plain-text context. It strictly excludes three things:
- Changes to model weights — memory does not modify parameters and involves no retraining or fine-tuning.
- In-context learning within a single conversation — valid only for the current session and gone once the session ends.
- Context replacement that compresses an old conversation into a summary — substituting a summary for the original text is lossy compression, not experience consolidation.
These three boundaries matter. They mean that agent memory is an external, readable and writable text knowledge base that sits outside the model, and is therefore inherently controllable, auditable, and rollback-able.
4. Memory Hierarchy: From Raw Records to Injected Context
A complete cross-session memory system can usually be divided into four layers, from bottom to top:
- Raw records — complete logs produced during interaction, with the highest fidelity but high noise and rapid growth in volume.
- Memory notes — key observations distilled from the logs, classified as rules, facts, or hypotheses.
- Memory representation — stable knowledge formed by further integrating, deduplicating, and structuring the notes.
- Injected context — the available knowledge retrieved on demand and injected into the model at the start of the next session.
The “dreaming” mechanism runs through all of these layers: it reads the underlying raw records, settles downward into notes and representations, and ultimately shapes what gets injected next time—producing a progressive refinement from “raw experience” to “usable knowledge.”
5. Tagging Memory: Simulating Emotional Marking
In the human brain, emotional or chemical signals “tag” memories at critical moments, causing them to be replayed more often during sleep and thus preferentially consolidated. Agents have a similar capability: they can actively mark events they consider important during a session, or write them into an external memory folder.
This raises a real and difficult question: how can an agent predict whether what is happening now will matter in the future? A pragmatic approach is to have the agent explicitly output confidence and reusability judgments, turning the “worth remembering” decision from something implicit into something explicit and observable:
// Illustrative structure of a memory note{"type": "rule | fact | hypothesis", // rule / fact / hypothesis"content": "Verify session permissions before querying orders, then look up the table","confidence": "verified | unverified", // verified / unverified"reusable": true, // whether it can be reused"source_session": "session-id","timestamp": "write-time"}
6. Memory as a Prediction About the Future: Forming a Learning Loop
Looking one level deeper, taking notes is itself a kind of prediction about the future. When an agent writes down a rule, it is essentially predicting “this rule will be useful again later”; when it records a verified truth, it is predicting “when my future self calls on it, I won’t have to re-verify it.” A good memory system therefore needs to close the loop:
Predict → Record → Later invocation → Feedback (verify or falsify) → Correct the memory.
The dreaming stage is exactly the offline execution step of this loop, illustrated as follows:
def offline_dreaming(history, memory_store):for session in history:for event in session.key_events:if event.verified and event.reusable:memory_store.deposit(event) # Consolidate verified experienceelse:memory_store.mark_as_hypothesis(event) # Stash as pending verificationif event.corrected_prior_conclusion:memory_store.correct(event.old_conclusion, event.new_conclusion)memory_store.restructure() # Merge duplicates, prune redundancy, update representations
7. Comparing Learning Shapes Through an Evaluation Task
To observe how different memory capabilities behave, one can design a long-horizon memory evaluation task with closed-loop feedback. A typical form is database table-lookup Q&A: the agent must look up data in a database table to answer a series of questions. After each answer, the system reveals the correct one, and the agent can write what it learned into a memory directory for reuse in later sessions. Under this setup, one can compare the cumulative performance of a stateless baseline (starting from scratch each time) against memory storage (able to read historical notes).
Interestingly, models from different generations often display completely different “learning shapes”:
- Earlier versions: produce more unverified guesses, with fragmentary and mutually contradictory theories scattered across the memory directory, making them hard to reuse.
- Newer versions: begin consolidating notes into a single reference document, clearly separating “confirmed” from “unconfirmed” details, with cumulative gains rising steadily as the number of sessions grows.
This comparison shows that merely being “able to write memory” is not enough. Whether the agent can verify, integrate, and self-correct is the true dividing line for long-term memory quality.
8. Engineering Implementation
To bring this mechanism into production, focus on the following:
- Storage tiering — use object storage for the highest-volume raw records, and structured storage to manage memory notes and representations, keeping read/write costs under control.
- Retrieval strategy — retrieve on demand when injecting context (rather than stuffing everything in), balancing hit rate against the context budget.
- Observability and governance — use logging services and monitoring alerts to track memory write volume, hit rate, and correction count; version memory changes; and support auditing and rollback.
- Privacy and security — filter sensitive information and enforce access control on memory content to prevent cross-session leakage.
- Offline scheduling — run “dreaming” on the idle compute between interactions, decoupled from online requests, so it never slows down response latency.
These capabilities can be supported by general cloud infrastructure, such as object storage, message queues, container platforms, logging services, and monitoring alerts (Baidu AI Cloud provides corresponding general-purpose capabilities as well). With these building blocks, organizations can assemble their own controllable, auditable long-term memory system for agents.
9. Summary
The essence of offline “dreaming” is to turn “memory” from a vague metaphor into an engineering mechanism that can be tiered, written to, verified, and corrected. When idle, the model replays and reorganizes its history, consolidating scattered experiences into cross-session, reusable knowledge—much as the human brain consolidates memories during sleep. Whoever does a more solid job on verification and self-correction owns the higher-quality learning loop, and that is precisely the key step for most agents today as they move from “being able to remember” to “remembering correctly and remembering for the long term.”
