Skip to content
The AI Agent Factory

36.2 Memory that survives a change of model

Approved by
Panaversity ·
8 min read

In everyday life. A firm's knowledge is in its files and procedures, not in the head of one employee. When an accountant leaves, the next one reads the client file and carries on.

What you will learn. The five kinds of memory a worker uses, and where to keep them so they survive a change of model. What each memory must record about itself, and why search results need a permission check.

Why it matters. Memory is what the company pays learning to produce. If it lives in a model provider's format, the company rents it.

Five kinds of memory

KindWhat it holdsExample for the AP worker
WorkingWhat the current assignment needsThis invoice, this PO, this approval
EpisodicWhat happened in past assignments"Invoice 1043: matched to PO-778, corrected by Ana: wrong cost centre"
SemanticVerified facts"Acme Supplies puts the PO number in the footer"
ProceduralApproved skills and procedures"How to handle a partial delivery"
OrganizationalKnowledge shared inside one company"Brightline pays all suppliers on the 15th and the 30th"

Working memory is the conversation, in the Durable Object. The other four live in Neon, in tables you own, with pgvector for search by meaning. None of them is stored in a format that belongs to a model provider. A memory is text, with structured fields around it. A rule the whole company must follow, people included, belongs in its policy documents, not in memory, and memory never overrides it (31.8).

Experience records

Every finished assignment writes an experience record. It holds references to the evidence (invoice ID, PO ID, not copies of them), the worker version and model used, and the skills and process versions. It also holds the outcome, the cost, and every correction a person made, with the correction itself.

Step 1. Read spec-learning.md. Add the memory migration: experience_records, memories and memory_versions, with tenant_id on every table and a vector column for search. At the end of every assignment, write one experience record with references, versions, outcome, cost and corrections, keyed by the assignment ID so a replay writes it once. Write the tests first.

Experience records are the raw material of learning. They are also untrusted: they contain supplier text, which may contain instructions aimed at the worker. Dreaming reads them as evidence, never as orders (36.3).

What every memory records about itself

A fact in semantic memory is only as good as its source. So every memory carries:

  • Provenance: the experience records it came from, and the candidate that proposed it.
  • Approval: who approved it, and when.
  • Validity: from when, until when, and on what condition it expires. "Acme's bank details" should not live forever.
  • Status: proposed, verified, expired, revoked. A memory is written as verified when a person approves its candidate (36.5).
  • Version history: every change, with its reason.

A guess by a model is never a verified fact. A memory becomes verified only through the evaluation and approval in 36.4 and 36.5.

Search is not permission

When the worker needs memories, the context planner from Chapter 35 searches by meaning: "what do we know about this supplier?" Vector search returns what is similar. It does not know what the worker may see.

So retrieval checks permission before any model sees a memory:

select id, body from memories
where tenant_id = $1                -- the trusted tenant, from the assignment
  and status = 'verified'
  and (valid_until is null or valid_until > now())
  and scope = any($2)               -- what it is about (a supplier, a procedure, the company), as the contract allows
  and id = any($3)                  -- only memories in the release's memory set
order by embedding <=> $4           -- then, and only then, by similarity
limit 8;

The filter comes first, as in the router from Chapter 35. A memory from another company, an expired or revoked fact, or one the current release does not use is never in the result, however similar it is.

The test that matters

Step 2. Write the model-switch test: run the eight visible golden questions on the worker with Claude Haiku and with its verified memories. Switch the model setting to the economy model. Run them again. The same memories must be retrieved, and every answer that depends on a verified memory must still use it.

What good looks like: the memories retrieved are identical. Some answers may differ, because a different model reasons differently. That difference is what you measure, not what you lose.

What to check. Is any memory stored only inside a Pi transcript or a provider's memory feature? Does the search filter by tenant, status, validity, scope and release before ranking? Is an experience record written once per assignment, even after a crash?

The invariant. Approved knowledge lives in the company's own store, with its source, approver and expiry, and a model sees only what the worker may see.

Check yourself. Dreaming writes "Lahore Foods' supplier X is unreliable" into semantic memory, and Acme's worker retrieves it because the supplier name matches. What two rules were broken? (Dreaming wrote straight to live memory, without evaluation and approval. And retrieval did not filter by tenant before ranking by similarity.)

  • Building Affordable, Self-Improving AI Workers (Panaversity, 29 November 2026), section 10.1
Owner
Panaversity