DEV Community

Why Your AI Agent Keeps Forgetting (and Getting Slower): 4 Memory Options and 3 Context Fixes

Frank Guan on November 17, 2026

Most AI agents have two memory problems. They forget what a user told them last week, and every turn costs more than the one before. Both come fro...
Collapse
 
kami_butt_69b922ade8de012 profile image
Agentic Affairs •

The memory-versus-retrieval split is the load-bearing distinction — RAG finds facts, but only a memory layer can say which fact is current, and the New York-to-San Francisco test makes that concrete. The 24 tokens of stored facts versus 1,400 for the whole conversation is the number that sells it. What happens when Memory Bank extracts a wrong fact — is there a correction path, or does the stale fact just keep winning until someone notices?

Collapse
 
izgorodin profile image
Edward Izgorodin •

The New York to San Francisco test checks one thing: that the newest value wins. Two more lines in the same script catch the stores that pass it for the wrong reason. After the move, ask "Where did I live before San Francisco?": a store that overwrote the fact has nothing to say, while one that kept both facts, with the date the first one stopped being true, answers New York. Then say "I am moving to Seattle in March" and ask "Where do I live now?": an updater that treats the latest statement as the current fact answers Seattle months early. The first line tests history, the second tests the difference between when a fact was said and when it becomes true.

Collapse
 
ayushdhanani369 profile image
Ayush Dhanani •

I use something else, and your RAG point is why. I build Aladdin, a job agent. A fresh worker reads the actual form for each application, instead of carrying a long chat history into it. It only uses facts from the user's own profile that are clearly known. If a question is reworded or the answer is not clear, it asks the user instead of reusing an old answer. That keeps a corrected fact from coming back as a stale one.

Collapse
 
ba796 profile image
brent alexis •

Interesting to see the rolling summary in there, because I live with it from the user side. I run my side project with an AI assistant, and when a long session runs out of room it gets summarized and carries on. That keeps the work going, but small details can drop out - an exact number, or a rule I gave it hours earlier.

What helped me was keeping my standing rules in a separate notes file that gets read at the start of every session. Things like "I do all the commits myself" or "check the live page after every push". They never live in the summary, so they can't get squashed. Pretty much your Memory Bank idea, just done by hand.

Did the demo check what the rolling summary leaves out after a long session, not just how small it gets?

This reply was drafted with AI help, edited by me.

Collapse
 
nexusfoundry profile image
Nexus Foundry •

The "NY then SF then where do I live" test is the right minimal case, and it exposes the thing retrieval-based memory can't fix: recency is a property of the fact, not the chunk. Vector search will happily return both "I'm in New York" and "I moved to San Francisco" with nearly identical scores, and something downstream has to decide which wins. RAG answers "what's similar," memory answers "what's current" — your table names that split correctly.

Two additions from running agents that deal with this daily:

  1. Whatever you store, keep valid_from/superseded_by on the fact itself, not just timestamps on the chunk. When the SF fact lands, the NY fact should be marked superseded at write time — otherwise you're relying on the model to notice the contradiction at read time, which is exactly the failure you're trying to fix.

  2. The rolling-summary fix has a subtle failure mode worth naming: summaries are lossy compaction of facts you didn't know were facts. "User prefers window seats" and "user is anxious about flying" compress identically into a summary token budget, but only one is a durable preference. If the summary is the only cross-session artifact, durable-but-quiet facts die first. That's the argument for Memory Bank-style extraction being a separate pipeline rather than a bigger window.

The 86% token reduction from a 40-word classifier window is real but I'd guess it doesn't survive contact with multi-intent utterances — "remind me to call mom and also what's the weather" needs more than the last 40 words of speech, though maybe not of text. Voice makes the window problem worse than it needs to be.

Collapse
 
mudassirworks profile image
Mudassir Khan •

the 40 word window at 86% fewer tokens is believable for an intent classifier, but i would want to know what it did to misclassification on turns where the intent started earlier than the window. in our streaming setups the cheap classifier was never the problem, the missed context was, so we logged every low confidence call next to the full transcript and tuned the window on real misses instead of a guess.

the 92 token rolling summary worries me a little too, since summaries quietly drop corrections like the New York to San Francisco move. did you test whether the summary and Memory Bank ever disagree on the current fact?

Collapse
 
saifuddin profile image
Saifuddin Ahmed •

Great breakdown, especially the line between retrieval and keeping a fact current. One thing I'd add from my work on speech for Sudanese Arabic: in a voice-to-action agent, memory is only as clean as the transcript feeding it. In our Whisper evaluation, text normalisation alone moved word error rate by about 11 to 13 points, mostly spelling variants of the same word. If a city name arrives in two or three spellings across sessions, Memory Bank may store them as separate facts or fail to replace the old one. And a 40-word window is not the same amount of meaning in every language: Arabic attaches pronouns and prepositions to the word itself. Did you try normalising transcripts before extraction, or sizing the window in tokens instead of words? Curious how Scribant handles code-switched speech.

Collapse
 
yonijd profile image
jonatan draganczuk •

I went through this in two stages.

First, with Gemini:

At first I used Gemini thinking its memory was very useful. Then I realized they didn't know how to implement it. It used it as context in almost everything, even when I didn't ask it to check memory. That made it slow for no reason. And when I really needed it, it didn't have indexed or tagged the section I wanted to locate. So, what's the point?

That's why I designed my own memory system for Gemini. A simple one, real and working, because the idea was different: not loading all the memory all the time, but going to fetch only what was tagged when it was needed. I'm going to tell that in detail in an article I'm preparing.

