AI Agent Memory: Using Decay Curves to Stop Context Loss A developer implemented a usage-reinforced decay engine based on the Ebbinghaus forgetting curve to prevent context loss in AI agents. The system assigns a strength score to each memory, applying exponential decay that slows with each access, and prunes memories below a threshold. In testing, the agent stopped repeating clarifying questions every 20 turns because core memories were reinforced enough to survive pruning cycles. AI Agent Memory: Using Decay Curves to Stop Context Loss To fix this, I implemented a usage-reinforced decay engine based on the Ebbinghaus forgetting curve. Instead of treating all memories as equal, the system assigns a "strength" score to every piece of stored information. The Logic Behind the Decay Engine The goal is to simulate human memory: information that isn't accessed fades away, but information that is frequently retrieved becomes "hardened" and resists deletion. 1. Initial Weight: Every new memory is stored with a base strength value. 2. Temporal Decay: I apply a decay function that reduces the strength score over time. 3. Reinforcement: Whenever the agent retrieves a specific memory via RAG /en/tags/rag/ Retrieval-Augmented Generation , that memory's strength is boosted. 4. Pruning: Once a memory's strength drops below a specific threshold, it's purged from the active context or moved to cold storage. Implementation Detail The core of the system relies on a modified decay formula. Instead of a linear drop, I used an exponential decay where the rate is slowed down by the number of times the memory has been accessed. python import math import time def calculate memory strength initial strength, last accessed, access count, decay rate=0.1 : elapsed time = time.time - last accessed The more times it's accessed, the slower it decays effective decay = decay rate / 1 + access count current strength = initial strength math.exp -effective decay elapsed time return current strength This approach transforms the memory from a simple sliding window into a dynamic priority queue. In real-world testing, the agent stopped asking the same clarifying questions every 20 turns because the "core" identity and constraint memories were reinforced enough to survive the pruning cycles. This is a much more robust AI workflow for anyone building long-term LLM agents who can't just rely on massive context windows to solve the "forgetting" problem. Next S3 to SNS: Real-time upload notifications → /en/threads/3159/