Agent Harness Memory: Layered Architecture and Reconciliation Mechanisms
This article breaks down how an Agent Harness manages memory across four layers—raw trajectory, lessons, topic index, and working set—and explains why externalizing memory as plain text matters for auditability, versioning, and portability. It covers what is worth writing down, the cost of memory bloat, a reconciliation loop that keeps wrong entries from being reused, and why model judgment should decide content while rules only enforce format and limits.
Agent Harness Memory: Layered Architecture and Reconciliation Mechanisms
In agent engineering, the model itself is only the reasoning engine. What actually determines whether an agent stays stable over long-running tasks is the runtime framework wrapped around the model—commonly called the Agent Harness. It assembles context, schedules tools, executes commands, and manages session state. Among these responsibilities, the most underrated one, and the one that most affects long-term performance, is memory.
Memory here is not a “database plugin” bolted onto the model. It solves a very plain problem: when a conversation fills its window, when a process restarts, or when a task spans several days, which information must be kept, in what form, and who guarantees it is correct. This article breaks memory into four layers, discusses the responsibility boundary of each, and then gives engineering practices for write criteria, bloat control, and a reconciliation loop.
1. Why Memory Must Be External and Readable
The model’s context window is a limited and expensive resource. Pushing all history into the window has three direct consequences: the signal-to-noise ratio drops as key instructions get diluted by redundant content; cost and latency grow linearly with each turn; and behavior becomes non-reproducible, since the same input yields different results under histories of different lengths.
The mature approach is to externalize memory as plain text files on a file system. The value of this choice is not “storage is cheap” but three engineering properties:
- Auditable: a person can open the file directly and verify word by word what the model remembered, and locate the exact entry when something goes wrong.
- Versionable: text naturally fits version control and diff comparison, so the change history of memory itself becomes a debugging clue.
- Portable: it is not tied to any proprietary storage or interface, and can be carried across models, frameworks, and environments.
Once memory becomes “vectors inside a black box,” all of these capabilities are lost and the cost of correction rises exponentially.
2. The Four Memory Layers: From Raw Trajectory to Working Context
Layer 1: Raw Trajectory
The bottom layer is the raw record of every interaction: what the user said, what the model replied, which tools were called, what commands output. This layer is append-only and does no processing; its sole responsibility is to be queryable later. It is the factual baseline for all subsequent organizing work, equivalent to source vouchers in a ledger.
Layer 2: Lessons
One layer up are experience entries distilled from the trajectory, usually one entry per note, persisted as plain text such as Markdown and openable with any text editor. The key constraint here is atomicity: one note covers one thing, the title states the conclusion, and the body gives the minimum necessary context.
# Generate the config before index building, otherwise the build script silently skips the cache directory- Trigger scenario: incremental build output is empty- Diagnostic signal: the log shows "skip" rather than "error"- Resolution: run config generation first, then trigger the build
Layer 3: Topic Index (Index / Map)
Once notes accumulate to dozens or hundreds, retrieval cost exceeds reading cost. At that point they need to be aggregated by topic into a directory page—not a copy of the notes, but a map: one line per topic, pointing to the location of several notes plus a one-sentence summary. It makes “locate first, then read” possible and avoids repeatedly loading all notes into context.
Layer 4: Working Set
The top layer holds only a very small block, loaded automatically when a new session starts. A common practice is to set a hard cap—for example, only the first 200 lines or the first 25KB are read, and anything beyond that never enters the initial context. This layer is not “the most important memory repository” but “the hottest index plus the most frequent constraints”; its scarcity is exactly why it stays effective over time.
3. What to Write: Only What You Cannot See Next Time
There is a very useful test for whether a piece of information is worth writing: if the next session can find it by looking at the screen again or reading the code again, do not record it; only information that cannot be obtained by re-observing is worth persisting.
Typical categories worth recording:
- How to run things: the actual execution order of a command, required environment variables, prerequisite steps.
- Entry points: the real code entry, the source of configuration, where logs are written.
- Pitfalls encountered: branches that appear to succeed but are actually skipped, operations that only take effect in a specific order.
- External constraints: environment limits, permission boundaries, immutable legacy baggage.
Not worth recording: directory structure, function signatures, the current error message, probe results that can be re-fetched at any time. Writing this kind of information into memory means polluting a long-term asset with perishable data.
4. The Cost of Bloat: What a Controlled Experiment Showed
A cloud vendor ran a controlled comparison in a long-horizon agent capability evaluation: the model played the same old-school game for tens of hours continuously under two memory strategies. One strategy produced 413 memory files and roughly 978,000 characters, and much of the time was not spent advancing the task but on organizing, deduplicating, and reordering memory; the other strategy wrote only 10 files and got further in task progress.
This matches engineering intuition: organizing memory is a kind of “meta-work” that crowds out the real task budget. When the maintenance cost of a memory system exceeds the information benefit it provides, it becomes a liability. So the first principle of memory design is not “remember more” but maintenance cost low enough to be negligible.
5. Reconciliation: Making Sure Errors Are Always Found
The most easily overlooked problem is not “failing to remember” but “remembering wrong.” A note may already be wrong at the moment it is written, and every later session trusts it unconditionally, so the error is continuously amplified and reused, eventually showing up as the model reliably doing the same wrong thing.
The fix is to treat memory as a ledger that needs periodic reconciliation:
- Check back against the raw layer: compare the conclusions in layers 2 and 3 with the trajectories in layer 1, confirming every conclusion has factual support.
- Rewrite and delete: correct outdated conclusions, delete unsupported entries, and explicitly note why they became invalid.
- Merge duplicates: combine semantically similar entries into one, keeping the more complete context.
- Compress the working set: push the top layer back within the line/byte cap, keeping only the hottest information.
In agentic coding tools such as Claude Code, this action is implemented as an automated background organizing task (auto dream), typically triggered when “more than 24 hours have passed since the last organization” or “5 new sessions have accumulated,” whichever comes first. The point of this design is that reconciliation is periodic, automatic, and low-cost, rather than dependent on someone remembering to do it.
6. Where Judgment Belongs: Do Not Replace Model Judgment with Hard Rules
A counterintuitive but important conclusion: writing “what to record” as hard rules often works worse. In testing, mandating “record only failures” reduced the benefit by about 0.234 compared with no restriction at all; the best-performing approach simply told the model “there is an available memory directory here.”
The reason is that hard rules take away the model’s judgment: they make the model filter mechanically to stay compliant, missing information that does not fit the rule but is actually high value (for example, a key entry point or an environment constraint). By contrast, stating the fact that “a memory facility exists” lets the model weigh things itself, preserving autonomy and naturally producing sparse writes.
The engineering compromise is: use rules to constrain format and limits, and let the model decide content. Format, paths, and line caps can be mandated; what to write and which layer to write it to are left to the model.
7. Implementation Recommendations
- Each of the four layers has its own role; cross-layer duplication of content is forbidden, and the index holds only pointers and one-sentence summaries.
- Set a hard cap on the working layer and truncate at load time; better to have less that is accurate.
- Run a “re-observability” check before writing to filter out information visible on screen.
- Make reconciliation a scheduled task that outputs a change summary for manual spot checks.
- Put memory files under version control; every change is a review.
- If centralized storage or cross-instance sharing is needed, general cloud product categories such as object storage or logging services can carry it, but keep the file format neutral and exportable.
Conclusion
The hard part of memory engineering has never been “storing” but making sure whatever was written wrong will definitely be reconciled. Layering solves retrieval efficiency, plain text solves auditability, and the reconciliation loop is what solves correctness. With all three in place, an agent can maintain a low-noise, explainable, and continuously evolving memory state across long-running tasks.
