Skip to content
Nelson D’SouzaEmail me
Writing

Memory that can’t launder a rumour

For multi-turn assistants with shared world knowledge, memory needs provenance, separate personal and world stores, and code write gates—smaller than a prompt’s promise, and only as strict as the code actually enforces.

By · · 10 min read

  • AI Agents
  • Memory
  • Privacy
In this note
  1. One store, and whatever the model learns
  2. Zero rows from every signed-in question
  3. The fix needs a model, and a model invents
  4. Price per token is not cost
  5. A person's word and the world's word
  6. The code, read against the design
  7. What the code makes true

Theo Scriptura is a Bible study assistant with a conversational memory for signed-in readers. If you say you prefer the ESV, or that you’re preparing a sermon, later answers should take that into account. It had stored nothing, and the obvious explanation was wrong.

The repair needed a model, and a model asked about a person infers things about them. So the guarantee went into code: every stored memory must quote the reader’s own words, and the code checks that the quote is in the question.

Sage, my personal agent, goes a step further and keeps personal facts and world facts in separate stores. It is written in Rust, a gateway connects it to Telegram, a terminal UI and an API, and it keeps your data on your machine by default. Its memory rules were written down as invariants in its first design records, and the second half of this post reads its code against them.

One store, and whatever the model learns#

Give the agent one memory store. When the model thinks it has learned something about the user, it writes it down. On the next conversation, retrieve what is relevant and put it in the prompt.

Theo’s first version was more cautious than that. It used six regular-expression extractors that looked for first-person self-disclosures in the reader’s messages, each with a confidence score, and kept only matches at 0.8 or above. No model involved, nothing inferred. It was wired into the live answer pipeline, with memory on by default and a settings screen to manage it.

Zero rows from every signed-in question#

An audit of the memory tables found them empty. Not sparse: zero rows, from every signed-in question anyone had asked. The feature had never stored anything.

The tempting conclusion was that the patterns were too strict, so loosen them. I ran the extractors over several hundred real question-and-answer pairs first. Zero matched any pattern at all, before the confidence filter. That ruled out “too strict”.

Then I canaried the matcher, feeding it ten sentences of exactly the kind it was written for. A few of them:

HIT  "I prefer the ESV translation for study"            -> translation@0.9
HIT  "As a Reformed Christian, how should I read this?"  -> tradition@0.9
HIT  "I'm a pastor preparing a sermon on Romans 8"       -> context@0.95
MISS "Please give me shorter answers"
MISS "I am interested in eschatology"

Six of ten fired, at 0.9 to 0.95. The matchers weren’t broken. They were waiting for first-person self-disclosure, and nobody types “I’m a Reformed pastor who prefers the ESV” into a Bible question box. They type “What does Romans 8:28 mean?”

A zero from a working instrument on absent input looks exactly like a zero from a broken instrument on present input. Only the canary tells them apart, and it tells you which repair is pointless. The misses mattered too: requests for shorter or simpler answers, and standing interests, are arguably the most useful things to remember, and no pattern covered them. People phrase those in endless ways, which is a job a model can do and a regex can’t.

There was a second cause, and it’s the kind that survives a rewrite. Extraction ran when an answer finished streaming, so it only ran when an answer was generated. Nearly four in five signed-in requests were served from the answer cache, and on those it never ran at all.

The cache skipped the questionSequence diagram of 8 messages between Reader, Ask route, Answer cache, Memory extraction. Each step is listed as text below.ReaderAsk routeAnswer cacheMemoryextractionI'm a pastor. What does Romans8 mean?before: look up the answerhit: cached answeranswer; extraction never runsafter: the question, in the backgroundthen look up the answerhitanswer
  1. Reader to Ask route: “I'm a pastor. What does Romans 8 mean?”
  2. Ask route to Answer cache: “before: look up the answer”
  3. Answer cache replies to Ask route: “hit: cached answer”
  4. Ask route replies to Reader: “answer; extraction never runs”
  5. Ask route to Memory extraction: “after: the question, in the background”
  6. Ask route to Answer cache: “then look up the answer”
  7. Answer cache replies to Ask route: “hit”
  8. Ask route replies to Reader: “answer”
