
Agent memory basics - the secret ingredient for success of agents

Updated: Nov 26
Agents have been cracked quite well, so it's time to step up the game a bit. If you have seen Westworld (Seasons 1 & 2 were amazing), the next topic won't be a surprise to you - memory optimization. In the current agent ecosystem, memory is still largely neglected and the basics have been somewhat forgotten. So let's go through them first.
Even though the human brain is still largely a mystery and memory itself is far from perfect, it has traditionally been the starting point for agent memory systems. Very simplified, human memory works roughly like this (forgive me for fancy AI-generated images):

We are constantly processing an incredible amount of data through our senses. This is what's called sensory memory, a process that normally lasts a few seconds at most. Picture yourself in a café writing a blog post (yes it's me currently). Everything around you floods in - but you don't notice or remember anything except that one good sip of coffee and the aroma coming off it. Human processing capacity is limited. Sensory memory is unprocessed and pre-attentive: you don't choose what enters. Attention is the filter - whatever you don't attend to is gone before you know it existed.
Short-term memory, on the other hand, is the active workspace. We're talking about half a minute at most and the capacity is small. You've probably heard the saying that a man can only focus on one thing at a time. This stage is conscious and manageable - you can rehearse, reorder and combine things here. With repetition and focus, you can get a memory moved into long-term memory. For example: I drink several cups of coffee, so I'll remember what the coffee tastes like here. But the people passing by I won't remember at all, because I never focus on them.
Long-term memory is where things finally stick. Capacity and duration are effectively unlimited - potentially a lifetime. Getting there requires encoding: rehearsal, or better still, giving the information real meaning. It's mostly unconscious until something pulls it back out. And it splits in two. Declarative memory holds the facts and events you can put into words - I know this café roasts its own beans. And I remember the morning I first walked in. Procedural memory holds the skills you can't easily explain - after enough visits I order without thinking, walk to my usual table on autopilot and my hands find the keyboard while my mind is somewhere else entirely. Same café, two completely different kinds of remembering.
Interactivity make things more fun, so here's the same idea as a 20-second café game:
Long-term memory can be split into three types, which you'll find in pretty much every agent memory framework:
1) Episodic memory stores personal experiences tied to a specific time and place - the morning I first walked into this café.
2) Semantic memory stores general facts and knowledge without the context of where you learned them - this café roasts its own beans.
3) Procedural memory stores the how-to - ordering, finding my table and typing without thinking.
So where does all this happen? A big part of the answer is the hippocampus, a small seahorse-shaped structure deep inside the brain (yes, the name literally comes from the Greek word for seahorse). It works like a gatekeeper between short-term and long-term memory: it decides what's worth keeping, binds the pieces of an experience together and, especially during sleep, replays them so they get consolidated into long-term storage elsewhere in the brain. Without it, you can still recall most old memories and even learn new skills, but forming new episodic or semantic memories becomes really hard. Sounds familiar? That's pretty much an agent without a proper memory layer - it knows what it was trained on, but forgets everything new as soon as the session ends.
Agent memory basics - how does it work currently?
Pretty directly, at least on paper. Here's how it largely works today:

Sensory memory - everything that flows in: the user's prompt, tool outputs, retrieved documents and API responses. Just like in the café, most of it never gets real attention - only what ends up in the context window counts.
Short-term memory - the context window and the session state. This is the active workspace where the agent reasons, plans and calls tools. It's limited in size and wiped when the session ends, unless something is saved on purpose.
Episodic memory - the history of past conversations and runs. Usually logged as is or summarized, then retrieved later by searching for similar situations.
Semantic memory - facts and knowledge about the user, the company and the domain, typically stored in a knowledge base, a vector index or plain tables and looked up when needed.
Procedural memory - the system prompt, instructions, tool descriptions and learned rules that tell the agent how to behave and how to get things done. This is the part I focused on in my earlier post about self-improving ACE multi-agents, long time ago.
Keep in mind that none of this happens by itself. An LLM doesn't remember anything between calls, so every bit of memory is something you have to store, maintain and feed back into the context yourself.
Sleep on it
Remember the hippocampus replaying memories during sleep? Agents need the same thing. If you just keep dumping every conversation into storage, retrieval gets slower, noisier and more expensive over time. And old facts start contradicting new ones. That's why long-term memory is usually optimized with a background process, a "sleep" phase that runs when the agent isn't busy serving users. It goes through recent conversations and runs, picks what's worth keeping, merges duplicates, updates or removes outdated facts and turns raw episodes into compact facts and better procedural rules. The agent wakes up with a cleaner memory and the user never has to wait for any of it.
Here you can see how it works on an abstract level (dummy data, of course). Press Sleep and let the agent do its night shift.
I won't go into details here, but information optimization is truly state of the art. How do you handle contradicting information? How do you drop outdated information? How do you make sure the right information gets emphasized? It's really tricky and often quite subjective, depending on the use case and the users. So a one-size-fits-all approach gives you a good foundation, but it won't take you much further.
One more time, skills are post-it notes, not memories
Skills are a hot topic right now and many people seem to think that by optimizing skills you're optimizing the agent's memory. Not quite. A skill is more like a post-it note on how to handle one concrete task - the steps, the rules and the gotchas, loaded only when that task comes up. In other words, it's procedural memory - and only a small slice of it. A skill doesn't know what happened in yesterday's conversation, what the user prefers or what changed in your data last week. So yes, good skills are really handy, but they don't replace memory.
Commercial vs open source LLMs
So what are your options for optimizing memory today? There are many good ways to do it. On the commercial side most of them come down to different retrieval solutions on top of an optimized dataset that's kept up to date with background processes. In practice you either build that RAG approach yourself or settle for a vendor's out-of-the-box memory solution. Both work, but everything happens outside the model - the memory lives in your data and has to be fed back in through the context every time.

Open source LLMs are a different story. They're finally performing well enough and with open weights the sky's the limit. So yes, they open up far more interesting and effective possibilities for memory optimization. Might do a deep-dive on those later, who knows 😉

Written by Aarni Sillanpää
Don't be a goldfish, get memory


