Agent Memory Tiering and Periodic Reconciliation in Practice
Abstract: As agents run across multiple turns, sessions, and long autonomous tasks, memory organization often becomes a bottleneck before model capability does. This article presents a four-layer memory architecture that separates resident, working, archive, and external source-of-truth storage by visibility and lifecycle, a write policy that records only information that cannot be perceived in the next turn and leaves value judgments to the model, and a periodic reconciliation process that corrects, deduplicates, compresses, and relocates entries against external sources. It also covers capacity governance, retrieval design, common anti-patterns, and a minimal starting point for implementation.
1. Background: Memory Is Becoming the Main Cost of Agents
In engineering practice with intelligent coding tools and long-running autonomous agents, larger context windows have not translated linearly into better task completion. The reason is straightforward: across multi-turn conversations, cross-session continuation, and long autonomous execution, agents continuously produce information that needs to be retained. How that information is organized often becomes a bottleneck earlier than the model’s own capability.
A common failure mode is “memory bloat.” The agent writes every intermediate artifact into long-term storage, and hundreds of files containing close to a million words of notes pile up quickly. On the surface the information looks complete. In practice, retrieval hit rate drops, the proportion of noise rises, and every session start pays an extra cost for loading and organizing. More importantly, the agent spends a large share of its reasoning budget “organizing what it wrote itself,” which squeezes out the compute that should be advancing the task.
The contrasting approach is a “minimal memory” strategy: keep only a small number of high-value files and leave complexity at runtime rather than in storage. In comparative observations on similar long-running tasks, the version that wrote fewer files actually got further. This points to a counterintuitive conclusion: the value of memory does not depend on how much is stored, but on the marginal contribution of each unit of information to later decisions.
The design goal of a memory system, therefore, should not be “remember more,” but “store the right things at the right layer and the right granularity, and make sure those things are correct.”
2. A Four-Layer Memory Architecture Based on Visibility and Lifecycle
The core logic of tiering is that the higher a layer is, the hotter, smaller, and more automatic it is; the lower it is, the colder, larger, and more dependent on retrieval it is. Memory can be divided into four layers.
The first layer is the resident layer. Its capacity is very small and it is loaded automatically at the start of every new session, typically capped in engineering practice at around two hundred lines or twenty-five thousand bytes. This layer is not a knowledge base but an index and a set of conventions: where the project entry point is, how common commands are run, key conventions about directory structure, and pitfalls that must never be repeated. There is only one criterion for admission: information you would absolutely not recall in the next session without looking at the screen.
The second layer is the working layer. It holds the current task’s plan, completed items, hypotheses still to be verified, and tentative conclusions. Its lifecycle is bound to the task, and it is archived or discarded when the task ends. Redundancy is allowed here because this layer serves continuity within a short window.
The third layer is the archive layer. It contains detailed records split by topic or by time, including the full context of failed attempts, the reasoning behind rejected options, and notes on environment differences. This layer is not on the automatic loading path and is retrieved on demand only, so it can be relatively large.
The fourth layer is the external source-of-truth layer: code repositories, task tracking systems, logging services, monitoring and alerting data, documentation, and artifact repositories. Its defining property is that it is objective and replayable, and it is the only authoritative basis for judging whether the first three layers are wrong. If any memory entry conflicts with an external source of truth, the external source wins.
The engineering value of tiering is that it decouples loading cost from total information volume: the resident layer keeps startup cost constant, the archive layer absorbs unbounded history, and the external source-of-truth layer carries the fact-checking responsibility.
3. Write Policy: Record Only What Is Invisible, and Give the Decision Back to the Model
Writes to the first layer must be extremely restrained. Content visible on the screen does not need to be remembered: the currently open file, the error stack, a directory listing, command output. All of it will be perceived again in the next turn. What needs to be remembered is what cannot be perceived: which environment variable a command requires in order to run, where a debugging entry point hides in a non-obvious location, what kind of regression a certain class of change has historically caused.
The second most common mistake is replacing judgment with hard rules, for example mandating “record only failures.” The problem with such hard constraints is that they take the value judgment away from the model. What the model needs to judge is whether a piece of information has marginal value for later decisions, not whether it belongs to success or failure. In related comparative tests, the group using a hard write rule actually saw its gain drop by about 0.234, while the group that was merely told “a usable memory directory exists here” performed best. The conclusion: providing the mechanism and the location, and leaving the decision of what to write to the model, works better than any static rule set.
A practical write flow looks like this:
if the information cannot be directly perceived in the next turn:if the information would change a specific later action:write it to the corresponding layerelse:discard itelse:do not write
Note that there is no branch for “type of information” here, only two dimensions: perceptibility and whether it changes an action. This is exactly what giving the decision back to the model looks like in practice.
4. Periodic Reconciliation: Making Wrong Memory Get Fixed Inevitably
The most easily overlooked risk in memory is not recording too little but recording wrongly. A note may already be inaccurate at the moment it is written: a command later changed its parameters, an entry file was refactored, or a supposed “pitfall” has actually been fixed upstream. The problem is that every later session trusts that note unconditionally, so the error is continuously amplified and produces no error signal at all.
Reconciliation is therefore not optional but a necessary component of a memory system. It does four things:
- Correction: compare entries in the resident and working layers one by one against external sources of truth, and delete or fix content that is no longer valid.
- Deduplication: merge semantically duplicate entries and keep the most accurately worded one.
- Compression: push an inflated resident layer back within its capacity threshold, sinking the evicted content to the archive layer rather than deleting it outright.
- Repositioning: move entries that relate only to historical tasks out of the resident layer, and promote archive entries that are repeatedly retrieved.
A dual threshold of “time plus frequency” is a reasonable trigger, for example running once after roughly twenty-four hours and about five cumulative sessions. This avoids high-frequency reconciliation eating into the task budget, and also avoids long stretches without reconciliation letting errors settle. In intelligent coding tool scenarios, this kind of background organizing is usually implemented as a low-priority self-maintenance task.
The reconciliation process itself must leave a trace: which entries were modified, the basis for each modification (pointing to a specific location in an external source of truth), and which entries were sunk. Modifications without a basis are not allowed, otherwise reconciliation degrades into another round of unconstrained writing.
5. Capacity Governance and Retrieval Design
The capacity threshold of the resident layer should be treated as a hard constraint, not a suggested value. Exceeding the line or byte limit means the write policy has failed, and compression should be triggered immediately rather than the threshold being relaxed. In practice, “segmented loading” can be used as a transitional measure, but segmentation only delays the problem and cannot replace tiering.
Three principles are recommended on the retrieval side. First, go narrow before wide: query the resident and working layers first, and only enter the archive layer on a miss. Second, retrieval results must carry their source and a timestamp so that staleness can be judged. Third, when an external source of truth is hit, overwrite the memory content with the external content directly instead of concatenating the two and handing both to the model, which avoids contradictory information entering the context at the same time.
If cloud capabilities are used to carry memory, a general category combination works: object storage for archive layer files, logging and monitoring and alerting services to retain execution sources of truth, a message queue to drive asynchronous triggering of reconciliation tasks, and a container platform to host periodic self-maintenance jobs. Baidu AI Cloud offers corresponding capabilities in these general categories; the specific selection should be evaluated against data scale and compliance requirements.
6. Common Anti-Patterns
- Using the resident layer as a log, so every session start pays a high loading cost;
- Replacing value judgment with static rules, taking away the model’s judgment and lowering overall gain;
- Writing without ever reconciling, so wrong entries are trusted indefinitely;
- Rewriting without a basis during reconciliation, turning correction into a new source of noise;
- Concatenating instead of overwriting when memory conflicts with an external source of truth, leaving the context self-contradictory;
- Letting the archive layer grow without bound and without topic segmentation, so retrieval hit rate keeps decaying.
7. Conclusion
The hard part of agent memory engineering has never been “can it store enough” but “does it err less and get corrected faster.” The four-layer architecture resolves the tension between loading cost and total information volume, the write policy addresses signal-to-noise ratio, and the reconciliation mechanism addresses trustworthiness. Missing any one of the three turns memory from an asset into a liability. For implementation, start with two minimal things: set a non-negotiable capacity ceiling for the resident layer, and give the memory directory a periodic reconciliation task driven by a dual time-and-frequency threshold. Once those two steps are done, refine the tiering and retrieval strategy gradually, which yields the most certain returns.
