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
- Every remembered fact is a record: claim, source, date written, date last verified, status.
- Facts with an owner elsewhere (policy, prices, contacts) are re-fetched from that source when used, and memory only stores where to look.
- The audit is a plan of small steps, each with a check and evidence in the log.
- The context holds an index and the task; the rules sit at the end.
- Handoffs list decisions and supersessions explicitly.
- 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
Store facts as records, not sentences
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)Plan the weekly audit as checkable steps
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
- List all facts with a policy source (check: count matches the index)
- Fetch each source page (check: HTTP 200 and a saved copy)
- Compare each fact to its source (check: mismatch list written to audit.md)
- Mark mismatches superseded and write the new record (check: old record kept, new one dated)
- Report counts: checked, matched, changed, blocked
Load an index and the rules, not the whole folder
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 Item Tokens When loaded System prompt and rules 3500 Always, rules repeated at the end Tool definitions 9000 Always Notes index 1200 Always Topic files 6000 On demand Ticket thread 21000 Always Old tool results 0 Cleared after use Hand off decisions and supersessions
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.
Stamp every trace and every write with versions
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"]}Roll back the prompt, then clean what it wrote
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
- Effective harnesses for long-running agents (Anthropic) (opens in a new tab)ArticleFree
How a progress file and git history let each new session resume work.
- Effective context engineering for AI agents (Anthropic) (opens in a new tab)ArticleFree
Covers note-taking, compaction and keeping only the context a task needs.
- Memory tool (Claude API docs) (opens in a new tab)DocsFree
A file-directory memory the model reads and writes across sessions.
- Compaction (Claude docs) (opens in a new tab)DocsFree
What compaction does and how to steer what its summary keeps.
- Context Rot (Chroma research) (opens in a new tab)ArticleFree
Measurements of how answers degrade as input length grows.
- Lost in the Middle: How Language Models Use Long Contexts (opens in a new tab)PaperFree
Shows facts in the middle of long inputs are used less reliably than at the edges.
- Model deprecations (Claude docs) (opens in a new tab)DocsFree
Retirement dates and how to plan a migration off a pinned model.
- OWASP Top 10 for LLM Applications (opens in a new tab)StandardFree
Names prompt injection and related risks that apply to anything an agent saves.