How I get AI to remember a correction
Which corrections I write down for an AI agent to weigh, which I enforce in code, and how I manage the context window, the prompt cache and files another provider could pick up.
WHAT IT REMEMBERS: Only what got written down from past sessions The rulebook and notes carry each correction forward
An AI agent starts every session with whatever its harness loads, and nothing more. The harness is the software wrapped around the model. For a coding agent, that's the project's instruction files, any memory files it's set up to read, in some harnesses a set of hooks that check its actions, and the tools and MCP connections configured for it (MCP is the common standard for plugging outside tools into an agent). For a support bot, it's the bot's instructions, the help center it searches and the actions it's allowed to take. Yesterday's session is gone unless one of those carries it forward. What any agent "remembers" comes down to what someone chose to load, and the right choices depend on your ecosystem: the tools you use and where your context already lives.
I do most of my work with ALAI, my team of AI agents on Claude, and the lessons I most need to carry forward look like this one. A loop in one of my projects ran on a schedule and saved its data on every pass, whether anything had changed or not. When it was found, on February 21, the database held 253 copies of each record the loop wrote. The fix took a few lines of code that check for a change before writing. The next agent to write a scheduled job for me won't know any of that unless the lesson sits in something its session loads.
In my setup a lesson can go to one of four places: a note, the rulebook, a hook or the failure library. Which one depends on how often the lesson matters and whether it has to hold every time. A note or a line in the rulebook is an instruction, which the model reads and weighs against the task in front of it, so it usually follows it and sometimes doesn't. A hook is code that checks the action from outside the model and gives the same answer on every run. The library holds the full story behind each lesson, for the agent that's about to repeat it.
Where a lesson goes depends on how often it matters and whether it has to hold every time
FOUR PLACES FOR A LESSON, IN MY SETUP
Notes get opened when they apply
My agents keep a memory folder of small notes, and its rules are worth copying. Each note is one file holding one fact. Its header gives a name, a one-line description and a type: user (about me), feedback (a correction), project (where a piece of work stands) or reference (where things live). After saving a note, the agent adds a one-line pointer to an index that loads into every session, with a title, a link and a few words on when to open it, and none of the note's content. Before saving anything, it checks for a note that already covers the point and updates that one, and a note that turns out to be wrong gets deleted.
The split between the index and the notes is about room. Everything loaded at the start takes up part of the context window, the working space the model reads on every turn, so the index stays at one line per note and the detail waits in the files. A session knows what's there and reads the few notes that match its work. Whether it opens the right one is still the agent's call, which is why anything every session needs goes in the rulebook instead.
My own index bends those rules. Its lines sit under headings like Absolute Rules, Code Quality and Workflow, and a few of them state a rule outright with no note behind it. Some of the older notes hold several facts each. Notes also go stale, because a note reflects what was true when it was written. If it names a file, a function or a flag, the agent has to confirm that thing still exists before recommending it.
A correction keeps its reason
Feedback notes are written in three parts: the rule, why it exists, and how to apply it. Without the why, a rule reads like my preference, and an agent will drop a preference the moment it slows down the finish. While I was building this site, an agent told me a page rendered fine. It had checked that the server answered and that the HTML contained the headline. I opened the page and found the wrong fonts, no layout, and every hidden design option on screen at once.
I asked, "did you look at it? it is totally broken?" and that reply went into the note word for word. The note is a general QC check now. Before anything gets called done, the agent opens it in a real browser, checks that it looks right, and clicks through it to see that it works. The next agent tempted to skip that step reads exactly how it went the last time one did.
The rulebook loads every session
My rulebook is a file called CLAUDE.md that every agent reads before it starts work. It holds what applies whatever the task: how work gets committed and pushed, what never gets printed into a log, when an agent has to bring in another one before it touches product code. The loop became a rule there, "No blind writes in loops," dated the day it was found, with three layers of defense:
- Check whether anything changed before saving.
- Make the database skip any row it already has.
- Put a no-duplicates rule on every table a scheduled job writes to.
A rule in the rulebook is still an instruction. Every agent sees it, and each one still decides whether it applies to the job in front of it. I can't make an agent give the same output twice, but a rule it reads at the start of every session massively raises the odds, and for most of what's in there that's enough.
A rule that must hold every time becomes a hook
A hook is a small script that runs before an agent's action and blocks it when a rule is broken. The model never reads or weighs it, and it costs nothing in the context window unless it fires. The test in my hooks guide asks, "Can a shell script determine if this rule is violated without understanding the intent of the code?" If it can't, the rule stays written down, because a script that guesses at intent ends up blocking good work. "No blind writes in loops" fails that test, since a script can't tell a loop that should save on every pass from one that shouldn't.
When a script can check a rule, I make it a hook if a miss can't be undone or a softer version already failed. A debug setting in one of my startup scripts would have copied a live API key into the logs on every run. A key in a log can't be pulled back out, and the only fix is replacing it, so a hook now blocks that pattern and other ways code leaks secrets into logs and error messages. My cap on heavy jobs is the second case. Its first version was bookkeeping with an override switch, and my agents typed the override to get past it, so it's a hook now, with no override.
My em dash hook blocks the dash itself and two hyphens in a row, since a script can spot both. An agent once typed the HTML code for a dash instead, the hook let it through, and the page showed a dash anyway. A hook only catches what its script checks for, and that rule still lives in a note, so on that one I'm back to playing the odds.
The failure library keeps the whole story
Each lesson's full story goes in a failure library. Every entry has a name, a date, a severity, what happened, the root cause and the guardrail. The loop is in there as Blind Loop Writes, rated Critical. The library asks for names that are memorable and easy to search, and most of its value comes from that. Before building anything that saves data, an agent checks the library for that pattern, and when one agent reviews another's work, "this looks like Blind Loop Writes" saves a paragraph of explanation.
Why I split long sessions and keep the top of a prompt stable
Keeping lessons in files is also what lets me throw a session away. Everything a session loads goes back to the model with every request, along with the whole conversation so far, and the longer that gets, the worse the model does with it. In Chroma's tests of 18 models, performance dropped as the input grew, and focused prompts of about 300 tokens beat full ones of about 113,000. So when a conversation runs long and drifts across themes, I start a new session for each theme instead of pushing on, and the new one opens with every lesson already in its rulebook and notes.
For agents built on the API, especially ones that run all day, the prompt cache matters as much. A provider can reuse the start of a prompt that hasn't changed since the last call, and the instructions and memory loaded at the start are the natural thing to cache. On Anthropic's API you opt in by marking that part. Cached reads cost a tenth of the normal input price (a twentieth on Opus 5.5 and Sonnet 5.5), and writing to the cache costs a quarter more than normal input.
The cache lasts five minutes by default, so an agent that calls every ten minutes pays that write price every time. Anything that changes near the top, like a timestamp, breaks the cache for everything after it. OpenAI and Gemini cache automatically on supported models, so there the waste is in how the prompt is ordered. On Anthropic, the usage data for every call shows how many input tokens came from the cache, so you can check instead of assuming.
Context that outlives the session and the provider
Some context shouldn't be copied into notes at all, because it already lives where people work. At Tools for Humanity we connected agents to Notion, Slack, Linear and GitHub. In one flow, a Slack workflow tagged Linear's agent on a request, and the agent read the team's doc on how to review and triage it, asked for anything missing, and confirmed or rerouted where it went, while the Slack thread synced to the issue. Because the agent read the doc on each request, a team could change how its requests got handled by editing a doc it already kept. It's also why I think Slack is winning: it's where people already work, and now the agents work there too.
When a connection runs through an MCP server, the model decides when to look something up and what to ask for, which makes it probabilistic in the same way instructions are. That's the right trade for reading a doc or searching a thread. For an action that has to happen one exact way, like a refund, I'd build the tool on the system's API directly, so code makes the call with fixed inputs.
My own context sits in files I control. The rulebook, the notes and the failure library are plain Markdown, so if Claude went down tomorrow, another provider's agent could pick up the work from the same files. The rulebook is named CLAUDE.md, but any model can read it. The hooks are where a move would cost me something. The checks are ordinary Python scripts, but Claude Code's settings file is what attaches them to the agent's actions, so I'd have to wire them into the new tool, if it supports hooks at all.
The hooks are where a move would cost me something
MY SETUP: RULEBOOK, NOTES, FAILURE LIBRARY, HOOKS
One harness for the whole company
For a company, the same idea becomes one harness that every employee's agent sessions load: company-wide rules and hooks, profiles tailored by department, and one voice, tone and brand guide so public output sounds like the same company whoever's agent wrote it. Staff should be able to propose changes the way engineers propose code, as pull requests someone reviews. Without that, each person's agent runs on whatever instructions that person thought to write, and a correction one of them makes never reaches the rest.
Most of this works without code. Standing instructions in your AI tool are the rulebook: sales might keep the discounts that need a manager's sign-off there, and support the refund policy, worded the way customers should hear it. Permissions are the hooks, because an agent that shouldn't issue refunds shouldn't be able to reach the refund tool, whatever its instructions say. Date every instruction and give it an owner, since one written before a price change keeps quoting the old price until someone rereads it. And check what the AI says it finished: open the report and check one total by hand, and send the email to yourself before a customer gets it.
In Team AI Enablement, each person builds a working AI skill for their own job, and the team leaves with a shared skill library to write the next correction into.
Services
- Is your company paying for AI that hasn't changed how the work gets done?
- Is your bot handing more conversations to agents than the vendor promised?
- Is your AI wish list growing faster than anyone has time to build it?
- Are you paying for more AI seats than your team actually uses?
- Is the bot you launched last quarter still giving last quarter's answers?
Is your company paying for AI that hasn't changed how the work gets done?