·9 min read

Why Your Agent Keeps Forgetting

Why Your Agent Keeps Forgetting blog cover
On this page

Build an agent long enough and you hit the same wall. It runs a job, does it well, finishes. You hand it the next job, the one that builds on the last, and it starts from absolute zero. No memory of the work it just did, no memory of the dead end it already hit, no memory of the thing it figured out ten minutes ago. Every run is amnesia. You pay again for conclusions it already reached.

That amnesia comes straight from the model, and it's the first wall you hit when you stop calling an API and start building an actual agent.

Before the ladder, one thing has to be clear, because everything else follows from it: the model is stateless.

A large language model has no memory. None. Every time you call it, it starts with a completely blank slate. It doesn't know what happened in the previous call, let alone last Tuesday's run. The only reason it ever seems to remember anything is that you, or the system around it, feed the previous turn back in as context. Cut that context and the agent is back to zero.

#1do XMODELresult A
no memory carries over
#2do YMODELresult B
no memory carries over
#3do ZMODELresult C

The model is stateless. Every call starts blank. It only knows what you feed it this turn.

So agent memory is never really the model remembering. It can't. Memory is everything you build around it to give it a past.

The fix is memory, and this is where people go wrong: "memory" isn't one thing. There's no single box called agent memory you bolt on. It's a ladder of six layers, cheapest to richest, and you climb it one rung at a time as your agent outgrows each one.

Let me show you how I build it. We'll follow one agent doing real work, the kind that runs across many turns and gets smarter the more it runs. Watch it gain a new kind of memory at every step.

01
Context window
Trigger: It jumps to conclusions, can't show its work.
remembers: The task, held in mind
02
Scratchpad
Trigger: A restart wipes everything, it redoes the whole job.
remembers: Working hypothesis written out
03
Persistent state
Trigger: It repeats a mistake, last run is gone.
remembers: Task #42, step 3 of 6, survives a restart
04
Episodic memory
Trigger: The journal is huge and noisy, patterns are buried.
remembers: Remembers how task #17 went
05
Consolidated memory
Trigger: Needs the pattern, not a replay of old runs.
remembers: Pattern: this signal usually means X
06
Retrieval (RAG)
Trigger: Needs knowledge it never encountered.
remembers: Pulls from a knowledge base it didn't write

If you want a feel for it before the details, think of a new hire. Day one they hold the whole task in their head. Soon they're scribbling sticky notes so they don't lose their place. Then a desk drawer that survives overnight. Then a memory of how last week's job went. Then instinct, hard-won from a hundred tasks. And eventually the company wiki, for the stuff their own experience never covered.

Six layers, and each one earns its place only when the rung below stops being enough. One thing stays constant across all of them: the model box never changes. What changes at every rung is what you read in before the call and what you write out after. You'll see that diagram at each step.

Walk them with me, from the cheapest up.

Layer 1: The context window

Start here, because it's free. Everything the agent knows right now lives in its context window: the prompt, the instructions, whatever's in front of it. This is working memory, the agent's consciousness, the thing it's actually thinking about this second.

Reads in
The full conversation
resent on every call
MODEL
Writes out

nothing written out

Your agent starts a task, reads the instructions, takes in whatever's in front of it. All in the window. Done.

The catch: the window is small and it vanishes the moment the run ends. Worse, the agent can't show its work, so it jumps straight to a conclusion and gets it wrong. That last part is what pushes you up a rung.

Layer 2: The scratchpad

It leaps before it reasons, so give it a scratchpad. A place to write intermediate notes, draft a hypothesis, list its steps before taking them. Think before you act. Still inside the window, but now it's deliberate.

Reads in

nothing new read in

MODEL
Writes out
Reasoning and scratch notes
into the window, before it answers

The agent writes: "Working hypothesis, this looks like case X. Steps: verify A, then B, then decide." It reasons out loud, and the conclusions get noticeably better.

Then you restart the process and it's all gone. Every note, every half-finished thought, wiped. It starts the whole task over from scratch. There's your next problem.

Layer 3: Persistent state

A restart wipes everything, so give it real storage. A database, a key-value store, something the agent reads from and writes to that survives the process ending. This is the notebook you control. Now it can save "Task #42, step 3 of 6," die, wake up, and pick up exactly where it left off.

Reads in
Saved task state
from your datastore
MODEL
Writes out
Updated task state
back to your datastore

This is the layer most teams skip, and it's why their agents feel amnesiac. They jump straight to the fancy stuff and never give the agent a place to put its keys down.

But state alone is dumb storage. It remembers what happened, not what it meant. Run it again and it repeats the exact mistake it made last Tuesday, because it stored last Tuesday as data, with no sense of it as an experience. Which is exactly what sends you up the next rung.

Layer 4: Episodic memory