Then, with Waio:

The last straw was when I wanted to use Gemini to organize the publication of Waio, a local orchestrator I'm building for web AI. It was never aware of the project updates, or it didn't relate them. It talked about old versions as if they were current. For all that, I stopped using Gemini.

And that's why I designed a simple one for Waio, which worked 10 times better than Gemini's. But I left it halfway, because it's still under study. It requires more research, and implementing improvements in my program that I still don't know how to do.

The funny thing is that now with Meta AI the opposite happens to me: it only goes to memory when I ask it to, and it seems to work.

For me the key is not remembering everything. It's knowing when NOT to use memory, and when you do use it, finding the right thing fast

Collapse
 
digbijoylabs profile image
digbijoylabs •

One pattern that fixed both the forgetting and the latency creep for us was strictly separating conversational history from execution state.

Once you wire up 3+ tool servers, verbose JSON parameter schemas and raw tool stdout quietly eat half the attention budget before the model even plans the next step. Stripping uncalled tool schemas between turns and keeping only a compact typed state object (rather than replaying raw stdout every turn) cut token growth dramatically and stopped mid-workflow instruction drift.

Collapse
 
shamazkhan profile image
Shamaz Khan •

I've experienced a similar problem with AI coding agents, particularly after context compaction. Architectural decisions and engineering constraints gradually disappear, even though they haven't changed.

I wonder if we should distinguish between conversational memory and engineering policy. Memory can be compressed and updated, but certain constraints should persist independently and be enforced rather than simply remembered.

I've been exploring this through Stet, a small open-source experiment.

Do you see persistent policy enforcement becoming a separate architectural layer alongside memory and context management?

Collapse
 
jacob456t5 profile image
Jacob gheery •

The comparison between RAG and long-term memory is especially useful. I like how the New York-to-San Francisco example shows that retrieving relevant information isn't enough—the agent also needs to know which fact is current. The combination of a rolling window, session summary, and persistent memory seems like a practical way to reduce token usage without losing important context. Has anyone tried a similar approach in production with longer conversations and frequent changes to user preferences?

Collapse
 
toon_yo_6409502a9f557f6f0 profile image
Toon Yo •

चाय वाला उधार – डायलॉग

गुड्डू

भाव: ज़ोर से, सीना ठोंककर, शेखी बघारते हुए। "अमीर आदमी" पर ज़्यादा ज़ोर, आख़िर में हल्की इतराती हँसी।

डायलॉग: “आज चाय मेरी तरफ़ से! मैं अमीर आदमी हूँ।”

पप्पू

भाव: पहले 1 सेकंड रुकना। फिर थकी, सपाट, उबासी जैसी आवाज़। कोई जोश नहीं।

डायलॉग: “तू तो कल भी यही बोला था।”

चाचा

भाव: शांत और भारी आवाज़, चेहरे पर हल्की मुस्कान वाला लहजा। "कुल" पर थोड़ा ज़ोर और फिर रुकना।

डायलॉग: “बेटा, पहले पिछला उधार तो चुका दो। कुल... 340 रुपये।”

गुड्डू

भाव: घबराहट। गला सूखा हुआ, पहले हल्का सा थूक निगलने की आवाज़। "वो..." और "मैं..." के बीच रुकना, हकलाना। आख़िर में जल्दी और ऊँची घबराई आवाज़ में बात पप्पू पर डालना।

डायलॉग: “वो... मैं... प-पप्पू देगा!”

पप्पू

भाव: पूरे वीडियो में पहली बार आवाज़ ऊँची। "मैं?" सदमे और हैरानी से, फिर आवाज़ रुआँसी होकर "सिर्फ़ 20 रुपये" पर टूटी हुई।

डायलॉग: “मैं? मेरे पास तो सिर्फ़ 20 रुपये हैं!”

चाचा

भाव: इत्मीनान से, ठंडे फ़ैसले वाला लहजा, जैसे यह रोज़ की बात हो। हल्की सी मुस्कान।

डायलॉग: “तो 20 दो, बाकी बर्तन धोकर चुकाओ।”

गुड्डू

भाव: फुसफुसाकर, थका हुआ और पछताता हुआ। शुरू में लंबी साँस छोड़ने की आवाज़।

डायलॉग: “अगली बार पहले पैसे पूछ लेंगे।”

पप्पू

भाव: वापस पुराना सपाट, बेपरवाह अंदाज़। बोलने से पहले हल्की उबासी या साँस। पंच लाइन पर कोई भाव नहीं, यही हँसाएगा।

डायलॉग: “अगली बार चाय पीएगा कौन?”

चाचा

भाव: दूर से पुकारते हुए, आवाज़ में हँसी। थोड़ा ऊँचा ताकि पीछे से आता लगे।

डायलॉग: “कल फिर आना!”

Collapse
 
alphalabstudio profile image
Jenifa Alam •

Following Guru...

Collapse
 
melvinhawkins profile image
melvin hawkins • • Edited

The whole content at this page is worth reading. I really enjoyed it a lot and will share it at revive clinics. Keep posting such informative stuff.

Collapse
 
_59eb1ed69d7c5c0d916345 profile image
CHIVOX AI •

Interesting!

Collapse
 
alcax_9726bb0d7919304386c profile image
Alcax •

Great insights, At Alcax , we believe better memory and context management are key to building smarter, faster, and more reliable [AI agents]

Collapse
 
adam_brody_14cee1b70bf672 profile image
James Porter •

Interesting!