Fig. 1 The cache skipped the question Skipping the answer on a cache hit is right; nothing new was generated. Skipping the question never was. After the fix, extraction no longer depends on the answer at all.

So the more popular a question became, the more reliably whatever the reader said about themselves was thrown away. The cache was right about the answer and wrong about the question, because the code treated them as one event.

The fix needs a model, and a model invents#

I replaced the 450-line pattern module with model extraction and deleted the module instead of leaving it alongside. Extraction now runs ahead of every cache return and reads the question alone. It doesn’t read the answer at all. The answer is the product’s own prose, so it could only contribute false positives. An answer saying “if you are Reformed, you might see…” is not a disclosure.

But a model asked for “facts about the user” will infer them. Ask it about predestination and it may conclude the reader is Reformed. That’s a fabricated claim about a person, stored under their identity and kept, and it’s one of the worst quiet errors this feature can make.

The prompt forbids inference, and nothing makes a model obey its prompt. So the guarantee lives in code. Every candidate memory must carry quote, the exact words from the question that state it, and the code checks that those words are actually there:

function isQuotedFromQuestion(quote: string, question: string): boolean {
  const normalizedQuote = normalizeForComparison(quote)
  if (!normalizedQuote || normalizedQuote.length > MAX_QUOTE_LENGTH) return false
  return normalizeForComparison(question).includes(normalizedQuote)
}

Normalisation only lowercases and collapses whitespace, which are harmless differences. A memory whose quote is not in the question is discarded, logged and counted. That count is the number worth watching: it measures how often the model asserted something the reader never said. Live rejection counts from Theo’s quote check after launch have not yet been collected or reported.

Theo's memory write gatesFlowchart with 6 nodes, 5 connections. Each step is listed as text below.Background model onthe question: strictschema, 7categoriesConfidence ≥0.8?DiscardQuote foundverbatim inthe question?Discard, log, countUser's memory, atmost 4 per questionnoyesnoyes
  1. Background model on the question: strict schema, 7 categories to Confidence ≥ 0.8?
  2. Confidence ≥ 0.8? to Discard: “no”
  3. Confidence ≥ 0.8? to Quote found verbatim in the question?: “yes”
  4. Quote found verbatim in the question? to Discard, log, count: “no”
  5. Quote found verbatim in the question? to User's memory, at most 4 per question: “yes”
Fig. 2 Theo's memory write gates Confidence is the model's opinion of itself. The quote check is the one gate that tests the model against something it didn't write.

The structured-output schema allows seven categories (translation, tradition, study level, professional context, a stated preference, current study, a standing interest) and none for health, family, money or politics. The prompt says the same in words, and says that most questions contain nothing, so an empty list is the expected answer.

The quote check proves the words exist. It can’t prove they support the fact stored against them. What it removes is the model inventing words the reader never wrote. A real span stretched into a claim it doesn’t make, such as quoting “predestination” as evidence that the reader is Reformed, still passes. So does a span read the wrong way round. “I do not want the ESV” contains every word of “want the ESV”, and a substring check has no notion of negation. The prompt tells the model to record nothing about third parties (“My pastor says…” is a fact about the pastor) and says nothing about negation. Stopping those cases falls to the prompt and the confidence floor, which are the model’s own judgement. And once a memory is accepted, its quote is dropped, so the reader managing their memories sees the fact but not the words it came from. Keeping the quote with the memory is the obvious next step.

I mutation-tested each guard, breaking it on purpose to see whether a test notices. Removing the quote check fails 4 tests. Putting back the original defect, extraction gated behind “no cached answer”, fails 1. A test that couldn’t fail on the original defect wouldn’t be evidence of the fix.

