Agent Memory Self-Correction: How the ReHarness "Look Back" Framework Works
This article explains why continually learning agents keep repeating the same mistakes when stale memories are retrieved, and how the ReHarness "look back" framework fixes this by revising the exact memory record that was used after a failed execution. It covers the root cause in the harness's forward-only read/write cycle, the core retrospective mechanism with pseudocode, the technical pain points it addresses, engineering practices for record granularity, trigger policies, conflict handling, state management, observability and storage isolation, plus evaluation metrics and known limitations.
1. The Problem: One Stale Memory, Repeated Failures
Picture a continually learning agent working through a series of sorting problems. The first task asks for descending order. The agent gets it right and leaves itself a note: “Put the larger numbers first.” The second task switches to ascending order. The agent retrieves that note, follows it, and arranges 2, 9, 5 as 9, 5, 2 — wrong. It then writes a new reflection, but the old memory is never modified. The third task happens to reuse the same three numbers from the first task, similarity retrieval hits “larger numbers first” again, the task still requires ascending order, and the same mistake occurs for the third time.
The key issue here is not that the model is “dumb.” It is the timing of memory reads and writes: after the error, the system only appended a new record and never went back to revise the record that was actually used. The same pattern holds in other settings. Three days ago, an agent wrote “query the users table first” into memory. Today the schema has changed, the user asks a similar question, and the old note is retrieved as usual. Logs may show why the agent chose that table at the time, and may even trace the query that executed successfully, but deciding whether that memory still holds today requires one extra step: checking whether the preconditions under which it was originally valid still exist.
2. Root Cause: The Harness Writes Forward and Reads Forward, With No Look-Back Step
The harness is the runtime layer outside the model, responsible for memory management, reflection generation, and prompt assembly. When the model weights are fixed, which old memories the same model can see at step t depends entirely on what the harness stored and what it retrieves at that step. The harness state at the beginning of step t is usually denoted hₜ.
Common industry implementations have only two forward-facing actions:
- Forward write: after a task ends, write the takeaway as a reflection and append it to the experience store.
- Forward read: when a new task arrives, retrieve the top k entries by similarity and inject them into the context.
Even when the experience store supports maintenance operations such as add, update, delete, and merge, most of these happen at the moment a new memory is written, not after an old memory has been used. This creates a structural gap: a record’s applicability conditions only surface when it is used again, and the system lacks a mechanism to go back and modify it at that moment. This is the essence of “the new note is written, but the old mistake remains.”
3. Core Idea: Change the Loop From Linear Appending to Looking Back
The “look back” framework (called ReHarness in the original, where Recurrent refers to this loop recurring across tasks) answers a very specific question: can an agent use later execution results to correct memories written earlier? Its approach triggers a retrospective step after a concrete use: if that use fails, it returns to the exact old record that retrieval matched and writes the new counterexample and boundary conditions back into that entry, rather than starting a new one.
Continuing with the sorting example: after the first ascending task fails, the framework goes back and rewrites the old note to “Put larger numbers first only when the order is descending.” When that note is retrieved again, the agent sees the version with full applicability conditions and avoids repeating the mistake. Illustrative pseudocode:
# Pseudocode: memory loop with look-backstate = harness.init()for task in tasks:hits = state.memory.retrieve(task.query, k=3) # forward readresult = agent.solve(task, context=hits)state.memory.forward_write(result.reflection) # forward write of new reflectionif not result.success:for rec in hits: # look back: revisit records that were usedstate.memory.revise(rec,add_condition=result.failure_context,add_counterexample=result.case,)state = harness.checkpoint(state) # state is rollback-able and auditable
4. Existing Technical Pain Points It Addresses
- Stale memories causing repeated failures: errors no longer disappear only when the old entry happens not to be retrieved; they are corrected in place at the point of use.
- A bloated reflection store with declining signal-to-noise: revision takes priority over appending, reducing how much near-duplicate entries crowd out top-k retrieval slots.
- Retrieval hits with no way to locate the invalidating precondition: applicability conditions and counterexamples are written into the original entry, so the boundary is visible on a hit.
- Wasted context budget: tokens go to “correct memories with conditions” instead of relying on piling up more reflections and hoping for luck.
- Lack of auditability: every revision is bound to a concrete use and failure context, making replay and accountability easier.
5. Engineering Implementation Notes
- Record granularity: a memory should contain four fields — trigger condition, action, expected effect, and failure counterexample — avoiding storage of a slogan-like conclusion only.
- Trigger policy: not every failure needs a look-back; thresholds can be set by task type, failure confidence, and retrieval hit rank to control write amplification.
- Conflict handling: when new and old conditions conflict, prefer narrowing the condition over outright deletion, preserving history for auditing.
- State management: harness state must support snapshots and rollback to prevent one bad revision from contaminating the entire task flow.
- Observability: bring retrieval hits, revision actions, and before/after revision text into logging services and monitoring alerts to form a traceable chain.
- Storage and isolation: the experience store can sit on general-purpose capabilities such as object storage or a database, isolated by tenant and task domain to avoid cross-domain contamination.
6. Evaluation and Boundaries
Evaluation should cover at least three categories of metrics: the recurrence rate of the same error, the number of task rounds needed to reach stable correctness, and retrieval hit rate together with context length. Boundaries to watch include: unreliable failure判定 leading to good memories being wrongly revised; high-frequency look-backs causing write amplification; and conditions written too narrowly, so the memory is almost never reused. A reasonable approach is to treat look-back as a controlled operation, paired with canary rollout and manual spot checks, validating in a controlled environment first before gradually loosening the degree of automation.
