WisyLink Blog

AI agent memorycontext windowlong-term memorycontext engineeringretrieval

Agent Memory: How Context Is Kept Across Sessions

AI agent memory explained: working vs long-term memory, why bigger context windows fall short, and how agents retrieve, update and forget what they know.

10 min read
Agent Memory: How Context Is Kept Across Sessions

AI agent memory is how an agent carries useful information from one session to the next. Because a model's context window is finite, agents keep a short working memory for the current task and a separate long-term store of facts, events and preferences, which they retrieve selectively, summarize, update and deliberately forget.

  • Working memory holds the task at hand; long-term memory outlives the session and has to be retrieved on purpose.
  • A bigger context window doesn't remove the problem: models use information buried in the middle of long inputs less reliably.
  • Episodic memory records what happened, semantic memory what is true; mixing them turns one-off events into rules.
  • Retrieval precision matters more than storage size, because a wrong memory recalled with confidence does more harm than none.
  • Every stored fact needs a date and a source so it can expire or be overridden.
  • Forgetting is maintenance: decay, demote and delete on a schedule.

What is agent memory?

Agent memory is information an AI system keeps after a conversation ends and can bring back in a later one. A stateless assistant starts from zero every time: you explain your project, your preferences and your constraints again in each session. An agent with memory starts from what it already knows. That sounds like pure gain, but every remembered item has a cost, and the longer something is kept, the greater the chance it will be recalled at the wrong moment.

The research vocabulary is useful here. The CoALA framework (Cognitive Architectures for Language Agents, by Sumers, Yao, Narasimhan and Griffiths) describes a language agent with modular memory components and separates four kinds. Working memory holds what is active in the current decision. Episodic memory stores experience from earlier interactions. Semantic memory stores knowledge about the world and the agent itself. Procedural memory is how the agent acts, held partly in the model's weights and partly in the agent's code.

Consider a scheduling assistant that remembers "this client prefers morning calls". Storing that line is trivial. The hard parts are everywhere else: noticing that it is worth keeping, finding it again when a meeting request arrives, and dropping it when the client moves to another time zone. Cross-session memory is mostly an access problem, and the design effort collects on the retrieval side.

Working memory vs long-term memory

Working memory is the material of the current task: the request, the files open, the last few steps. It is fast to use but narrow, and it loses meaning when the task ends. Long-term memory is broad and durable, but only a small part of it is in front of the model at any moment. Keeping the two layers apart is a necessity. If temporary details leak into long-term storage, a one-off situation starts behaving like a permanent rule. If durable facts stay only in working memory, they vanish when the session closes and the agent relearns them every time.

Well-built systems define a promotion rule between the layers. A note moves from working to long-term memory only when it passes a threshold: it has proven useful more than once, it applies beyond the current task, or the person explicitly asked the agent to remember it. Too loose a rule fills long-term memory with noise; too strict a rule means the agent never learns.

Stateless assistants vs agents with long-term memory
DimensionStateless assistantAgent with long-term memory
Lifespan of informationEnds with the sessionExtends across sessions
Starting pointFrom zero each timeFrom what it has kept
Main riskRebuilding context again and againRecalling a stale or wrong memory
MaintenanceAlmost noneManaging staleness, conflicts and noise
Privacy surfaceSmallGrows with everything stored

Why a bigger context window is not enough

The context window is the amount of text a model can consider at once. Windows have grown dramatically, which invites a tempting shortcut: keep the whole history and let the model sort it out. Two findings argue against it.

First, models don't use long inputs evenly. In "Lost in the Middle" (Liu and colleagues, published in TACL), performance was often highest when relevant information occurred at the beginning or end of the input and degraded significantly when it sat in the middle, even for models built for long contexts. Second, more context can actively hurt. Anthropic's engineering team calls this context rot: as the window fills, the model's ability to recall information from it decreases, so context is a finite resource with diminishing returns.

So remembering turns into compressing. The common technique, which Anthropic calls compaction, summarizes a conversation near the limit and starts a fresh window from the summary. Compression always loses something, and you can't know in advance which detail tomorrow's question will need. Mature systems layer the two: recent history in detail, older history summarized, and the summary written with a purpose ("what would the next session need to continue this project?") rather than as a generic recap.

Episodic, semantic and procedural memory

Separating memory by job makes design decisions clearer, because each kind ages differently.

Episodic memory
What happened, and when: "on 3 March the client rejected the blue logo". It stays true forever as a record of the past, but its relevance to today fades.
Semantic memory
What is currently true: "the client's brand colour is green". It is useful precisely because it is general, and it can silently become false when conditions change.
Procedural memory
How to do things: the agent's instructions, tools and learned routines. It changes least often and is usually edited by people.
Retrieval precision
How often the memory the agent brings back is the right one for the moment.

The classic mistake is promoting an episode to a fact. A user once asked for a formal tone in a legal email; the agent stores "user prefers formal tone" and applies it to every casual message for months. Keeping the episode as an episode, with its date and context, avoids the overreach. Semantic facts, by contrast, need periodic re-checking, because nothing in them announces when they stop being true.

How do agents decide what to recall?

Storing is easy; choosing what to bring back is the real work. One influential design comes from the Generative Agents paper by Park and colleagues (UIST 2023). Its agents keep a complete record of experiences in natural language and retrieve them dynamically to plan behavior. Each memory is scored on three signals: recency, which decays exponentially from the last time the memory was used; importance, which the model rates from 1 (mundane) to 10 (poignant) when the memory is created; and relevance, measured as similarity to the current situation. The highest combined scores go into the prompt.

