Personal Operating System
Jersey · GMTEst. 2026Get in touch →
Practitioner notes · AI applied to finance & operations

Jewel Nguyen

Deep read · July 5, 2026 · source published July 2, 2026

A four-layer memory architecture for agents that stay useful for months

Source: “The 4-layer memory architecture I run across 2 AI agents in production” by @MatthewGunnin · July 2, 2026
The thing that makes an AI agent genuinely useful over months isn't the model or the tools — it's how you file what it remembers. The argument here is that durable agent memory is an infrastructure problem, not a prompting problem: split what the agent remembers into four layers by how long each fact needs to live, and keep it all in plain markdown you can open and edit. The load-bearing evidence is boring on purpose — no vector database, no embeddings and no retraining — so you can open any file and fix a bad instruction by hand. It's a working blueprint from someone running two agents on one shared memory system across hundreds of sessions, and it tells you which layer you're probably missing.

Why a bigger context window isn't memory

The default fix when an AI forgets is to give it a bigger context window — the amount of text it can hold in view at once. The point here is that this doesn't solve forgetting, it delays it. Restart the session and everything is gone, and even mid-session the model reads the middle of a long context worst (the well-documented "lost in the middle" effect).

The broken starting setup is familiar: several disconnected chat windows, each with its own stale picture, agents contradicting each other because neither can see what the other knew, instructions from three weeks ago simply forgotten. The reframe is the whole piece: durable agent memory is an infrastructure problem, not a prompting problem.

In finance terms it's the difference between remembering a number because you're staring at it and writing it into the ledger. The first survives until you look away; the second survives the year. Memory isn't cramming more into the prompt. It's deciding what gets written down, and where.

Layer 1 — what's live this session

The first layer is what the agent reads the moment a session starts: an identity file (how it should behave, what it never does without asking) plus a memory index — a plain table of contents pointing to lots of small fact-files, read on demand.

The insistence is that the index stays "not a vector database, not embeddings." It's kept in markdown for one reason: "Because I can read it, edit it, and debug it. When an agent starts acting wrong, I open the index and find the bad instruction."

The detail worth stealing is file per fact, not one big document. Deleting a stale memory then never disturbs the others, and the index stays cheap to load and cheap to prune.

Layer 2 — what to carry to the next session

Markdown-only memory has one hole: it captures only what someone remembers to type. The valuable material is implicit — a decision made mid-run, a failure pattern you fixed, a preference the user corrected.

Layer 2 is a small local facts bank: a store the agent auto-writes curated facts into at the end of a session and queries at the start of the next one, before it answers. The safety rail is the important part. The path is fact → human review → index entry, so retention is automatic but nothing becomes permanent memory until a person approves it.

That gate is what separates a facts bank from an agent quietly teaching itself things you never sanctioned. Automatic capture, manual promotion.

Layer 3 — shared state, and the one rule that makes it work

Add a second agent and single-agent memory breaks. They drift; one thinks the project status is X, the other thinks Y, and within a week they contradict each other. The fix is one shared file both agents read before every reply and append to after every meaningful turn — a live, append-only log.

The rule that stops two writers corrupting it translates cleanly into three worlds. In software it's event sourcing: you never edit a past record, you append a new one that supersedes it, and the state is the replay of all entries. In accounting it's the oldest rule in the book, where you never erase a posting, you book a reversing entry, and the audit trail stays intact. In git it's just commits.

Each entry is signed (which agent, what kind, a one-line summary), kept append-only, and no agent may edit another's entry: "convergence is achieved by appending, never editing." Across hundreds of sessions that produced exactly one conflict, two agents writing in the same minute, resolved by reconciling on the next turn with no automated merge.

Layer 4 — what either agent can look up later

The first three layers are episodic: what happened, what was decided, what to carry forward. Layer 4 is the semantic one — a compiled wiki running as a search service (an MCP server, the standard socket that lets an agent query an external tool) over the shared knowledge base. It returns a ranked list of relevant pages with their sources instead of dumping everything into context.

The framing is the line to keep: L1 to L3 are what the agent carries; L4 is what it can look up. That's the difference between memory and recall.

The quiet lesson under all four layers is that they need different retention policies. Live state churns by the minute, shared state by the turn, carried facts by the session, and lookup knowledge is near-permanent. Treating them as one undifferentiated pile is the mistake that works for about six weeks and then rots.

The honest tradeoff, and where to start

The part that earns trust is that it isn't oversold: "It is not a magic always-on system. It is structured manual discipline plus automation at the seams." You have to write things down, maintain the files, and review what gets retained before it becomes permanent.

The reassuring number for a solo builder is that the full four-layer stack took six months to stabilise, but layers 1 and 3 took one weekend: an identity file plus an index, and one shared append-only log. That's the minimum viable version, and it carries most of the value.

The closing instruction is the one to borrow. Build the memory before you add more tools. The useful agents aren't the ones with the biggest context window, they're the ones that remember what matters and forget what doesn't.

Vocabulary

If you're building — what to watch for

Reading it critically

Read the original → ← Back to the Reading Desk