Build Log

How to Give an
AI Agent
a Memory

5 layers of memory. Episodic recall. Self-critique. Semantic search. A system that learns from every decision.

agent memory-system
01 — The Anatomy Lab

I used to hold human brains in my hands.

Three pounds. Wrinkled like a walnut left in water. Oxford anatomy lab, two in the morning. Just me, a cadaver and questions that wouldn't stop circling.

I'd trace a single neuron from the cortex all the way down to the fingertip. An unbroken thread. Thought to touch.

The brain isn't a computer. Every metaphor you've absorbed — files and folders, storage and retrieval, input and output — they got us far. But they're not the whole story. The brain is a jungle. Dense. Pulsing with things growing and dying and competing for sunlight.

Donald Hebb figured this out in 1949. Seven words: neurons that fire together wire together.

I taught this at Oxford. And now — seventy-six years later — we can build it.

02 — The Inspiration

Then I met a community building brains in code.

Reuven Cohen — 82 Rust crates. Each one a neuron. RuVector for synapses that strengthen when they fire together. AgentDB for episodic memory that captures everything. ReasoningBank for the thalamic relay that filters signal from noise. SAFLA for the brainstem — the safety layer that cannot fail.

He mapped neuroscience to software architecture. And gave it away. Open source.

I joined the Agentics Foundation. London chapter. A community of practitioners building the next layer of AI infrastructure. Not consultants. Builders.

Inspired by this work, I built my own.

$ agent --architecture

The architecture of a brain
that learns.

cortexhippocampusthalamuscerebellumbrainstem
CEREBRAL CORTEX

LLM Reasoning Layer

The slow, deliberate thinker. Language, planning, abstract thought. The LLM handles what the cortex handles — conscious, expensive reasoning.

analyst.evaluate(context, indicators)
HIPPOCAMPUS

Episodic Memory

Records everything. Doesn't judge importance. Damage it and you're frozen in an eternal present. Every decision captured with full context.

entry_reasoning, exit_reasoning,
context, confidence_at_entry,
outcome_tags
THALAMUS

Reflexion Engine

The relay station. Good outputs reinforce pathways. Bad outputs trigger correction. Post-decision critique via LLM.

reflexion: "Entry timing premature —
  divergence not confirmed"
lesson_type: "timing"
SYNAPSES

Semantic Search (FAISS)

Paths that fire together wire together. Three namespaced indices with staleness decay. The system sculpts itself around use.

namespaces: [reasoning, wiki, raw]
staleness: score *= 1/(1 + 0.01 × days)
BRAINSTEM

Safety & Guardrails

Ancient. The systems that cannot fail. Hard limits, emergency stops, automatic rollback. The autonomic layer that keeps the system alive — even when the cortex hallucinates.

max_exposure: 5%
daily_loss_limit: -2% → circuit_break
blackout: [high_impact_events]
$ agent --extend

Cohen built a brain.
I built one that evolves.

cortexhippocampusthalamuscerebellumbrainstem
CEREBELLUM

Skill Library

Procedural memory. Motor patterns that run without conscious thought. Patterns auto-promote at 5+ observations with >60% success rate. The agent develops muscle memory.

pattern: "momentum_divergence"
success_rate: 0.73
sample_size: 12
status: "active"
DOPAMINE SYSTEM

Provenance Tracking

Which data sources actually predicted well? Credit the winners, discount the losers. Not all information is equal. The brain learns who to trust.

source: "economic_calendar"
accuracy: 0.71
predictions: 38
CONTEXT-DEPENDENT RECALL

Regime Snapshots

When the environment returns to something seen before, reload the priors. Like how a smell triggers a childhood memory. Snapshot on regime change, reload on regime return.

regime: "risk_off"
snapshot: { skills: [...], provenance: [...] }
restored_from: "2026-03-15"
$ agent --feedback-loop

When a decision closes, seven things happen automatically.

1

Input arrives — cortex analyses

2

Decision executes — hippocampus records

3

Outcome observed — thalamus critiques

4

Patterns extracted — cerebellum updates

5

FAISS re-indexes — synapses strengthen

6

Provenance scores update — dopamine fires

7

Loop. The brain improves while it runs.

This is what learning looks like. Not a training run. Not a fine-tune. Continuous. Emergent. Alive.

$ agent --reflect

What nature already knew.

Episodic memory isn't a database pattern — it's the hippocampus.

We didn't invent "capture everything with context." Biology did. We just finally have the compute to implement it. I held this structure in my hands at Oxford. Now it's a Python class.

Self-critique isn't a prompting trick — it's the thalamus.

Every sensory signal gets filtered before reaching consciousness. Good signals reinforce. Bad ones correct. Cohen calls it "bounded reasoning." Neuroscientists called it the thalamic relay 150 years ago.

Forgetting is a feature, not a bug.

Staleness decay in FAISS mirrors synaptic pruning — the brain actively discards what isn't reinforced. We had to build this deliberately. The brain does it automatically.

Muscle memory is real in software.

The skill library auto-promoting patterns after enough observations — that's the cerebellum. Procedural knowledge that runs without conscious thought. The agent develops intuition. Not because we programmed it, but because the architecture produces it as an emergent property.

$ agent --status

The scalpel's in your hand.

Not replacing the human. Making the human unstoppable.