Memory consolidation for AI agents, step by step
Storing memories is easy. Turning them into a few correct beliefs, and retiring the wrong ones, is the hard part.
Memory consolidation in AI is the step that turns an agent’s raw experience into durable knowledge. It groups related events, extracts what generalizes, retires what turned out to be wrong, and re-weights what matters. The word comes from neuroscience, and the analogy is useful if it’s handled carefully. This post covers what the biology does and doesn’t support, why consolidation is the hard part of agent memory, why it belongs offline, and what a real consolidation pass looks like, using output from our prototype.
What is memory consolidation in the brain?
In neuroscience, consolidation is the process that turns new, fragile memories into stable long-term ones, and sleep plays a large part in it. A widely cited review, Rasch and Born’s About Sleep’s Role in Memory (Physiological Reviews, 2013), sets out the leading account, the active system consolidation hypothesis:
- Two stores. New memories of facts and events are first encoded in a fast-learning store (the hippocampus) and gradually transferred to a slow-learning store for long-term storage (the neocortex). The review presents this two-stage design as a solution to the “stability-plasticity dilemma”: how a network can learn new patterns without overwriting old ones. Machine learning knows the same problem as catastrophic forgetting.
- Replay. During slow-wave sleep, newly encoded memories are reactivated again and again, and those reactivations help move them into long-term storage. In animal studies, neurons that fired in sequence during a task fire again in the same order during later sleep, at a much faster, time-compressed rate.
- Selection. Not everything is consolidated equally. The review reports that relevance to a person’s future plans was consistently found to favour sleep-dependent strengthening. Evidence that sleep favours emotional memories is mixed.
The review is also clear about what isn’t settled. The exact functions of sleep are still debated, and what decides whether a given memory gets consolidated during sleep is not well understood.
What does the analogy mean for AI, and what doesn’t it mean?
Three ideas carry over well to agent memory:
- Separate fast capture from slow integration. Record events cheaply as they happen, and do the expensive integration later.
- Integrate offline, when the system isn’t serving anyone.
- Be selective. Not every event deserves to become knowledge. What mattered, and what’s likely to matter again, should win.
What doesn’t carry over: a memory graph isn’t a hippocampus, a batch job isn’t sleep, and no part of the system dreams. The biology doesn’t support that link either: the review found “no convincing evidence for a direct link” between the memory reactivation recorded in neurons during sleep and the dreams people report. DawnLoop’s nightly agent is called the Dreamer. That’s a name, not a mechanism.
Why is consolidation the hard part?
Accumulation is easy. Appending an event to a log or embedding it into a vector index is one write, and storage is cheap. But a memory that only accumulates gets bigger without getting better.
Consolidation is where every hard decision lives:
- Generalizing. Six successful auth changes: is that a pattern or a coincidence? And what exactly is the rule?
- Resolving contradictions. This week’s failure contradicts last quarter’s belief. Does it overturn the belief, narrow it, or add an exception?
- Forgetting. What’s stale, and what’s just been unused for a while?
- Weighing. Which memories should win retrieval when ten of them are relevant?
Each of these can go wrong, and a wrong consolidation is worse than none. A bad generalization becomes a belief, and beliefs are retrieved with more authority than raw events. So the signal matters. If the only judge of what went well is the model that did the work, consolidation is a model grading its own homework. DawnLoop is designed to use outcome labels instead: tests that pass or fail, pull requests that merge or get reverted, builds that break. Those are facts from the world, not opinions.
Why do memory consolidation offline?
Memory work done during a request competes with the user for time. LangGraph’s memory overview describes the trade-off. Writing memories “in the hot path” makes them available right away, but the agent has to multitask. Writing them in the background “eliminates latency in the primary application” and keeps application logic separate from memory management.
Offline memory consolidation gets more than lower latency:
- It sees the whole day at once, so it can spot patterns that no single request reveals.
- It can wait for outcomes. A merge or a revert often lands hours after the work it judges.
- It can spend more compute per memory, including frontier-model time, because nobody is waiting.
- It can be checked before it’s committed, and undone afterwards.
Generative Agents (Park et al., 2023) is an early example of periodic consolidation in LLM agents. Its agents synthesized higher-level reflections whenever the importance of recent events crossed a threshold, which worked out to roughly two or three times a day. The broader idea of using idle time to think ahead is called sleep-time compute, which has its own post.
The four steps: Replay, Consolidate, Prune, Strengthen
DawnLoop’s nightly pass is designed as four steps. Our prototype implements a crude version of each:
- Replay. Re-walk the day’s episodes, joined to how they actually turned out. In the prototype: gather the last day’s episodes whose outcome is known, and count successes and failures.
- Consolidate. Extract what generalizes, and write it down with its evidence attached. In the prototype: group successful episodes by topic. With at least two on a topic, create a belief, or confirm an existing one (+0.05 confidence and a fresh last-confirmed time).
- Prune. Fade what’s gone stale, and retire what the day’s outcomes contradicted. In the prototype: a failed episode that matches a belief halves its confidence. Below a floor of 0.35, the belief is retired and replaced with a “contradiction” belief that records the lesson. Beliefs nobody confirms lose 2% of their confidence per day.
- Strengthen. Re-weight what mattered and what’s used often. In the prototype: recompute each node’s salience, a weighted score of outcome magnitude, access frequency, recency of confirmation and contradiction pressure. A failure carries 2.5 times the outcome magnitude of a success. More in Salience scoring for agent memory.
Every constant here was picked by hand. None of them has been tuned against anything yet.
A real nightly pass from our prototype
This is real output from the prototype’s deterministic demo: a synthetic scenario with a seeded day and one working day, where a script marks each outcome. Trimmed and wrapped for width:
Nightly pass — Track A (Replay → Consolidate → Prune → Strengthen)
Replay — 8 episodes joined to their outcomes (7 ok, 1 failed)
Consolidate — extract candidate beliefs from repeated success patterns
created belief 'Team auth work is repeatable and succeeds every time: Split auth
middleware out of the router; Consolidate the two auth token helpers; ...' (conf 0.92, 6 episodes)
Prune — decay unconfirmed beliefs, retire contradicted ones
decayed 'Team uses service objects, not fat models' to conf 0.69
contradicted 'Deploying directly to production via SSH is fine for small fixes'
by 'Deploy the auth changes straight to production' (conf 0.28)
retired 'Deploying directly to production via SSH is fine for small fixes' below conf floor
after contradiction
replaced with 'Team discourages ssh direct deploy: 'Deploy the auth changes straight to
production' caused a revert/incident and was rolled back.' (conf 0.5)
Strengthen — update salience weights from access and outcome magnitude
graph: 8 episodes, 3 beliefs
Three things happened, and each one shows something about why consolidation is hard.
The SSH belief was contradicted and retired. It was seeded at confidence 0.55, standing in for something learned from git history. Then a deploy straight to production failed and was rolled back. The pass halved the belief’s confidence to 0.28, below the 0.35 floor, so it was retired and replaced with a new belief that cites the failed deploy as its evidence. That’s the loop working as designed: an outcome from the world overturned a belief. But look at why it matched. The prototype’s contradiction check is a topic match plus a word overlap, and the shared word was “deploy”. The failed episode never mentioned SSH. The new lesson is plausible, but it was reached for a weak reason. A real system needs a much better test for “this evidence contradicts this belief”.
The auth belief is a crude concatenation. The prototype “consolidated” six successful auth episodes by gluing their titles together and declaring that the work “succeeds every time”. One of the six was a question, not a change, and the confidence went straight to the 0.92 cap. That’s an honest picture of the problem: grouping is easy, and writing the rule the group actually supports is the hard part.
The service-objects belief decayed even though the day supported it. One of the day’s episodes extracted billing logic into a service object, which is exactly what that belief says. But the prototype needs at least two successful episodes on a topic before it confirms anything, so the belief decayed from 0.7 to 0.69 instead. Blunt rules miss evidence.
None of this is a benchmark. It’s a wireframe that makes the mechanics, and their failure modes, concrete. The layers it reads from and writes to are described in Episodic vs semantic memory for AI agents, and decay and contradiction get a fuller treatment in Forgetting in AI memory.
Why does every consolidation pass need a rollback?
Consolidation is self-modification: the system rewrites what it believes. So the prototype appends every change its pass makes (create, update, retire, re-weight) to a journal, and reverting the journal undoes the whole pass in one operation:
Rollback — the nightly pass is fully reversible (one operation)
revert -> exact restore (2 beliefs, was 2)
re-apply -> 9 operations, graph back to 3 beliefs
“Exact restore” here means that every belief’s ID, confidence and contradiction count matches a snapshot taken before the pass. Re-running the pass then applies the same changes again.
This comes from a design principle in our repository’s AGENTS.md:
Nothing self-modifying ships without an eval gate, a shadow period, and a one-operation rollback.
Track A and Track B: graph consolidation vs weight distillation
Everything above is Track A: consolidation inside the memory graph. It’s designed so that no model weights are touched, which keeps every belief inspectable, correctable and deletable. Track A is planned, and it’s the product.
Track B is a separate idea: distilling each night’s consolidated knowledge into per-customer model weights. It’s a research bet. It ships only if it beats the graph-only version on a real evaluation, it never reaches anyone without a one-operation rollback, and it may never ship at all. Track A doesn’t depend on it. We keep the two separate on purpose, so that a buildable feature never waits on an open research problem.
Can AI learn while you sleep?
In a narrow, testable sense, yes, and that’s the only sense we mean. An agent’s memory can be updated overnight from the day’s outcomes, so the next morning it retrieves better-supported beliefs and fewer contradicted ones. That’s what DawnLoop is designed to do. Under Track A the model itself doesn’t change, nothing has shipped yet, and “dreaming” is a metaphor for an offline batch job. Whether the result beats simpler memory is something we intend to show with evaluations, not adjectives. For how consolidation compares with the other ways to give agents memory, see Long-term memory for AI agents.