Memory Engineering: Six Pillars for Self-Improving AI Agents
This article outlines a six-part memory engineering framework—write, categorize, recall, reflect, forget, and review—that enables AI agents to improve daily, contrasting structured memory with raw conversation logs and citing research from Stanford, Google, NVIDIA, and Anthropic.
Introduction: Why Memory Engineering Matters
Stanford University and Google equipped 25 AI agents with memory and placed them in a simulated town. One agent decided to throw a Valentine's Day party; invitations spread autonomously, and five agents showed up at the right time and place without any scripted behavior. In contrast, typical agents repeat mistakes you corrected days earlier. The difference lies not in the model but in what gets written, read, and discarded.
Most developers enable memory and save everything, then wonder why the agent gets worse. This article explains how to configure memory so your agent becomes a little smarter every day.
30-Second Version: Six Components
Memory engineering has six parts; all six must work for the agent to truly improve:
Write : Save corrections, decisions, and outcomes—not full conversation transcripts.
Categorize : Store rules, facts, and events separately because they are retrieved differently.
Recall : Load only what the current task needs, selecting by recency, importance, and relevance.
Reflect : Periodically consolidate raw notes into a few rules.
Forget : New facts overwrite old ones; one-time notes expire.
Review : A human reads the memory weekly because a single wrong line can be repeated forever.
Skip writing and the agent learns nothing; skip forgetting and it learns the wrong things; skip review and it confidently learns the wrong things.
What Research Shows Memory Can Do
Stacking Memory Isn't Enough
In the Stanford town, each agent maintained a memory stream of everything it saw with timestamps. What made the system work were two additional mechanisms: retrieval scored each memory by recency, importance, and relevance; reflection let agents pause, ask what their memories implied, and save the answer as a new memory. In the paper's evaluation, the full system was most convincing; removing reflection, planning, or memory degraded performance each time.
Writing Down Failures Beats Retrying
Reflexion makes an agent write a brief note after each failed attempt and read it before the next try. On the HumanEval coding benchmark, it achieved 91% pass@1 versus 80% for GPT-4 alone.
Saving What Works Compounds
Voyager, a Minecraft agent developed by NVIDIA, saves every successful code snippet as a skill in a skill library for reuse. Compared to an agent without a skill library, it collected 3.3× more unique items and reached key tech-tree milestones up to 15.3× faster.
Memory Works Best Paired with Forgetting
When Anthropic released a memory tool for Claude, they simultaneously shipped context editing to remove stale tool results. In Anthropic's own agent tests, memory plus context editing improved performance by 39% over baseline; in a 100-turn web search task, context editing cut token usage by 84%.
These four studies reveal a pattern: memory only adds value when it is concise, categorized, and continuously rewritten; an ever-growing chat log backfires.
Write Experience, Not Transcripts
The default is to save everything, which is the first mistake. Yesterday's transcript may be thousands of tokens; the agent must re-read it to find the one sentence that matters.
What's worth writing is short and reusable:
A correction: "Client A requires prices without VAT."
A decision: "We stopped using the old CRM on Nov 3."
A preference: "Reports use bullet points, never tables."
An outcome: "Emails with numbers in the subject line doubled reply rates."
Record it the moment it happens, one line per entry, in the agent's own file—not in a weekend summary. Rule: if it won't change what the agent does next time, don't write it.
Categorize: Rules, Facts, and Events in Separate Stores
Princeton researchers in the CoALA paper divided agent memory into the same categories as human memory:
Working memory : what's currently in context.
Episodic memory : what happened, when, and who was involved.
Semantic memory : facts about the world, users, and clients.
Procedural memory : how to do things, including rules and skills.
Each category is read differently: rules load on every task, facts are looked up when needed, events are searched only when the task requires a specific date. Mixing them forces the agent to re-read 300 lines of old events to find the five rules it actually needs.
UC Berkeley's MemGPT takes this further: context is RAM, everything else is disk, and the agent decides what to page in and out. Rule: rules at the top and always loaded; facts in a queryable store; events stored separately and searched only when necessary.
Recall: Load Only What the Current Task Needs
If the agent can't find a memory at the right moment, it doesn't exist; if it reads a memory at the wrong moment, it's noise. Stanford's agents score each memory on three dimensions before retrieval. You don't need the exact formula to use the idea:
Recency : this week's notes beat last quarter's.
Importance : a client complaint beats a typo.
Relevance : notes tagged by client, project, or task—only matching tags are loaded.
The third dimension does most of the work; it prevents the agent from writing one client's details into another's email. Rule: load memory by tag, not by default; let the task decide what the agent needs to remember.
Reflect: Turn Notes into Rules
Twenty notes saying the same thing are worth less than one rule. Daily or every few tasks, the agent re-reads new notes and answers: "What should I do differently from now on?" The answer goes into rules; the source notes are archived. This step is what actually makes the agent smarter: it turns "client complained about tables three times" into "reports should use bullet points." Rule: notes are raw material; rules are memory.
Forget: Newest Facts Win
An agent that never forgets will confidently quote last month's price. Three forgetting mechanisms cover almost every case:
Overwrite : new fact replaces old fact; the old one doesn't sit alongside it.
Expire : one-time task notes are dated and disappear after the date.
Archive : rules unused for 30 days move out of the always-loaded file.
Rule: every fact occupies exactly one line; newest version wins.
Review: A Human Reads Memory Weekly
Memory makes an agent's mistakes permanent—a risk rarely mentioned when enabling memory. A single wrong line, a misread instruction, a joke taken seriously, or a line copied from someone else's document can cause the agent to repeat it in every task thereafter. That's why ChatGPT lets you view and delete what it remembers, and why readable memory files beat opaque ones.
Ten minutes a week is enough: read the rules top to bottom, delete errors, merge duplicates. Rule: if no one reads the memory, no one knows what the agent learned.
Full Example: An Email Agent Over Four Weeks
Assume you run an agent that writes follow-up emails to prospects.
The default version has memory on, saves every conversation, never organizes or deletes. By week four it has ~300 notes, loads all of them for every email, and you're still correcting the same issues: wrong sign-off, prices with VAT, overly long emails, following up on closed deals, outdated Calendly links.
The memory-engineered version:
Write : only corrections and outcomes, one line each—300 notes reduced to 41.
Categorize : 12 rules at the top, facts filed by client, the rest in a dated log.
Recall : each email loads only rules plus facts tagged with that prospect's company.
Reflect : every Friday, distill the week's log lines into at most three rules (e.g., "too long" appears three times → "keep under 90 words").
Forget : new Calendly link overwrites old one; closed deals expire.
Review : Monday morning, ten minutes reading rules.
Weekly corrections dropped from 14 to 9 to 4 to 1. Same agent, same model—just remembering less, and remembering better.
File: MEMORY.md
Give this to any agent that can read and write files; only the bracketed parts need customization:
RULES (always loaded, max 20 lines): [how I work and what I never do] FACTS (one per line, newest first): [client or project | fact | date] LOG (search only when needed): [date | task | what happened | how I'll improve] WRITE: after every correction, decision, or result, immediately add one line NEVER WRITE: transcripts, chit-chat, anything that won't affect the next task RECALL: rules + facts tagged with this task's [client / project]; view log only when asked REFLECT: every [Friday], consolidate new log lines into at most [3] rules, then archive those log lines FORGET: overwrite facts in place; one-time notes expire after [7] days; rules unused for [30] days archived REVIEW: every [Monday] a human reads rules top to bottom and deletes errors
The 20-line limit on RULES is the most important rule; an ever-growing rule file eventually turns back into a chat log.
Which Part of Your Memory Is Missing?
When an agent stops getting smarter, the symptom tells you exactly which component is broken:
Repeats the error you fixed Friday → Write failed; the correction was never saved.
Loads 300 notes to send one email → Categorization failed; rules and events are piled together.
Pulls the wrong client's profile → Recall failed; notes lack tags.
Same note appears 20 times but never becomes a rule → Reflection failed.
Confidently quotes last month's price → Forgetting failed; old fact never overwritten.
Weird habit appears and won't go away → Review failed; no human reads the memory.
Six symptoms, six components—and a larger context window fixes none of them.
Mistakes That Make Memory Useless
Thinking "enable memory" equals memory engineering : the toggle only decides whether to save, not what, where, or for how long.
Saving full chat transcripts : the one sentence that matters is buried in thousands of tokens the agent must re-read every time.
Agent writes rules but no one reviews them : unreviewed rules drift, and a drifted rule gets executed more faithfully than any prompt you give.
All clients share one memory : without tags, one client's memory leaks into the next client's email.
Never deleting anything : Anthropic shipped context editing alongside the memory tool for a reason—forgetting is half the system.
Treating the context window as memory : a million-token window is a desktop, not a filing cabinet, and the desktop wipes clean tomorrow.
Start Tonight
Create MEMORY.md with three headings: RULES, FACTS, LOG.
Review last week's chats; write down everything you corrected more than once—those are your initial rules.
Tell the agent: after every correction, add one line; never write summaries.
Set a Friday reflection step: new log lines become at most three rules.
Monday morning, read the rules and delete at least one.
Then count how many corrections you need next week.
P.S. Agents don't get smarter by remembering more; they get smarter by remembering less, more accurately.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
