Our agent's memory hit 47,000 entries and started giving advice from three versions ago
I've been running the same agent for six months. Last week I looked at its memory system and found 47,000 entries. Most of them were garbage.
The agent remembered every API error from March. It had detailed notes about a bug that was fixed in April. It knew the exact wording of 23 different "file not found" messages. But when I asked it about our current deployment process, it gave me instructions from two versions ago.
Your agent's memory isn't getting smarter over time — it's getting noisier. Here's how to fix it.
The problem: Memory without expiration
Most agent memory systems work like this: write everything, read everything, hope the model figures it out. That works for a few hundred entries. At a few thousand, your agent starts drowning in its own history.
I watched our agent spend 40 seconds "thinking" about a simple task because it was processing thousands of irrelevant memories. The solution isn't a bigger context window. It's memory that knows when to forget.
Build memory tiers with different lifespans
Not all memories are created equal. Some should last forever. Others should expire after a week. Here's the tier system that fixed our agent's memory bloat:
- Core knowledge (permanent): API docs, system architecture, security policies
- Project memory (30-90 days): Current work, active bugs, team decisions
- Session memory (7 days): Error messages, debugging steps, temporary context
- Interaction memory (24 hours): Chat history, user preferences, conversation state
The key insight: tag memories when you write them, expire them automatically.
The expiration config that actually works
Here's the memory cleanup routine that runs every morning:
# Memory cleanup - runs daily at 6am # Delete session memories older than 7 days DELETE FROM memories WHERE type = 'session' AND created_at < NOW() - INTERVAL 7 DAY; # Archive project memories older than 90 days UPDATE memories SET status = 'archived' WHERE type = 'project' AND created_at < NOW() - INTERVAL 90 DAY; # Keep core knowledge forever # (no expiration for type = 'core')
But here's the part most people miss: you need manual override commands. Sometimes the agent needs to forget something immediately (like when you fix a bug), and sometimes it needs to remember something longer (like when a "temporary" workaround becomes permanent).
I added these commands to our agent:
forget <topic>— immediately delete all memories matching the topicremember <fact> for <duration>— store with custom expirationpromote <memory> to core— move from temporary to permanent storage
The cleanup that saved us 60% on inference costs
After implementing memory expiration, our agent's "thinking time" dropped from 40 seconds to 12 seconds. More importantly, it stopped giving outdated advice.
The agent now starts each day by running a memory cleanup routine. It deletes expired entries, archives old project context, and keeps only the memories that matter for current work.
Pro tip: Don't just delete expired memories — log what you're forgetting. I've caught several cases where the agent forgot something it should have remembered by reviewing the deletion logs.
The result: an agent that gets smarter over time instead of drowning in its own history. Memory that helps instead of hurts. And inference costs that stay reasonable even after months of operation.
Your agent's memory needs an expiration date. The question is whether you'll build one before it drowns in six months of accumulated noise.