StackLift
All terms

Glossary

Agent memory

How an AI agent keeps information across steps and sessions: short-term context plus stored long-term facts.

Agent memory is the set of mechanisms that let an AI agent retain information beyond a single model call. Short-term memory is the working context of the current task, and long-term memory is information stored outside the model, such as past interactions, user preferences or learned facts, and retrieved when relevant.

Language models are stateless: they only see what is sent in each request. Anything an agent seems to remember was either included in the prompt or looked up from storage and put there.

Long-term memory is usually built with the same pieces as [RAG](/glossary/rag): a database, often with vector search, plus rules for what to save, what to retrieve and what to forget.

Memory improves continuity and personalization, and it adds privacy, accuracy and security questions: what is stored, who can see it, and what happens when it is wrong.

Start in 60 seconds

Put this to work on your project.

Get an AI-assisted, architect-reviewed scope, cost range, and timeline. Free, no login.

The complete guide

Agent memory: the complete guide

Updated November 18, 2026 ยท Published by , Founder, StackLift AI. Written with AI assistance; how we make content.

Short answer

Agent memory is how an AI agent keeps information between steps and across sessions. Because language models only see what is sent in each request, memory is built by saving facts outside the model and putting the relevant ones back into the prompt. It adds continuity and personalization, and it adds privacy and accuracy questions.

What is agent memory?

Agent memory is whatever lets an AI agent act on information it did not receive in the current request. If an assistant remembers that you prefer short answers, that a ticket was escalated yesterday or that a step in a workflow already finished, something stored that fact and something brought it back.

The model itself does not remember. A large language model is stateless: each call starts fresh and sees only the text sent to it. Memory is therefore an engineering layer around the model, made of storage, rules for what to save, and rules for what to retrieve and when.

That layer decides how an agent feels to use. A good one makes the agent consistent and helpful over time. A careless one makes it repeat itself, recall the wrong thing or hold data it should not.

Why does agent memory matter for a business?

Without memory, every conversation starts from zero. Users repeat their situation, agents redo finished work, and long tasks lose track of what they already tried. With memory, an agent can carry a task across days, follow a customer's history and learn the preferences of a team.

  • Continuity: a support agent knows what happened in earlier tickets without asking again.
  • Personalization: an assistant remembers format, tone and recurring choices.
  • Long-running work: a workflow can pause for an approval and resume with its state intact.
  • Efficiency: the agent does not re-fetch or re-derive facts it already established.
  • Accountability: a record of what the agent knew and did supports review and audit.

The same capability brings risk. Stored data can be wrong, outdated, private or planted by an attacker, so memory needs design, not just a database.

What types of agent memory are there?

Researchers borrow words from human memory, and the labels are useful as long as you remember they describe software patterns.

Types of agent memory
TypeWhat it holdsWhere it livesExample
Short-term (working)The current task: recent messages, tool results, the planIn the prompt, within the context windowThe last ten turns of a chat
Long-term: episodicRecords of past events and interactionsDatabase, often searchable by meaningWhat happened on a customer's last three tickets
Long-term: semanticFacts and preferencesDatabase or key-value storeThis user prefers weekly summaries
ProceduralHow to do things: instructions, playbooks, learned routinesPrompts, rules, tool definitionsThe steps for handling a refund
Shared or team memoryInformation several agents read and writeA shared store with access rulesA case file used by research and drafting agents

Most business agents need short-term memory and a small amount of semantic or episodic memory. Procedural memory is usually written by engineers and changed through review, not learned on the fly.

How does agent memory work, step by step?

  1. A request arrives, and the agent assembles a prompt from the instructions, the recent conversation and the task state.
  2. Before calling the model, the system searches long-term storage for items relevant to the request, often with embeddings and vector search.
  3. The retrieved items are filtered by permission and relevance, then added to the prompt in a short, labeled form.
  4. The model responds or calls a tool, and the result is added to the working context.
  5. When the context gets long, older turns are summarized or trimmed so the important parts still fit.
  6. At a defined point, such as the end of a task, the system decides what is worth saving and writes it to long-term storage with a source and a date.
  7. Old or low-value entries are merged, expired or deleted on a schedule.

Retrieval here uses the same pieces as RAG, and the same embeddings and chunking ideas apply. The difference is the content: RAG usually reads a document library, while memory stores what the agent itself learned or was told.

Agent memory vs. RAG vs. a bigger context window

These three get mixed up. They solve related problems in different ways, and many systems use all of them.

Memory compared with neighboring ideas
ApproachWhat it doesStrengthLimit
Large context windowPuts more text in each requestSimple, nothing to maintainCost and latency grow; relevant facts can get buried
RAGRetrieves from a document library at question timeGrounds answers in approved sourcesReads documents; does not record what the agent learned
Agent memorySaves and recalls facts from the agent's own experienceContinuity across sessions and tasksNeeds rules for saving, checking and forgetting
Fine-tuningChanges the model's weightsTeaches style or narrow skillsSlow to update; not a good place for facts that change

A bigger window helps, but it is not memory. Anything outside the window is still forgotten, and filling it with everything is slow and costly. For facts that change, retrieval beats fine-tuning, which is a poor way to store information you need to update.

What are real examples of agent memory?

  • A customer support agent that recalls the product a customer owns, their open issues and what was already tried.
  • A sales assistant that remembers the stakeholders on a deal and the objections raised in earlier calls.
  • An internal helpdesk agent that keeps a user's device and access context so it stops asking the same questions.
  • A coding agent that records project conventions and the reason a past change was rejected.
  • A research agent that stores sources it has already reviewed so it does not read them again.
  • A workflow agent that keeps a task's state while it waits days for a person to approve.