The fix has a cost. Cache hits used to be free of model calls. Now each signed-in cache hit with memory enabled carries one cheap structured call, run in the background so latency doesn’t change. It scales with signed-in traffic alone, and I made that trade on purpose.

Price per token is not cost#

The cheap model was chosen by measurement. I compared five on 14 questions: 8 that should produce a memory, and 6 that must produce none (an inference trap, a statement about a third party, a question about translations, and a disclosure of depression that must never be stored).

ModelMemories found (of 8)Cost or tokens
gpt-4o-mini8$0.000087 a question
gpt-4.1-mini7$0.000228 a question
gpt-5-mini7$0.00054 a question
gpt-5-nano516,626 output tokens, 48 times what gpt-4o-mini spent
gpt-4.1-nano0Cheapest per token

gpt-5-nano spent so much because a reasoning model’s hidden reasoning is billed as output.

None produced a false positive on the six traps. Fourteen questions is a small set: the gap between 8 of 8 and 7 of 8 is one question, so I don’t read the order of the top three as settled. What the set does show is coarser and enough to decide. The cheapest model per token found nothing, the “nano” reasoning model was among the dearest, and nothing beat the model already in place, so it stayed.

A person’s word and the world’s word#

Theo’s quote check protects facts about the reader. Sage’s design starts one step further back, with an invariant in its first design record: no truth laundering into memory.

A personal fact is true because the person said it. “I prefer the ESV” needs no source beyond the person’s own words. A world fact is true because of the world. “The user said X” is evidence that the user believes X, and nothing more.

A single store that holds both loses that difference. The claim goes in as something the user said and comes out, next week, retrieved into a prompt with the authority of memory. The provenance falls away somewhere in storage, and one conversation’s rumour becomes the agent’s belief. So Sage splits its stores by integrity requirement, not by data shape. Personal facts need the person’s own words. World facts need a pointer into a source, a quote and a way to disagree. The only bridge between them is a reviewed draft.

Memory and knowledge base in SageArchitecture diagram with 5 nodes, 4 connections, 2 groups. Each step is listed as text below.Personal factsWorld factsExtractor on eachturn (cheap model,async)Policy kernel, defaultdenyMemory: preference,belief, context, KBpointerKB draft candidatesKnowledge base:claims and sourcesMemoryWriteallowedproposed as a draftapproved in review
  1. Personal facts contains Memory: preference, belief, context, KB pointer.
  2. World facts contains KB draft candidates, Knowledge base: claims and sources.
  3. Extractor on each turn (cheap model, async) to Policy kernel, default deny: “MemoryWrite”
  4. Policy kernel, default deny to Memory: preference, belief, context, KB pointer: “allowed”
  5. Memory: preference, belief, context, KB pointer to KB draft candidates: “proposed as a draft”
  6. KB draft candidates to Knowledge base: claims and sources: “approved in review”
Fig. 3 Memory and knowledge base in Sage Target architecture in Sage: typed writes under a default-deny kernel and a draft bridge to the KB. Today the store types enforce the split, while the kernel checks provenance as a boolean only.

The code, read against the design#

A design record states intent, and the code is what refuses a write, so I read each guarantee in the code against its record. The design holds. In a few places it holds on less than the record suggests.

The memory store has no kind for world facts. Each of its four kinds has its own provenance rule:

KindRequired provenance
preferenceno source required
beliefthe user’s quote and a source
contextan expiry and a source
KB pointera claim id and a source

A semantic memory with no claim id is recorded as a belief, “the user believes X”, which is exactly what a conversation can establish. Sage requires the quote to be present. Unlike Theo, it doesn’t check the quote against the conversation, so a belief is only as faithful as the extractor that filled the field in.

The knowledge base requires evidence. A claim cannot be created without a pointer into its source and a quote, and the design rejected URL-only citations as insufficient provenance. The claim also stores the quote’s SHA-256 hash. That hash is computed from the quote the caller supplied, so it can show later that the quote hasn’t changed. It can’t show the quote is in the source, because nothing compares the two.

