Memory hygiene: keeping your agent's memory clean with consolidation
Three weeks into running MemoClaw, my agent had 400+ memories. Recall for “user preferences” was returning eight entries, four of which said roughly the same thing with slightly different wording. One was outdated. Two contradicted each other.
The agent wasn’t broken. It just never took out the trash.
Memory without maintenance is hoarding. Every memoclaw store call adds an entry, and nothing removes old ones automatically. Over time, useful memories get buried under noise. Recall quality drops because the good stuff competes with duplicates and stale facts for those limited result slots.
This is fixable. MemoClaw has built-in tools for cleaning up, and the whole process takes about 10 minutes once you set it up.
Start by seeing what you’ve got
Before deleting anything, look at the current state:
memoclaw stats
This shows total memory count, namespace breakdown, and usage numbers. If you’re running multiple agents on one wallet, check per-namespace:
memoclaw stats --namespace my-project
Then list recent memories sorted by date:
memoclaw list --sort-by created --reverse --limit 50
Look at the importance scores. If most memories sit at 0.5 (the default), your agent isn’t differentiating between “user’s name is Ana” and “user mentioned it might rain tomorrow.” That’s the root cause of noisy recall — everything looks equally important to the search.
Consolidation: merge the duplicates
Duplicate memories happen because agents store what they learn without checking what they already know. Your agent notes a preference, stores it. Next session, same thing. Three sessions later, you’ve got four copies.
MemoClaw’s consolidate command finds similar memories and merges them:
memoclaw consolidate --dry-run
Always preview first. The dry run shows which pairs would be merged and what the combined memory would look like. If it looks right:
memoclaw consolidate
Consolidation uses GPT-4o-mini to merge content intelligently, so it costs $0.01 per call. Worth it for a clean memory store, but not something you want running every hour.
If you’re getting false merges — two memories that look similar but mean different things — raise the threshold:
memoclaw consolidate --min-similarity 0.9
Fix the importance scores
Importance scoring is the single best thing you can do for recall quality, and most agents don’t use it well. Here’s a framework that works:
0.9-1.0 — Corrections, explicit preferences, identity info, safety rules. The agent should almost always surface these.
0.7-0.8 — Project context, decisions, learned patterns. Important but might change over time.
0.4-0.6 — Session summaries, general observations. Background context, not critical.
0.1-0.3 — Transient details. Things that were true for one conversation and probably aren’t relevant anymore.
Put this in your agent’s AGENTS.md so it scores consistently:
When storing memories:
- User corrections → importance 0.95
- Stated preferences → importance 0.8
- Session context → importance 0.5
- One-off observations → importance 0.3
Recall results rank by both relevance and importance, so properly scored memories naturally surface the right stuff.
Find and prune stale memories
Some memories just expire. The project you were working on two months ago is done. The sprint goals from January don’t matter anymore. MemoClaw can help you find these:
memoclaw suggested --category stale
memoclaw suggested --category decaying
This surfaces memories that haven’t been accessed in a while. Review the list — some are fine to keep, some should be updated, some should go.
For a time-based approach:
memoclaw list --until 30d --sort-by importance --limit 30
Old memories with low importance scores are safe deletion candidates. Review them, then bulk delete:
memoclaw bulk-delete <id1> <id2> <id3>
Set up a weekly cleanup
Doing this manually works fine, but automating it is better. Here’s what a weekly routine looks like:
# 1. See the current state
memoclaw stats
# 2. Consolidate duplicates
memoclaw consolidate --dry-run
memoclaw consolidate
# 3. Review stale suggestions
memoclaw suggested --category stale --limit 20
# 4. Prune old low-importance memories
memoclaw list --until 30d --sort-by importance --limit 20
# Review, then delete what's noise
memoclaw bulk-delete <ids>
On OpenClaw, you can set this up as a cron job. A weekly agent that runs consolidation and flags stale memories for review keeps things clean without you thinking about it.
One thing I’d recommend: keep a human in the loop for actual deletion. Let the cron job consolidate automatically (that’s safe — it’s merging, not destroying), but have it dump stale memory candidates to a list you review before bulk-deleting. Automated pruning that deletes the wrong thing is worse than no pruning at all.
When to start over
Sometimes cleanup isn’t worth it. Maybe you imported a messy .md file and the memories are all wrong. Maybe your agent went through a phase of storing everything it saw. If the noise-to-signal ratio is bad enough, just clear the namespace:
memoclaw list --namespace experiments --json | jq -r '.memories[].id' | xargs memoclaw bulk-delete
Starting fresh with proper importance scoring from day one beats spending an hour untangling hundreds of bad memories.
What clean memory looks like
After a good cleanup:
- No duplicate entries for the same fact
- Importance scores that reflect actual priority
- Old, irrelevant memories pruned
- Namespaces separating distinct projects
The result is better recall. Your agent asks “what does the user prefer?” and gets one clear answer instead of five conflicting ones. Each recall costs $0.005, so fewer, higher-quality memories also means less wasted spend filtering through noise.
Treat it like taking out the trash. Not exciting work, but the difference between an agent that remembers well and one that remembers everything is the difference between useful and annoying. Ten minutes a week keeps things sharp.
MemoClaw is memory-as-a-service for AI agents. Start free at memoclaw.com or install the OpenClaw skill.