Whatever the formula, the measure of success is how rarely the wrong memory is recalled. A system that remembers nothing at least behaves as if it doesn't know. A system that recalls a stale fact builds on a faulty foundation and sounds sure of itself, and that silent error is harder to catch than an honest gap. Growth makes this worse: the more an agent stores, the more near-duplicates and contradictions compete at retrieval time.

Two habits help. Check validity before use: is this memory still current, and where did it come from? And when confidence is low, ask instead of assuming: "Last time you preferred morning calls; is that still right?" costs one message and prevents a wrong booking.

How should an agent forget?

Memories go stale. What was true last quarter may not be true now, and an agent that never forgets ends up arguing with its own past. Forgetting is what keeps memory useful. A practical order of priorities:

  1. Attach a date, a source and a confidence level to every stored item.
  2. Keep episodes and facts separate, so a single event never becomes a rule by accident.
  3. Let the weight of rarely used items decay over time instead of deleting them at once.
  4. When two memories conflict, prefer the one with the better source and more recent confirmation, and record that the older one was superseded.
  5. Re-check a memory's validity before acting on it; if in doubt, don't use it or ask.
  6. Give people a way to see, correct and delete what the agent remembers about them.

Soft decay and hard deletion serve different purposes. Fading a memory's weight pushes it into the background but leaves a way back if it turns out to matter. Deletion is final and is the right choice for anything sensitive, anything the person asked to remove and anything that was simply wrong.

Practical memory patterns you can use today

Most working agents combine a few simple patterns rather than one elaborate memory system. Anthropic describes three for long-running work: compaction, structured note-taking in which the agent regularly writes notes to a store outside the context window (a to-do list or a NOTES.md file) and reads them back later, and sub-agents that explore with clean context windows and return condensed summaries to a lead agent.

Common memory patterns and their trade-offs
PatternWhat it keepsGood forWatch out for
Structured notes fileDecisions, open tasks, key factsLong projects with one ownerNotes drifting out of date
Session summariesA compressed record of each sessionContinuing work days laterLost details nobody can recover
Searchable memory storeMany small records, retrieved by meaningAssistants serving many usersNear-duplicates and stale hits
Sub-agents with summariesOnly the condensed result of each sub-taskResearch and multi-step jobsSummaries hiding errors

If you are building an agent, start with the simplest pattern that could work: a notes file the agent reads at the start of each session and updates at the end. Add summaries when sessions get long, and add search by meaning only when the notes no longer fit. Each layer adds a new way to be wrong, so add it when the simpler one demonstrably fails, and test retrieval with a small set of "should recall" and "should not recall" cases.

Choosing what goes into the window at each step is the discipline our piece on context engineering as information architecture covers in depth. Memory gets harder again when several agents share it, as described in multi-agent orchestration, and the stakes rise once agents act on what they remember, the shift discussed in tool-using agents.

The same principles apply when you build an app by chatting with an AI. In WisyLink, each project (a link) has its own chat thread, and follow-up messages in that thread change the same app. Keep working in that thread instead of starting new ones, so the history of decisions stays attached to the project. Developers can do the same through the API by continuing a link with its id, as described in the API reference and our guide to the AI website builder API.

Don't rely on any chat history as your only memory, though. Keep a short written brief of the decisions that must survive (who the app is for, the rules for bookings or refunds, the tone of the copy) and restate them when you ask for a larger change. That brief is your semantic memory, and our article on spec-driven development explains why it deserves the same care as the product itself. Keep secrets out of the chat entirely: payment and email keys go under Integrations, where they are encrypted.

When you're ready to try it, start free and describe your first app in a single, well-structured message.

F.A.Q.

Frequently asked questions

Does a language model remember previous conversations on its own?
No. A model's weights don't change when you chat with it, so it has no record of earlier sessions by itself. Any memory you see in a product is an application layer: software that stores notes or past messages and puts the relevant ones back into the prompt. That is why memory behaves differently from product to product, and why some products let you view and delete what they keep.
What is the difference between RAG and agent memory?
Both retrieve text and add it to the prompt. Retrieval-augmented generation (RAG) usually searches a document collection that people curated in advance, such as a help center. Agent memory is written by the agent itself from its own interactions, so it also has to decide what to store, when to update a record and when to let it expire. The retrieval machinery can be the same; the write path and the lifecycle are what differ.
How do you give an AI agent long-term memory?
Start simple: have the agent write short, structured notes to a file or database outside the prompt, each with a date and a source, and load the relevant ones at the start of a task. Introduce semantic search later, once there are too many notes to load in full. Summarize finished sessions instead of storing full transcripts, and give users a way to see and delete what is stored.
What is context rot?
Context rot is Anthropic's name for the drop in a model's ability to recall information accurately as its context window fills up. Every extra token draws on a limited attention budget, so stuffing the window with old history can make answers worse. The usual remedies are compaction (summarizing and restarting), clearing old tool results, and keeping only high-signal material in the prompt.
Is a long context window better than a memory system?
They solve different problems. A long window helps within one session, but every call pays to process everything in it, and models tend to overlook facts buried partway through very long inputs. A memory system selects what matters and survives across sessions. Most capable agents combine both: a working window for the task at hand and a selective store for what should outlast it.
What should an AI agent never store in memory?
Secrets such as passwords and API keys, sensitive personal data the person hasn't agreed to share, and one-off instructions that shouldn't become permanent rules. Secrets belong in a dedicated, encrypted store. WisyLink follows that pattern: third-party keys are entered under Integrations, where they are encrypted and never shown again, rather than pasted into the chat.
Share