Skip to content
mentoor

Agent memory that does not go stale

For engineers

Memory, planning, compaction and versioning for an agent that runs for weeks.

An agent that runs for weeks needs memory that carries a date, a source and a status, plus a plan, a handoff and a prompt version it can be audited against; otherwise yesterday's truth is quoted as today's.

The case

Brightline Logistics runs Relay, a support agent built on a Claude model through its own API harness. Relay triages customer tickets for freelancers who ship parcels, drafts replies and keeps notes for itself in a folder of Markdown files, because each session starts with an empty context window. It has worked for six weeks. On 2 December 2026 a customer is told that refunds are possible "within 30 days". Since 12 November the policy is 14 days. The old number sat in Relay's notes, the notes were loaded at the start of every session, and the model quoted them with full confidence.

Nobody changed the model. The fault is in how the memory, the plan, the context and the versions fit together. Five skills apply.

What failed, and where

Memory (agent-memory). The fact was written once, with no date, no source and no way to tell it had been replaced. A memory store has no sense of time. Search finds what is similar, not what is current. A fact needs a date, a source and a status such as current or superseded, and facts that come from a policy should be checked against the policy page before they are quoted.

Planning (agent-planning). A weekly audit was on the to-do list and marked done, but the run log showed that only 12 of 42 facts were looked at. A to-do list is a claim. Each step needs a check the agent can run, and the evidence goes next to the tick. When the policy page moved and the audit hit a 404, the agent should have re-planned: keep finished steps, mark the dependent ones blocked and ask for help, not carry on from memory.

Context budget (context-budget). The notes grew to about 38,000 tokens and were pasted in whole. The rule "never quote policy numbers from memory" sat in the middle of that pile, where long inputs are used least reliably. Load a short index, read topic files on demand, and put the rules that matter next to the current task.

Compaction and handoff (context-compaction). When a long session was summarised, the summary kept the old refund number and dropped the decision that replaced it. A handoff must carry the goal, the decisions with their reasons, the current state, open questions and what was superseded. Resolved noise goes. Superseded facts are named as superseded.

Versioning (llmops-versioning). Complaints could not be tied to anything. The trace had no prompt version, no model snapshot and no revision of the notes. When a prompt change later removed a rule, there was no staged rollout, and the bad version had already written wrong notes by the time it was switched back. Rolling back the prompt does not roll back what the agent wrote.

The working pattern

  1. Every remembered fact is a record: claim, source, date written, date last verified, status.
  2. Facts with an owner elsewhere (policy, prices, contacts) are re-fetched from that source when used, and memory only stores where to look.
  3. The audit is a plan of small steps, each with a check and evidence in the log.
  4. The context holds an index and the task; the rules sit at the end.
  5. Handoffs list decisions and supersessions explicitly.
  6. Every trace and every memory write is stamped with the prompt version, the model snapshot and the notes revision, so a bad version's writes can be found and reverted.

Before and after

Before: Refund window: 30 days, written in October, undated and unsourced, quoted in December.

After: Refund window: 14 days | source: policy page, section 4 | changed 2026-11-12 | verified 2026-12-01 | supersedes: 30 days (2026-10-03). Relay now knows when to doubt a line, and a person can see why.

What still goes wrong

  • A summary written by the model can itself be wrong, and then the wrong version is what the next session trusts.
  • An instruction hidden in a ticket can be saved as a "rule". Treat customer text as data, never as policy.
  • Deleting old notes without a record removes the evidence you need to find out what went wrong.
  • A tidy-looking to-do list can still be untrue. Read the run log, not the ticks.

The questions that follow ask you to work through this case: what to store, what to check, what to load, what to carry over, and what to stamp.

Steps

  1. Store facts as records, not sentences

    Skill: agent-memory

    Replace free-text notes with records that hold the claim, its source, the date written, the date last verified and a status. Policy facts are not trusted from memory: the record points to the policy page and the agent fetches it when it needs the number.

    Relay notes: before and after

    notes/refunds.md

    # Before- Refund window: 30 days# After- claim: Refund window is 14 days  source: policy page, section 4  written: 2026-11-12  verified: 2026-12-01  status: current  supersedes: 30 days (written 2026-10-03)
  2. Plan the weekly audit as checkable steps

    Skill: agent-planning

    Write the audit as steps that each end in a check Relay can run, with evidence in the log. If the policy page is unreachable, mark the dependent steps blocked, keep finished work and ask a person.

    Weekly memory audit

    Goal: Every policy fact in the notes matches its source

    1. List all facts with a policy source (check: count matches the index)
    2. Fetch each source page (check: HTTP 200 and a saved copy)
    3. Compare each fact to its source (check: mismatch list written to audit.md)
    4. Mark mismatches superseded and write the new record (check: old record kept, new one dated)
    5. Report counts: checked, matched, changed, blocked
  3. Load an index and the rules, not the whole folder

    Skill: context-budget

    At session start Relay loads a one-page index, the ticket and the rules. Topic files are read when a ticket needs them. The rules go last, next to the task, where they are used best.

    Context budget per session
    Planned tokens of a 200,000-token window
    ItemTokensWhen loaded
    System prompt and rules3500Always, rules repeated at the end
    Tool definitions9000Always
    Notes index1200Always
    Topic files6000On demand
    Ticket thread21000Always
    Old tool results0Cleared after use
  4. Hand off decisions and supersessions

    Skill: context-compaction

    When a session is compacted or restarted, the handoff states the goal, each decision with its reason, the current state, open questions, and every fact that was replaced. A summary that keeps a stale fact without saying it was replaced is worse than none.

    Handoff note, end of session 41

    Goal

    Keep Relay's policy facts correct while it triages tickets.

    Decisions

    Refund window is 14 days since 2026-11-12, so the 30-day record is superseded. Policy numbers are fetched, never quoted from notes.

    State

    Audit step 3 of 5 done; 30 of 42 facts compared.

    Open

    Policy page returned 404 for the shipping section; asked Mara in support.

  5. Stamp every trace and every write with versions

    Skill: llmops-versioning

    Each trace and each memory write carries the prompt version, the model snapshot and the notes revision. A complaint then points to a version, and a bad version's writes can be found and reverted.

    Trace line for one reply
    {  "ticket": "T-90412",  "prompt_version": "relay-v14",  "model": "dated snapshot id from the provider",  "notes_revision": "r212",  "memory_writes": ["refunds.md#r212"]}
  6. Roll back the prompt, then clean what it wrote

    Skill: llmops-versioning

    Switch the prompt version by configuration and keep the previous version ready. Then list every note written under the bad version, quarantine it and re-verify it. A rollback undoes the prompt; it does not undo saved facts or cached answers.

Skills this scenario uses

Where to study