Short-Term vs Long-Term Memory in AI Agents
Memory is what lets an agent behave consistently instead of treating every request as a fresh start. But “memory” is not one thing. Agents rely on at least two distinct kinds — a short-term working memory for the current task and a long-term store for knowledge that should survive across sessions. Confusing the two leads to agents that either forget too much or remember the wrong things.
Why agents need memory at all
A language model on its own has no memory between calls. Each time you invoke it, it starts from the context you hand it — nothing more. Without a memory system, an agent cannot carry information from one step to the next, let alone from one conversation to another.
Memory solves this by storing information outside the model and feeding the relevant parts back into context when needed. The design of that storage is one of the most important decisions in building an agent.
Short-term memory: the working space
Short-term memory holds what the agent needs right now: the current conversation, the goal it is pursuing, recent actions and their results, and intermediate notes. It lives in the active context window and is rewritten as the task progresses.
Think of it as a desk surface. Everything the agent is currently working on is laid out there, easy to reach. But the desk is limited in size — as the task grows, older items have to be moved aside or discarded.
Long-term memory: the durable store
Long-term memory holds information that should persist: user preferences, facts learned in earlier sessions, summaries of past work, and reusable knowledge. It lives outside the context window — in a database, a vector store, or a structured file — and is retrieved when relevant.
This is more like a filing cabinet. Things are stored away, not constantly in view, but they can be looked up when the current task calls for them. What lasts is what you deliberately save.
The key differences
The two kinds of memory differ on several dimensions:
- Lifetime — short-term memory lasts for one task or session; long-term memory spans sessions.
- Location — short-term lives in the context window; long-term lives in external storage.
- Access speed — short-term is instantly available; long-term requires a retrieval step.
- Capacity — short-term is bounded by the model’s context limit; long-term can be very large.
- Cost — short-term consumes context on every call; long-term costs storage and retrieval.
Understanding these trade-offs helps you decide what belongs where.
What should go into short-term memory
Keep the current task’s working state here: the goal, the plan, what has been tried, what worked, and what failed. Include recent conversation turns and the results of the latest tool calls.
Be disciplined. Anything that does not help with the current task is taking up space that could hold something useful. As the task progresses, summarize or drop completed steps rather than keeping every detail.
What should go into long-term memory
Save information that will be useful again: stable facts about the user, preferences expressed over time, decisions made in past projects, and distilled lessons from completed tasks. Store it in a form that can be found later — with clear labels or searchable representations.
Avoid saving raw conversation transcripts. They are noisy and hard to retrieve from. Instead, write concise summaries and structured facts that capture what actually matters.
The bridge between them
The most important design question is how information moves between the two kinds of memory. Two operations matter:
- Write — deciding what from the current task is worth saving for later. Save too little and the agent forgets; save too much and the store fills with noise.
- Read — deciding what from long-term storage to bring into the current context. Retrieve too broadly and you dilute the context; too narrowly and you miss what is relevant.
Good agents treat both operations as deliberate decisions, often made by the model itself with clear guidance.
A practical pattern
A common and effective setup works like this. Keep a compact working summary in short-term memory, updated as the task runs. Maintain a long-term store of structured facts and past summaries. At the start of a task, retrieve a small set of relevant long-term items and place them in context. At the end, extract anything worth keeping and write it back.
This gives the agent both continuity and focus: it remembers what matters without being weighed down by everything it has ever seen.
The bottom line
Short-term memory is the workspace for the task at hand; long-term memory is the archive of what should endure. Neither works well alone. Design the boundary between them carefully — what to keep close, what to store away, and how to move information across — and your agent will be both coherent in the moment and continuity-aware over time.
Get Ball — Ball
Get Ball