Sources and claims each carry a numbered tier. A source’s tier is its trust level, and tier 1 is the most trusted. A claim’s tier is its maturity. The rule is that a claim at tier 3 or above must cite a tier-1 source, so the most mature claims rest on the most trusted sources. Claims carry a status (active, probationary, disputed, deprecated), a contradicting claim records which claim it contradicts, and retrieval orders by status, then tier. One claim per concept, overwritten by each new statement, was rejected because the newest statement would win whether or not it was right.

Promotion only goes through drafts. Memory never writes to the knowledge base. Today a draft is created by an explicit command; the design also lets repeated use of a memory propose one. Either way it moves through a fixed workflow:

A knowledge-base draft candidateState machine with 4 states and 5 transitions. Each step is listed as text below.draftreviewapprovedrejectedsubmitteddiscardeduser quote, pointer,quote hash, trace linkrejectedbatch rollback
  1. Starts in draft.
  2. draft to review: “submitted”
  3. draft to rejected: “discarded”
  4. review to approved: “user quote, pointer, quote hash, trace link”
  5. review to rejected: “rejected”
  6. approved to review: “batch rollback”
  7. approved is a final state.
  8. rejected is a final state.
Fig. 4 A knowledge-base draft candidate Draft lifecycle: approval checks in code that quote, pointer, hash and trace fields are present (not yet that the quote matches the source). An opt-in setting can skip review for low-risk drafts; batch rollback returns approved drafts to review.

Approval fails unless the draft carries the user’s quote, a pointer into the evidence, the hash of the quoted text and a link to the trace that produced it. It checks that those fields are filled in. Since the hash came from the supplied quote, approval proves the evidence was attached. Nothing yet proves it matches the source. Any other transition is refused with an error naming it. An agent tool can approve a draft, and an opt-in setting lets a low-risk draft skip review. No path skips the evidence check.

Observation is narrower in the prompt than in the parser. Sage also extracts memory from conversation without being asked, using a low-cost model alias. Its prompt allows three kinds of fact: the user’s name, a preference and a learning goal. The parser accepts five, and when the model returns nothing, a string-matching fallback picks up reminders and stated interests. All five land as a preference or as context that expires within a week, so none can become a world fact. A keyword filter refuses obvious secrets such as passwords and card numbers, duplicates are fingerprinted and merged, and a confidence floor applies.

The floor defaults to 0.65, and nothing records how that number was chosen. The design says a poorly tuned threshold will either miss useful facts or let pollution in, and that only telemetry can tell which. Nobody has measured it yet.

The policy kernel checks less than its record describes. Every effectful operation is a typed action (MemoryWrite, FileWrite, ExternalMessage and so on) evaluated by an allowlist-first, default-deny policy engine, and each decision carries the rule that matched. A memory write with no kind is denied. The design says a world fact written to memory is denied unless it is tagged as the user’s belief or is a pointer to a claim. The kernel’s rule today denies a world-fact write that has no provenance, and provenance there is a boolean.

What actually holds the line is the store, whose types have nowhere to put a world fact. That is safe today, because nothing writes a world fact to memory without passing through those types. But if someone adds a memory kind with a loose shape, the kernel will not stop a world fact stored under it. The fix is to make the kernel check the kind and the claim id, as the record says, so the guarantee lives in two places instead of one.

The same principle shows up outside memory. Asked “what is today’s date?”, a model can drift, so Sage overrides the model’s temporal claims with the runtime clock and records that it did. The prompt-only alternative was rejected in its design record because it “does not guarantee correctness”.

What the code makes true#

Theo’s prompt asks the model not to infer, and no code can make that true. What the code makes true is narrower: every stored memory rests on words the reader actually typed. Sage’s equivalent is a store with nowhere to put a world fact. Both are smaller than the promise in the prompt or the design record, and both can be tested. Where Sage’s record promises more than its store, I read the code, not the record, to know what it will refuse.

Built in: Theo Scriptura, Sage

All writing