It keeps repeating its own mistakes, so start keeping a journal. Every action, every observation, every outcome, written down. Now when a new task starts, the agent can look back and ask, "how did task #17 go?" Retrieve by recency, or by similarity to the current situation.

Reads in
Similar past runs
pulled from the journal
MODEL
Writes out
This run's outcome
appended to the journal

This is episodic memory, a record of what happened to you. It's wildly useful, and it's also where things start to rot. Fast-forward a few hundred runs and the journal is enormous. Every retrieval drags back a pile of vaguely-related old runs, most of them irrelevant, and the actually-useful patterns are buried in the noise. Time to climb again.

Layer 5: Consolidated memory

The journal is huge and noisy, so do what your own brain does when you sleep. Consolidate. Take the pile of episodes and distill them into lessons. "This signal usually means X." "Last time I tried Y, it failed for this reason." Compact, structured, the patterns with the noise stripped out.

Reads in
Distilled lessons
from the lessons store
MODEL
Writes out
Refined lessons
merged in over time

This layer gets skipped, and it matters more than any of them, because memory is really a write problem. Everyone reaches for better retrieval, and retrieval over the wrong memory just gives you faster wrong answers. The hard, valuable work is on the write side. What earns a place? What gets compressed into a one-line lesson? And the hardest question of all: what do you forget?

We'll come back to forgetting. First, the rung everyone wants to start on.

The RAG reflex

If your agent is forgetting, your first instinct will be to bolt on a vector database. It's almost always wrong. Walk the ladder from the bottom first: context, scratchpad, state, episodic, consolidated. Each one is cheaper and more reliable than the rung above it. Most amnesia comes from a missing layer 3 or layer 4, long before retrieval enters the picture.

Layer 6: Retrieval (the one they call RAG)

Here's the rung the entire industry starts on, and it should be the last. Retrieval, RAG, whatever you call it: pull relevant chunks out of a big store on demand, by meaning. Your agent finally has a knowledge corpus too big to hold any other way, so it searches it when it needs something specific.

Reads in
Matching chunks
vector search over the corpus
MODEL
Writes out

nothing written out

It works. It has a real place. But understand what you're buying. Retrieval is the heaviest, most fragile layer in the stack to run. A vector database, an embedding pipeline, retrieval tuning, drift as your corpus changes over time. You don't reach for it because your agent is "forgetting." You reach for it only when the five rungs below genuinely can't carry the load, when there's a real external corpus too big to hold any other way. Most teams install it first and then can't figure out why their agent still feels dumb. It's because they skipped the ladder.

Forgetting on purpose

Now back to the hardest question. What do you forget?

A memory that never forgets is useless. Every run you log, every episode you keep, every lesson you write, the haystack grows and the needle gets harder to find. And the damage runs deeper than search. Stuff more into the context and the model's recall actively rots: its attention spreads thin and the wrong detail starts calling the shots. Past a point, more memory actively hurts. An agent that remembers everything effectively remembers nothing. Good memory systems forget on purpose. They compress old episodes into lessons and drop the raw logs. They decay what hasn't been touched in a while. They evict what isn't earning its place. Forgetting is a deliberate design decision, and getting it right is what separates a memory system that helps from one that slowly chokes.

The model retrieves. The harness decides what's worth keeping.

The cheat sheet

The whole ladder in one place: when to reach for each layer, and the trade you make.

LayerUse it whenUpsideDownside
1. Context windowAlways, it's the baselineZero infra, instantTiny, ephemeral, over-stuffing hurts
2. ScratchpadThe task needs real steps before an answerBig quality lift, still no infraEats tokens, wiped on restart
3. Persistent stateWork must survive a restart or span runsContinuity, you own and query itYou maintain the schema, it's dumb storage
4. EpisodicIt repeats past mistakes, or past runs would helpLearns from experienceGrows fast and noisy, retrieval drags back junk
5. ConsolidatedThe journal's too big, you want distilled patternsCompact, generalizes, reusableHardest to get right, bad lessons bake in
6. Retrieval / RAGBig external corpus, knowledge it never metUnbounded knowledge, no window stuffingHeaviest, most fragile, reached for too early

Read down the Downside column and you see the pattern: every rung up buys you something and costs you something. The craft is knowing which trade you actually need.

The whole picture

That's the ladder. Six layers, cheapest to richest, climbed one trigger at a time. Context is what you're thinking. The scratchpad is thinking out loud. State is a place to put things down. Episodic is a journal of what happened. Consolidated is the lessons you drew from it. Retrieval is borrowing from a library when your own shelves aren't enough.

Notice how little of that is the model. The model reads and writes the memory. Everything that decides what gets kept, what gets compressed, what gets forgotten, that's engineering. Memory is one of the harness's organs, and like the rest of them, it's mostly code, not prompting.

When I build these, I don't start at layer 6. I start at layer 1 and listen for the trigger. The craft is knowing which layer you're standing on, and what's telling you to climb.

Author: Glenn Pray