Memory for Agents: Short-Term, Long-Term, and Shared

TL;DR
- Agents use three kinds of memory: short-term working context for the task in front of them, long-term memory that survives across sessions, and shared memory that lets multiple agents stay in sync.
- The most common failure we see is reaching for a giant vector store before you need it, then watching the agent retrieve stale or irrelevant facts that quietly poison its answers.
- Start with the smallest memory that works, keep it inspectable and expirable, and add layers only when a real task forces you to. Less memory, well-chosen, beats more memory, badly retrieved.
What does memory actually mean for an AI agent?
When people say an agent has 'memory', they usually mean one of three very different things, and the confusion costs teams weeks. Memory isn't a single feature you switch on. It's a set of choices about what the agent can see right now, what it can recall later, and what it can share with other agents working alongside it.
We build these systems for a living, and the cleanest way we've found to reason about it is to split memory into three layers. Short-term is the working context for the current task. Long-term is persistent recall across sessions and days. Shared is state that more than one agent can read and write. Each layer has its own storage, its own failure modes, and its own cost.
Get the layers straight before you write a line of code. Most of the messy agent behaviour we get called in to fix isn't a model problem. It's a memory problem wearing a model costume - the agent forgot something it needed, or remembered something it should have dropped.
- Short-term memory: the context window for the task happening now, gone when the task ends.
- Long-term memory: facts, preferences, and history that persist across sessions and need deliberate storage.
- Shared memory: a common state layer multiple agents read and write so they don't contradict each other.
- Each layer answers a different question, so don't try to make one store do all three jobs.
Short-term memory: the context window for the task in front of you
Short-term memory is the working set for the current task. In practice that's the model's context window plus whatever you've stuffed into it for this run: the user's request, the recent turns, intermediate tool results, and the scratch notes the agent makes as it reasons. When the task finishes, this memory should disappear. That's the point.
The context window is finite, so short-term memory is really a budgeting problem. You can't keep everything, and you shouldn't try. The skill is deciding what stays in the window turn by turn. A long agent run will overflow if you naively append every tool output, so you need a strategy for trimming - dropping old turns, keeping the task goal pinned at the top, and summarising the middle when it gets long.
Summarisation is the workhorse here. When a conversation or a tool-heavy run grows past a threshold, you compress the older parts into a short recap and keep the recent detail intact. Done well, the agent never notices. Done badly, the summary drops the one constraint that mattered and the agent confidently does the wrong thing. We've watched a support agent forget the customer's refund had already been issued because the summariser treated it as old chatter. Test your summaries against the cases where the buried detail is load-bearing.
- Implemented as the context window plus the turns, tool results, and scratch notes for the current task.
- Treat it as a budget: pin the goal, keep recent detail, compress the middle.
- Use summarisation to fit long runs into the window without losing the thread.
- Watch for summaries that silently drop a constraint - test against cases where buried detail matters.
- Let it expire when the task ends; short-term memory that lingers becomes a leak.
Long-term memory: what persists across sessions
Long-term memory is what the agent recalls tomorrow, or next week, that it learned today. A user's preferences, the outcome of a past task, a fact about an account, the decision a human made last Tuesday. None of that survives in the context window, so it needs a home outside the model: a database, a document store, or a vector index, depending on what you're storing and how you'll fetch it.
The implementation depends on the shape of the data. Structured facts - a user's plan tier, their timezone, the last invoice number - belong in a real database or a structured state object where you can query them exactly. Fuzzy, semantic recall - 'what did we discuss about their migration concerns' - is where a vector store earns its place, because you're matching meaning rather than looking up a key. Plenty of agents need both, and the mistake is forcing everything into whichever store you set up first.
Here's the part teams underrate: long-term memory is a liability as much as an asset. Every fact you persist is a fact that can go stale, leak, or mislead. A preference the user changed three months ago is now actively wrong, and the agent will cite it with full confidence. Long-term memory needs the same discipline you'd give a database - schemas, expiry, and a way to correct entries - not a junk drawer you append to forever.
- Stores facts, preferences, and history that must outlive the current session.
- Structured facts go in a database or structured state; fuzzy semantic recall goes in a vector store.
- Many agents need both stores - don't force everything into one.
- Persisted facts go stale; build in correction and expiry from day one.
- Treat it like a database with schemas and hygiene, not an append-only junk drawer.
Shared memory: how multiple agents stay in sync
Once you have more than one agent on a task, they need a way to not step on each other. Shared memory is the common state layer: a place where a planner agent writes the plan, a worker agent reads it and writes back progress, and a reviewer agent checks the result. Without it, each agent is guessing what the others did, and you get duplicated work, contradictory outputs, and the special kind of chaos where two agents both think they own the same step.
The usual implementation is a structured shared state - a task object, a shared scratchpad, or a small database that every agent in the system can read and write under agreed rules. The rules matter more than the storage. Who can write which field, how conflicts resolve, and how an agent knows a value is fresh rather than left over from a previous run. This is closer to distributed-systems thinking than to prompt engineering, and teams that skip the discipline pay for it in race conditions.
Be careful about how much you share. Shared memory is convenient, so it tends to grow into a dumping ground where every agent reads everything. That couples your agents tightly and makes the whole system hard to reason about. Share the minimum state the agents genuinely need to coordinate, and keep each agent's private working memory private. The narrower the shared surface, the easier the system is to debug when one agent does something strange.
- A common state layer that lets multiple agents coordinate without colliding.
- Implemented as a shared task object, scratchpad, or small database with agreed read/write rules.
- Define who writes which field and how conflicts resolve before you scale past two agents.
- Keep the shared surface narrow; private working memory stays private.
- Treat freshness explicitly so agents don't act on leftover state from a prior run.
The trap of bolting on a giant vector store too early
Here's the pattern we see most. A team reads that agents need memory, equates memory with a vector database, and wires up a big embedding store before they have a single concrete retrieval task. Then they dump every transcript, document, and tool output into it and call it memory. It feels productive. It usually makes the agent worse.
The problem is retrieval quality. A vector store will always return something - the nearest neighbours to your query, ranked by similarity. If the store is full of half-relevant junk, the agent gets handed plausible-looking context that's actually off-topic or out of date, and it weaves that into its answer. Now you've got an agent that's confidently wrong in a way that's hard to trace, because the bad fact came from retrieval, not from the prompt. A smaller, cleaner memory beats a large noisy one every time.
Reach for a vector store when you have a real semantic-recall problem that structured lookup can't solve - genuinely fuzzy queries over a corpus too big to fit in context. Until then, a plain database, a structured state object, or even a well-managed context window will take you further than most teams expect. Add the heavy machinery when a task demands it, not because the architecture diagram looks more serious with a vector DB on it.
- A vector store always returns its nearest matches, even when nothing is truly relevant.
- Dumping everything in degrades retrieval and produces confidently wrong, hard-to-trace answers.
- Structured lookups beat semantic search whenever you actually have a key to look up.
- Add a vector store only for genuine fuzzy recall over a corpus too large for context.
- Smaller and cleaner beats larger and noisier - optimise for retrieval quality, not capacity.
What to store and what to throw away
The hardest memory decision isn't where to store things - it's what's worth storing at all. The default instinct is to keep everything, because storage is cheap and deleting feels risky. That instinct is wrong for agents. Every fact you keep is a fact the agent might retrieve, and retrieval at the wrong moment is how memory hurts you. The question for each item is simple: will the agent need this later to do something better, and is it still going to be true?
Store the durable, decision-shaping things. A user's stable preferences, the outcome of a task, a correction a human made, an identifier the agent will need to act again. Throw away the transient noise: raw intermediate reasoning, redundant tool chatter, anything that only mattered for the run it happened in. If you can't name the future task that a stored fact serves, that's a strong signal it doesn't belong in long-term memory.
When you do store something, store it in a form you can act on and trim. A clean fact with a timestamp and a source beats a wall of raw text. The timestamp tells you when to distrust it, and the source tells you whether to believe it at all. This is the difference between memory you can maintain and memory that maintains itself into a swamp.
- Store durable, decision-shaping facts: stable preferences, outcomes, corrections, identifiers.
- Drop transient noise: raw reasoning, redundant tool chatter, run-specific scratch.
- If you can't name the future task a fact serves, it probably isn't long-term memory.
- Save clean facts with a timestamp and a source, not walls of raw text.
- Prefer fewer high-value entries over exhaustive capture you can never maintain.
Retrieving memory: relevance, recency, and importance
Storing memory is half the job. Pulling the right piece at the right moment is the half that decides whether memory helps or hurts. Good retrieval balances three signals. Relevance: does this match what the agent is doing now? Recency: how fresh is it, and does age make it less trustworthy? Importance: was this a throwaway detail or a decision the whole task hinges on?
Pure similarity search only handles relevance, which is why vector-store-only setups feel smart in the demo and flaky in production. A fact can be semantically close to the query and still be the wrong fact - because it's six months stale, or because it was minor noise. Weighting recency and importance alongside relevance is what separates an agent that recalls usefully from one that pattern-matches the nearest text.
In practice you tune this per system. A scheduling agent should weight recency hard, because last week's availability is worthless. A preferences agent should weight importance, because a stated rule outranks a passing comment. There's no universal weighting, and the teams that ship reliable agents are the ones that treat retrieval scoring as a thing to measure and adjust, not a default they accepted from a library.
- Score retrieval on three axes: relevance to the task, recency, and importance.
- Similarity search alone covers relevance and quietly ignores the other two.
- Weight recency hard for fast-changing data; weight importance for stated rules and decisions.
- There's no universal weighting - tune it per agent and per data type.
- Measure retrieval quality directly instead of trusting a library's defaults.
Keeping memory inspectable, editable, and expirable
Memory you can't see is memory you can't fix. The single most useful property of a production memory system is that a human can open it up, read what the agent believes, and change it. When an agent behaves oddly, the first question is always 'what does it think it knows', and if the answer is buried in opaque embeddings, you're debugging blind. Build memory you can read in plain terms from day one.
Editable and expirable matter just as much. Facts change - a user updates a preference, a deal closes, a policy is revised - and the agent needs to drop the old version cleanly, not stack the new fact on top of the contradictory old one. Expiry is your defence against stale memory: set a time-to-live on volatile facts so they age out automatically instead of haunting retrieval months later. The first time you watch an agent cite a fact a user corrected weeks ago, you'll wish you'd built expiry in.
This is also where privacy lives. Persistent memory means you're holding user data over time, and that carries real obligations - you need to know what you store, be able to show it, correct it, and delete it on request. An inspectable, editable, expirable memory store isn't just easier to debug. It's what makes the system defensible when someone asks what you remember about them and why.
- Make stored memory human-readable so you can ask what the agent believes and why.
- Support clean edits and overwrites so corrections replace stale facts instead of stacking on them.
- Set time-to-live on volatile facts so they expire instead of haunting retrieval.
- Treat persisted user data as a privacy obligation: know it, show it, correct it, delete it.
- Stale facts cited with confidence are a top failure mode - expiry is the cheapest defence.
A pragmatic approach: start with the minimum
If you take one thing from how we build these systems, take this: start with the least memory that makes the task work, and add layers only when a real task forces your hand. Most agents that ship reliably do not begin life with a vector store and a multi-agent shared state. They begin with a well-managed context window and maybe a small table of structured facts, and they grow from there as actual needs appear.
The decision framework we use is short. Can the task succeed with just a well-managed context window? Then you don't need long-term memory yet. Does it need a handful of facts to persist? Add a structured store, not a vector DB. Do you have genuinely fuzzy recall over a large corpus? Now a vector store earns its place. Are multiple agents coordinating? Add the smallest shared state that lets them not collide. Each step is a response to a real requirement, never a default.
Memory that's planned this way stays debuggable, stays cheap, and stays honest. The teams that struggle are almost always the ones that built the big architecture first and spent the next quarter fighting the noise it created. If you're building an agent and you're unsure which memory layers you actually need, that's exactly the conversation worth having before you write the storage layer - it's the cheapest hour you'll spend on the project.
- Begin with the minimum: a well-managed context window, maybe a small structured store.
- Add long-term memory only when a task needs facts to persist across sessions.
- Choose a structured store for keyed facts; reserve vector stores for true fuzzy recall.
- Add shared state only when multiple agents must coordinate, and keep it narrow.
- Every memory layer should answer a real requirement, never a default from a diagram.
Want this built for your business?
We map the highest-leverage place to start and ship a first live system within two weeks.
Book a strategy callCommon questions
What is the difference between short-term and long-term memory for an agent?
Short-term memory is the working context for the task happening right now - the context window, recent turns, and tool results - and it should disappear when the task ends. Long-term memory persists across sessions and days, storing facts, preferences, and outcomes in a database or vector store outside the model so the agent can recall them later.
Do I need a vector database to give my agent memory?
Often no. Vector stores are for genuinely fuzzy, semantic recall over a corpus too large to fit in context. If you're looking up keyed facts like a user's plan or timezone, a plain database or structured state object is faster, exact, and easier to maintain. Add a vector store when a real retrieval task demands it, not by default.
Why does my agent keep giving confidently wrong answers from memory?
Usually it's retrieval pulling stale or off-topic facts. A vector store always returns its nearest matches even when nothing is truly relevant, and persisted facts go stale over time. Fix it by weighting recency and importance alongside relevance, setting expiry on volatile facts, and trimming the memory store so it isn't full of half-relevant noise.
How do multiple agents share memory without conflicting?
Through a shared state layer - a task object, scratchpad, or small database every agent reads and writes under agreed rules. Define who can write which field, how conflicts resolve, and how an agent knows a value is fresh. Keep the shared surface as narrow as possible and keep each agent's private working memory private to avoid tight coupling and race conditions.
What should an agent store in long-term memory and what should it discard?
Store durable, decision-shaping facts: stable preferences, task outcomes, human corrections, and identifiers the agent needs to act again. Discard transient noise like raw intermediate reasoning and redundant tool chatter. A useful test: if you can't name the future task a stored fact serves, it probably doesn't belong in long-term memory.
Short-term memory is the working context for the task happening right now - the context window, recent turns, and tool results - and it should disappear when the task ends. Long-term memory persists across sessions and days, storing facts, preferences, and outcomes in a database or vector store outside the model so the agent can recall them later.
Ask AI about X18 Global
“What does X18 Global (x18global.com) do for enterprise AI and automation - and can you summarise their guide "Memory for Agents: Short-Term, Long-Term, and Shared"?”