TL;DR:
Most long-running AI agent memory systems evict old context using a sliding window: if something hasn’t been touched in N turns, it’s gone. This treats a foundational fact stated once on turn 1 and a throwaway debug log from turn 40 as identical — whichever is older loses, no matter how many times either one has actually been used. I built a memory engine that scores retention using the Ebbinghaus forgetting curve, where every recall reinforces an item’s stability and pushes its eviction horizon out non-linearly. Across 50 seeded sessions, it held a 100% Foundational Recall Rate against a 0% rate for the recency-only baseline — and I traced the exact mathematical reason why, then found the specific failure case where its advantage disappears entirely.
Key Takeaways
The issue here is structural, not something you can tune your way out of. With a fixed recency window, you hit a hard mathematical wall: if you don’t touch an item within window_size turns, it’s wiped from memory. It doesn’t matter if it was the most heavily used item in the system five minutes ago—once it slips past that window, it’s gone.
Second, reinforcement compounds where recency fails. By letting retention scale with recall frequency, the decay engine pushes an item’s effective survival horizon out by orders of magnitude based on just a few early interactions.
Third, let’s be clear: this isn’t “better memory” across the board. To make sure this wasn’t a benchmark artifact, I built a failure-case test. When a fact is introduced once and never recalled, the decay engine performs identically to the baseline. That is the honest boundary of this mechanism.
Fourth, it is entirely deterministic. Everything relies on an explicit turn counter, not wall-clock time. To verify, I ran the suite on two different machines and operating systems—the diffed outputs were byte-identical.
Finally, always audit your benchmarks. Two hidden bugs almost invalidated this entire run. I’m breaking them down because catching these issues is the difference between data you can trust and data that quietly lies to you.
Complete code: https://github.com/Emmimal/memory-decay-engine/
The Fact That Outlived Its Own Window
Let’s look at how this actually plays out in practice. Imagine you are 150 turns into a session with an agent. On the very first turn, the user gives the agent a core rule, like a compliance requirement or a specific tech stack constraint. The agent references it a few times during the first thirty turns while getting oriented, but then the conversation moves on. For the next hundred turns, the agent is busy doing other things, like parsing logs, making one-off tool calls, and handling random side tasks.
Later in the session, well past that early window, you ask a question that depends entirely on that rule from turn one.
With a standard sliding window, you have already lost that rule. The window doesn’t know the rule is critical, and it doesn’t care that the agent already used it five times. It just sees a turn count that got too high and drops the data. That isn’t memory. It is just a countdown timer.
I ran this exact scenario across 50 seeded sessions. In this benchmark, the decay engine retained every foundational fact through the end of the session, while the recency-only baseline retained none. The result was consistent across all 50 seeds. Here is why that happens.
Who This Is For
This approach applies to any system where an agent needs to keep context across a long, multi-turn session. Think of coding agents working on multi-day tasks, customer support bots handling extended troubleshooting threads, autonomous research loops, or any pipeline where memory has to mean more than just the last few messages.
It matters most when your sessions follow a specific pattern. Something important gets established right at the start, then goes quiet for a long stretch while other work happens, and needs to still be active when it finally resurfaces.
In 2026, as agents increasingly run autonomously over hours or days—whether in software engineering, scientific research, or enterprise workflows—such usage-reinforced memory is becoming critical to avoid costly context loss.
