AI chat memory: rolling summaries and an in-reply memory panel
Why long role-play and writing chats run out of context, and two common fixes: a separate summarizer model, or a memory section the model maintains in each reply. Trade-offs and a template.
Verification
- Test environment
- Unknown
- Tested on
- Unknown
- Last updated
- 2026-11-20
Related models: DeepSeek-V4.1-Flash-1017
A model's "memory" is its context window, measured in tokens. The system prompt, the whole conversation history and the current turn all share it. Many current models offer around 1M tokens, which is plenty for short personal chats, but there is no fixed conversion to words, and a large window does not guarantee perfect recall.
Where it runs out
Role-play apps often carry a system prompt of thousands of words plus a lorebook, and each reply is long. Novel writing is similar, with replies of thousands of words. In those cases the window can fill after a hundred or so turns, and early details start to slip. Two approaches are common, and both cost extra.
Approach 1: a separate rolling summary
One model chats with you; the transcript is also sent to a second model (or a second call) that compares it with what came before and writes an updated summary, which the app stores and feeds back into later prompts.
- You can pair an expensive role-play model with a cheap summarizer such as DeepSeek, and summarize every few turns instead of every message to save money.
- The stored summaries can grow into a searchable knowledge base, so in theory this holds the most memory.
- Downsides: it is harder to set up (on AstrBot, plugins such as astrbot_plugin_mnemosyne help), and summaries can lose details or preserve earlier mistakes.
Approach 2: a memory section in every reply
Ask the model, in the system prompt, to output a short-term and long-term memory block at the start or end of each reply. The template below renders as a collapsible panel in front-ends that display HTML (replace the long-term part with your own story and character facts):
<details style="background-color:#e6f7ff;border:2px dashed #69b1ff;border-radius:10px;padding:12px 15px;margin-top:15px;">
<summary style="cursor:pointer;font-weight:bold;color:#0958d9;">Conversation memory</summary>
<p style="margin-top:12px;font-size:13px;line-height:1.6;color:#1677ff;">
<strong>[Short-term memory]</strong> (0/5)<br>
(List recent events. Compress when there are five.)<br><br>
<strong>[Long-term memory]</strong><br>
Replace this with the story, character and facts that must stay important.
</p>
</details>
It is easy to deploy, but it shares the same finite window, generating the notes every turn burns output tokens (more than approach 1), and later requests pay again to read them. As a simple summary it is also usually less thorough.
Choosing
Separate storage and retrieval give more control for more work; the in-reply panel is convenient but harder to audit. Neither creates unlimited, human-like memory on its own. Whichever you use, check summaries against the conversation and let users correct important facts.
Adapted from the XMLans blog: AI Chat Memory: Rolling Summaries and Persistent Context (Chinese original: AI记忆研究:如何尽可能持久记忆上下文).
Sources
- AI记忆研究:如何尽可能持久记忆上下文(星梦博客)www
.xmlans .com (opens in a new tab) · checked 2026-11-20 - AI Chat Memory: Rolling Summaries and Persistent Context (XMLans blog)en
.xmlans .com (opens in a new tab) · checked 2026-11-20