Skip to content
All writing
·8 min read

Building CORTEX: an AI that learns from being wrong

Notes from a side project — a brain-inspired cognitive architecture that wraps local LLMs in a prediction-error loop, with hierarchical memory and a world model that trains itself.

  • AI
  • Machine Learning
  • Build Log

Most “AI agents” today are a language model with a to-do list bolted on. I wanted to try something different: treat the LLM as one part of a larger mind, and build the rest of the machinery around an old idea from neuroscience — that intelligence is mostly about predicting what comes next, and learning from the surprise when you’re wrong.

That project became CORTEX.

Prediction error as the core loop

The central bet is that a useful agent shouldn’t run the big, expensive model on every input. It should predict what’s coming, and only escalate to the heavy machinery when reality surprises it. Familiar situations get cheap, fast responses from memory; novel ones get the full treatment.

So at the heart of CORTEX is a small GRU network — a world model — that continuously learns to predict the next semantic embedding. When its prediction is close, we’re in known territory. When it’s badly wrong, that’s a signal: pay attention, this is new.

Memory in tiers

Humans don’t have one undifferentiated memory, so CORTEX doesn’t either. It has four tiers:

  • A reactive in-memory cache for the immediate moment
  • A short-lived working memory
  • An episodic store for things that happened
  • A semantic knowledge graph for things that are true

They share one interface, so the rest of the system doesn’t care where a memory lives — only how relevant it is.

Curiosity, mood, and dreaming

Two more pieces make it feel less mechanical. A five-dimensional emotional state modulates the model’s temperature — a “calm” CORTEX is more deterministic; an “agitated” one explores more. And a dream mode lets it run idle, surfacing its own questions instead of waiting for input.

Why local

The whole loop runs on local models via Ollama. Partly for cost, mostly for principle: a system that’s meant to remember should keep its memories on your own machine.

It’s still research — but it’s the most fun I’ve had building anything in a while.