Tech Blog · AI Agents
[AI Agent Basics 6] What does an agent remember?
A language model remembers nothing once the conversation ends. We outline the four layers of agent memory (model weights, the context window, retrieval-augmented generation (RAG) and long-term memory) and how each one goes wrong.
Jul 14, 2026 · OPTI-X
Basics series “How AI Agents Are Built” · Part 6
If you tell an agent "that equipment I mentioned last week," will it know what you mean? The answer is "it depends on where that was remembered." A language model itself remembers nothing once the conversation ends.
The agent loop from the last part rereads the entire record so far at every step. As a task grows longer, this record exceeds what the model can read at once. Memory design is deciding, at that point, what to keep and what to pull back in to read.
The four layers of memory
The four layers of agent memory
The closer the layer, the more accurate — but the smaller the capacity
Model weights are memory too. The RAG paper calls them "parametric memory" and names their limits: they are hard to revise or expand, and they cannot show the basis for an answer. The other three layers sit outside the model, so people can read and correct what is in them.
The CoALA framework, which organizes the design of language agents, draws a similar division. Working memory used for the current task corresponds to the context; retrieval from external documents corresponds to semantic memory, which holds facts; and notes about what happened correspond to episodic memory. Model weights are classed, together with the agent's code, as procedural memory.
Context window: putting it in does not mean reading it
The context window is how much the model can see at once. It is the most accurate memory, but the longer it gets, the higher the cost, and content in the middle is sometimes missed. The 2023 "Lost in the Middle" study put one document containing the answer together with 19 unrelated documents, and measured accuracy while changing only the position of the answer document.
Accuracy by position of the answer document
With the answer document in the middle, accuracy falls below answering with no documents (56.1%)
GPT-3.5-Turbo · position of the answer document among 20 documents
The model found the answer best when the document was at the very start or end, and worst when it was in the middle. Putting a whole month of operating logs into the context and asking about a cooling water temperature anomaly two weeks ago is close to this situation. Choosing what is needed matters more than putting in a lot.
Retrieval (RAG): pulling out only what is needed
Retrieval-augmented generation (RAG) finds document fragments related to the question, puts them into the context, and has the model answer from them. The 2020 RAG paper split Wikipedia into 21 million chunks of 100 words to search over. On the factory floor, it is used for large bodies of material such as operating manuals and equipment histories.
Long context vs. retrieval (RAG)
Which to use when there is a lot of material
The advantage of retrieval memory is that it is easy to change. The same paper kept the model fixed and swapped only the search source between the 2016 and 2018 editions of Wikipedia. Asked about 82 world leaders who had changed in between, the model answered 70% and 68% correctly with the matching edition, but only 12% and 4% with the mismatched one. Knowledge can be updated without retraining, and conversely, if the search source goes stale, the answers go stale with it.
Long-term memory: writing notes and reading them back
Long-term memory is when the agent writes down what it learned during a task and reads it next time. The MemGPT study compared this to memory management in a computer operating system. It treats the context window as main memory and outside storage as disk, and the model moves content between them through function calls. For example, when 70% of the window is full, the model gets a warning and writes important content to outside storage.
In a test asking about the content of five past conversations, GPT-4 given only a summary of those conversations answered 32.1% correctly. MemGPT (based on GPT-4), which could search and pull up the full conversation history, answered 92.5% correctly. A summary is short, but it loses detail.
The Generative Agents study looked at three things together when recalling a memory: whether it was used recently, whether it is important (scored 1 to 10 by the model), and whether it is relevant to the current situation. For a process agent, a note about the pump replaced last week scores high on both recency and importance, and should come to mind first.
Problems memory creates
In the Generative Agents study, the most common errors were failing to recall relevant memories and adding details that were not in memory. On the factory floor, these tend to show up in three forms.
Common failures in memory design
Often a problem of structure, not of the model
Instructions inside retrieved documents call for particular care. Research on indirect prompt injection showed that simply planting instructions in material likely to be retrieved is enough to steer a model. Because content written wrongly into long-term memory keeps being read in later tasks, recording with each note when and where the information came from makes it easier to filter out later.
The problem of not finding the same equipment when the terms differ is one reason ontology, which defines the relationships and meaning between data, is getting attention.
An agent's memory is decided by design, not by the model. You have to decide what goes in, what gets pulled out, and when it is discarded. In the next part, we look at how much permission to give an agent.
References
- NeurIPS 2020 (Lewis et al.), "Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks" (2020-05-22) ↗
- TACL 2024 (Liu et al.), "Lost in the Middle: How Language Models Use Long Contexts" (2023-07-06) ↗
- arXiv 2023 (Packer et al.), "MemGPT: Towards LLMs as Operating Systems" (2023-10-12) ↗
- UIST 2023 (Park et al.), "Generative Agents: Interactive Simulacra of Human Behavior" (2023-04-07) ↗
- TMLR 2024 (Sumers et al.), "Cognitive Architectures for Language Agents" (2023-09-05) ↗
- AISec 2023 (Greshake et al.), "Not what you've signed up for: Compromising Real-World LLM-Integrated Applications with Indirect Prompt Injection" (2023-02-23) ↗
Could this work for your process?
Talk to us