Key takeaways
- Restructure first, change behaviour later. All four restructuring steps left every decision unchanged. A parity replay found 0 differences over 233,636 recorded outputs for the first two steps, and over 234,163 for the last two.
- Put policy behind one decision function, called at fixed points. Ours has nine points, from capture to delegation. A pack that denies everything closed every policy decision with no change to the core code.
- Write policy as data, under a floor no pack can lower. Packs combine in a fixed order, a narrower pack can only narrow, deny wins, and errors fail closed.
- Be honest about what a seam is not. 17 of the 19 places where today's rules run still run the old code, now reached only through the new function.
- The layers made our next weakness visible. On PersonaMem-v2, preferences stated outright were found 99.5% of the time. Preferences revealed only in passing were found 30.7% of the time (752 questions).
The need: memory that agents can trust, and a module that did everything at once
A memory system for agents makes thousands of small decisions: should this message be remembered, is it a correction, who may read it, may it go into this agent's context, must it be erased? In our lab, all of those decisions lived in one 3,682-line module, and the rules added by parallel pieces of work had started to interfere with each other in tests.
Looking at our own numbers, we had to admit something uncomfortable: by trying to build every layer at once, we had made the memory infrastructure more complicated than it needed to be. And the numbers that were failing were core memory, not enterprise policy. On our latest synthetic test set, the rule-based arm recalled only 0.21 of the things it should have remembered. Each week's fixes had gone to whichever failure the latest read showed, enterprise or not.
So we decided to split the module along the lines our own goals already drew:
- core memory for one person: capture, deciding what to remember, correct and forget, retrieval and serving;
- a thin access layer: who wrote each record and where it lives, with permissions applied before ranking;
- policy modules on top: special categories, team rules, erasure across scopes, legal hold.
Looking back from 2037
Before choosing the boundaries, we asked a harder question: what will memory look like when AI agents are its heaviest users? We put it to several frontier models, each at its highest reasoning effort, first with no knowledge of our design and then with it. On many points they agreed:
- an append-only record of what happened is the only source of truth, and everything else is rebuilt from it;
- every event and read carries an identity envelope: who acts, for whom, about whom and for which audience, with agents as principals in their own right under a mandate;
- permissions are applied inside the query, before ranking;
- a model may propose, but code decides, and a model may narrow access, never widen it;
- policy is data behind one decision function with fixed decision points.
That gave us a target: fixed layers, each with a written contract saying what it must never do, and a policy plane the layers call into. "Ready for the future" did not mean building every feature now. It meant getting the seams right now: the places that would need a rebuild if added later.
Our approach: four steps that move code but change no decision
- The split. The one module became a facade over three parts: core (2,991 lines), access (213) and policy (492).
- The split by stage. Core was split again, along the path a message takes: a capture guard, a stage that proposes what to remember, a stage that admits it, and a read view.
- The envelope. Every raw event, derived record, served item and read request now carries an envelope with typed required fields. That includes the actor, on whose behalf it acts, its mandate, the subject, the audience, the purpose, and the id of the decision that allowed it. Envelopes and decision ids come only from sealed functions, so a caller cannot mint its own.
- One decision function at nine points.
decide(point, envelope, labels)is the only way to reach the access and policy rules. Its nine points are:- capture: may this event be stored?
- admit: may this proposal become a record?
- widen: may its scope or audience change?
- read: what may this reader see?
- inject: may this item enter an agent's context?
- act: may this tool call run?
- emit: may this claim reach this audience?
- lifetime: keep, expire, erase or hold?
- delegate: may this principal grant this mandate?
A policy pack is a versioned bundle of rules written as data, with no code. It names the decision points it applies to and the labels it uses, and carries its own must-allow and must-deny test cases, which run when it is loaded. Packs combine in a fixed order: regulation, tenant, client, department, team, then person or agent. A narrower pack may only narrow what a wider one allows, and deny wins.
Under every pack sits the kernel floor: a short list of rules that no pack can lower. Tenants and clients are isolated. Permissions apply before ranking. Some content is never stored. A legal hold beats an erasure. No unverified claim is raised to fact. No mandate is wider than its grantor's. A pack that would break the floor is refused when it loads, and every decision is checked against the floor again when it runs.
The default pack is today's rules, so the structure could change while the decisions stayed the same. Detectors, such as the filters that spot secrets or health information, are kept apart as labelers: they produce labels, and packs refer only to labels. That separation is what makes a pack swappable.
Why not rewrite it, keep adding rules, or adopt a policy engine now?
- "Rewrite it cleanly." A rewrite changes structure and behaviour at the same time. When a number then moves, you cannot tell whether that was a fix or an accident. Moving code first, with proof that nothing changed, lets every later behaviour change be measured on its own.
- "Keep adding rules where they are." That is how the module reached 3,682 lines with rules crossing in tests.
- "Put policy in the prompt, or let a model judge it." Our contract for the policy plane says it must never live in a prompt or be evaluated by a model. A decision about who may see a record has to come out the same every time, and be explainable afterwards.
- "Adopt a general-purpose policy engine now." One may come later, behind the same function. Today's need was the seam, not the engine.
How we tested it: a parity replay, then regression reads
A parity replay records every input and output of the old code over all our test material, runs the same inputs through the new code, and compares the two line by line. Ours covered 34,028 calls captured from the test suite and 12,876 simulated sessions under 8 to 83 different guard settings. A single changed output anywhere would fail the step.
A regression read reruns our three already-used synthetic test sets through the restructured code and compares every reported number with the read before. These sets are not blind any more, so the reads prove only that nothing moved. That is exactly the question here.
All of this is lab work on synthetic data. No real user text was used.
Results
Each step was merged on 30 Nov 2026:
| Step | Parity replay | Lab test suite |
|---|---|---|
| 1. Split into core, access and policy | 0 differences over 233,636 outputs | 6,649 passed |
| 2. Split core by stage | 0 differences over 233,636 outputs; the facade's 410 names identical | 6,676 passed |
| 3. The envelope | 0 differences over 234,163 replayed lines, with and without envelopes | 6,728 passed, 0 failed |
| 4. One decision function at nine points | 0 differences over 234,163 lines | 6,754 passed |
- The regression reads were identical at every step, line for line, on all three test sets. That includes the harmful-served counts: 36 of 1,980, 32 of 3,062 and 45 of 4,132 items. The restructure fixed none of those, and was not meant to. It froze them, so that the fixes that follow can be measured cleanly.
- The envelope's own 35 tests refuse a record missing a required field, an envelope or id made by a caller, and a revoked mandate. After erasing a capture, nothing derived from it could be retrieved, across more than 200 erasures. All 653,378 records in the replay carried a valid envelope.
- The decision function's own 26 tests: a pack that denies everything blocks every policy decision with no edit to the core code. Packs that would break the floor are refused at load, run-time overrides are denied, and code that reaches around the function, leaving no decision id, is caught.
What failed along the way
- One of our own numbers was wrong. A reviewing model caught that our proposal had joined two different arms' results into one row. We corrected the table in the proposal and recorded the correction.
- Two tests failed after merging pieces that had passed on their own. Two branches had been checked only with their targeted tests. Run together, two tests on the main branch failed, and were fixed before the next step. Our rule now: run the full suite after every merge of a separately tested branch.
What it did not do yet
A seam is not the finished building. Honestly:
- 17 of the 19 places where today's rules run still run today's code. The default pack reaches them through the decision function, but only two of them are written as data rules: the capture disposition and the record-type-by-scope matrix.
- The serving path is not yet wired to the read decision. We showed the two agree on small test plans.
- The tool-call, claim and delegation points deny everything for now. On a single laptop the delegation chain is empty.
- An error inside the old rule code still stops the whole session instead of becoming a deny. That is still closed, but it is not yet tidy.
- The envelope is not yet in the database schema, and its lineage goes one level deep.
What's next: core memory first
With the seams in place, the direction is clear: build the core memory first, for one identity. That identity may be a person, or an AI agent with its own identity. Teams, departments, clients and policy packs beyond the default wait behind the seams we just built.
1. Context bloat and context rot, with the lines written first. As a memory grows, two things go wrong:
- bloat: an agent's context fills with tokens that don't help;
- rot: the right memory is found less often, and stale facts creep in.
Before reading any data, we wrote down how we will measure both. We will grow a store from one persona's own history to about 10,000 and then about 100,000 chunks, and run the same benchmark questions at each size. The pass lines:
- recall at 10 at the largest size must stay at least 0.90 of its value at the smallest;
- the share of injected tokens that carry the evidence must keep at least 0.75 of its value;
- no injected packet may exceed its 800-token budget.
2. Preferences that are never stated outright. On PersonaMem-v2, a public benchmark of personal preferences learned from ordinary chats, we ran a retrieval-only test on 40 personas (29 Nov 2026, 952 questions with evidence):
| Preferences | Questions | Evidence found in the top 10 |
|---|---|---|
| stated outright, updated, or asked to be forgotten | 200 | 99.5% |
| revealed only in passing | 752 | 30.7% |
How far back the remark sat made no difference. The gap is about meaning: a question asking for breakfast ideas does not resemble an earlier remark about a family history of diabetes. That points at learning preference facts when the chat is written, each linked to the message it came from, rather than hoping a later search finds the passing remark.
Before building anything, we will run a free ceiling test. We will store the benchmark's own correct preferences as perfect facts and check whether each of three designs can reach them:
- facts searched like any other memory;
- facts tagged with the topics they apply to;
- a small profile kept in the context.
We also fixed the benchmark's splits before reading them. The 40 personas above are never tuned on, and every change is read once on a held-out set.
3. Reproducibility, continued. Our article on reproducible memory search left two things open: a stable tie order cheap enough to adopt, and whether results survive a rebuild. Since then we count each question's rank as a range over its tied results, rather than one rank that a random tie order decides.
- Those ranges came out identical in every run, for 7 questions on LongMemEval run twice each. They were the same with and without the stable tie order we are still testing.
- A backup and restore of a test copy left the full search order unchanged on 7 of 7 questions.
- One caveat: these runs embedded each text on its own. A restore that re-embeds in batches could still move scores slightly, and that is our next question.
What we'd suggest
- Prove each restructuring step with a parity replay before changing any behaviour. The recording of real inputs and outputs is the safety net.
- Give policy one function and a fixed set of decision points. Write rules as data with their own test cases, under a floor no pack can lower, and make deny win.
- Keep detectors apart from rules. A label is easy to reuse; a rule with a detector inside it is not.
- Write pass lines before reading the data, and fix a benchmark's splits before you look at them.
- Measure stated and implicit preferences apart. One average hides a 99.5% and a 30.7%.
Frequently asked questions
What is a policy pack in AI agent memory?
A versioned bundle of rules written as data, not code. Each rule applies at a fixed decision point, such as capture, read or erase. The pack carries its own must-allow and must-deny test cases. Packs combine in a fixed order, and a narrower pack can only narrow what a wider one allows.
How do you refactor an AI memory system without changing its behaviour?
Record every input and output of the current code over your tests and simulated sessions. Then replay the same inputs through the new code and require zero differences before merging. Change behaviour only in a later, separate step, with its own pass line.
What is context rot?
The drop in memory quality as a store grows: the right item is found less often, and stale facts are served more often. We measure it by asking the same questions at growing store sizes.
Why does vector search miss implicit preferences?
A preference revealed in passing rarely resembles the later question it bears on. In our test, similarity search found the evidence for 30.7% of such preferences, against 99.5% for preferences stated outright.
What do AI agents need from memory that chat assistants do not?
An identity of their own, and a record of whom they act for and under what mandate. Memory also has to check, on every read and write, that an agent's reach never exceeds its principal's.