In each example, the saved items are narrow and useful. None of them is a transcript of everything. Saving less, with a clear reason, is usually the better design.

What are the risks of agent memory, and how do you control them?

Persistent memory turns a stateless tool into one that accumulates data, so it deserves the same care as any store of customer information.

Memory risks and controls
RiskWhat goes wrongControl
PrivacyPersonal data is kept longer or shown to the wrong personSave only what is needed, set retention limits, scope memory per user, allow deletion
Wrong memoriesA mistaken fact is saved and reusedStore sources and dates, let people review and correct entries
Stale factsA preference or status changed but the old value is usedExpire entries and prefer recent, verified data
Memory poisoningAn attacker plants instructions or false facts in stored contentTreat memory as untrusted input; see prompt injection
Cross-user leakageOne user's data appears in another's sessionEnforce permissions at retrieval, not only at the model
Runaway growthMemory gets large and noisy, hurting quality and costSummarize, merge duplicates and delete on a schedule

Permissions need special care. The agent should only retrieve what the current user is allowed to see, and that check belongs in code, not in the prompt.

How do you design memory for an agent?

  1. Decide what the agent needs to remember and why. If you cannot name the benefit, do not store it.
  2. Separate working state for the current task from long-term facts, and keep them in different structures.
  3. Choose storage to match the data: a relational database for structured state, a vector index for fuzzy recall, or both. PostgreSQL with pgvector covers many cases.
  4. Define write rules: who or what may save a memory, when, and with which source and date.
  5. Define read rules: how many items to retrieve, how to rank them and how to apply permissions.
  6. Add retention and deletion, including a way to honor a user's request to be forgotten.
  7. Log what was retrieved for each answer so you can explain and debug behavior.
  8. Test memory behavior in your agent evaluation set, including stale, conflicting and poisoned entries.

How do you know memory is helping?

Look at behavior, not storage size. Users should repeat themselves less, and agents should redo less finished work. Review samples of retrieved items to see whether they were relevant, current and allowed for that user.

  • Recall quality: when a saved fact would help, does the agent use it?
  • Precision: does it avoid pulling in unrelated or outdated items?
  • Correction rate: how often do people edit or delete stored entries, and why?
  • Task continuity: do long-running tasks resume correctly after a pause?
  • Cost: do retrieved tokens stay small relative to the benefit?

If people keep correcting the same kind of entry, fix the write rule that created it rather than cleaning up after it.

What tools and frameworks support agent memory?

You can build memory with ordinary parts: a database, a vector index and some glue code. Frameworks add structure. LangGraph provides state and checkpointing for long-running graphs, and its store features hold longer-term items. LlamaIndex and LangChain offer memory modules, and dedicated libraries such as Mem0 and Letta focus on memory management for agents.

Vector storage options include pgvector, Qdrant, Weaviate and Pinecone. Cloud agent services from AWS, Google and Microsoft now include managed memory features too. Features and names change quickly, so pick by data-handling needs and portability. A thin layer of your own code around any of them keeps you from being locked in.

What does agent memory mean for cost and timeline?

Memory adds cost in three places: storage and retrieval, extra model calls to summarize or decide what to save, and extra tokens in every prompt that carries retrieved context. The build effort depends on how much you remember, how sensitive it is and how much access control you need.

A simple agent with task state only is a small addition. Per-user long-term memory with permissions, review screens and deletion is a larger piece of work. See AI agent costs for ranges, prompt caching for one way to trim repeated tokens, and the free estimate to scope your own case.

How does StackLift approach agent memory?

Memory is part of the architecture conversation in discovery, where an architect reviews scope before it becomes a commitment. We ask what must be remembered, who can see it and how it is corrected or deleted, then plan storage, access rules, logging and tests from sprint one.

Engineers own those decisions, and clients stay in control of their data. See AI agent development for how agent projects are delivered.

Questions people ask

Do AI models remember my past conversations by themselves?

No. A model only sees the text in the current request. Anything that looks like remembering comes from software that saved earlier information and added it back into the prompt.

What is the difference between short-term and long-term agent memory?

Short-term memory is the working context of the current task. Long-term memory is stored outside the model, such as past interactions or preferences, and retrieved when relevant.

Is agent memory the same as RAG?

They share technology, such as embeddings and vector search, but differ in content. RAG retrieves from a document library. Memory stores what the agent learned or was told during its work.

Can a bigger context window replace memory?

Only partly. A larger window holds more of the current session, but it does not carry information across sessions, and filling it raises cost and slows responses. Long-term needs still call for storage and retrieval.

How do I stop an agent from remembering sensitive data?

Decide up front what may be saved, filter or redact sensitive fields before writing, set retention limits and allow deletion. Also scope retrieval per user so one person's data never reaches another.

Can memory be attacked?

Yes. If an agent saves content from emails or web pages, an attacker can plant false facts or instructions that return later. Treat stored memory as untrusted input and keep tool permissions narrow.

Where should agent memory be stored?

Use a database that matches the data. Structured task state suits a relational database, and fuzzy recall suits a vector index. Many teams use PostgreSQL with pgvector to keep both in one place.

Does every agent need long-term memory?

No. Many useful agents only need task state for the current run. Add long-term memory when continuity across sessions clearly helps the user, and not before.

Sources

Sources and further reading

The standards, rules, research and official documentation this page draws on.