{"slug": "my-ai-agents-spend-10-minutes-every-night-rewriting-their-own-memory", "title": "My AI agents spend 10 minutes every night rewriting their own memory.", "summary": "A developer built Lorekeeper, an open-source memory layer for AI agents that uses idle-time reflection cycles to prune, merge, and link memories. The system achieves 84.6% Recall@1 and 96.6% Recall@5 on LongMemEval-S while keeping all data local. The approach, called 'local dreaming,' runs on a cron-based scheduler to maintain memory quality over time.", "body_md": "Every morning for three months, I re-explained myself to my coding agents.\n\nThe same preferences. The same project structure. The same \"no, we already tried that\" conversation. Fresh context window, zero memory of anything we'd discussed before.\n\nThen I built [Lorekeeper](https://github.com/jessira/lorekeeper) — an open-source memory layer for AI agents. Fixing the *storage* problem was the easy part. The hard part was making memory get *better* over time. Not just fuller. Sharper. Less noise.\n\nThe approach that surprised me: let the agent reflect on its own memory when it's not busy.\n\nThe first version was dumb storage. You save a memory, you find it later.\n\n```\nmemory.insert(\"user prefers snake_case for Python, camelCase for TypeScript\")\nmemory.search(\"naming convention\")\n# → [\"user prefers snake_case for Python, camelCase for TypeScript\"]\n```\n\nAfter a few weeks you've got hundreds of memories — old decisions you reversed, half-thoughts that went nowhere, conventions that changed three refactors ago. The useful stuff drowns. The more you save, the worse retrieval gets.\n\nWe tested against other systems and found recall dropped from ~80% to ~40% after just 200 stored memories. Storage without maintenance isn't memory — it's a junk drawer.\n\nLorekeeper uses a cron-based scheduler. Every few hours, when your agent isn't working, it runs a reflection cycle:\n\n```\n[03:15] lorekeeper: reviewing 347 active memories\n[03:15] lorekeeper: 12 memories have low utility scores (≤ 3.0)\n[03:15] lorekeeper: 3 memories are near-duplicates (similarity ≥ 0.92)\n[03:15] lorekeeper: merging \"prefers async/await\" + \"team uses async for I/O\"\n[03:15] lorekeeper: archiving \"old approach used callbacks\" (unused 47 days, score 1.2)\n[03:15] lorekeeper: done — 12 pruned, 3 merged, 1 archived (331 active)\n```\n\nEach cycle scores every memory by usefulness, merges duplicates, archives dormant noise, and links related facts. All on your machine, using your API key, with your auth.\n\n```\n# ~/.config/lorekeeper/cron.yaml\nschedule: \"0 */6 * * *\"\nactions:\n  - score_memories\n  - merge_duplicates\n  - archive_dormant\n  - link_related\n```\n\nI call this **local dreaming** — the agent reflects and consolidates during idle time, the way your brain processes the day's experiences while you sleep.\n\n| Week | What happens |\n|---|---|\n| 1 | Sparse but accurate. Every retrieval hits. |\n| 3 | Growing fast. Some noise creeping in. Retrieval less reliable. |\n| 5 | Feedback loop has stabilized. Noisy memories pushed down. High-value ones float up. Better than week 3 with 3x the volume. |\n\nThe benchmarks: 84.6% Recall@1, 96.6% Recall@5, 32.9ms average latency on LongMemEval-S with a local 384-dim embedding model. Zero data leaves your machine.\n\nThe dreaming cycles don't just prune noise. They surface connections I hadn't made. Last week it linked my error-handling middleware memory with an API versioning convention — 0.81 cosine similarity. I confirmed the link, and now pulling one surfaces the other.\n\nA static memory store can't do this. A cloud service won't see the connections in *your* project. A local agent that reflects on its own memory can.\n\nServices like Letta use server-side scheduling for dreaming — their infra, their LLM calls. Valid approach. We took a different path: local by default, cloud optional, always on your API key.\n\n```\npip install lorekeeper-mcp\nmcp-server setup\n# dreaming starts automatically via cron\n```\n\nThe repo is [github.com/jessira/lorekeeper](https://github.com/jessira/lorekeeper), Apache 2.0.\n\n**Have you noticed your coding agent repeating itself across sessions?** The same approach it already tried, the same pattern you already rejected? Drop a comment — I'd love to hear how you handle it.", "url": "https://wpnews.pro/news/my-ai-agents-spend-10-minutes-every-night-rewriting-their-own-memory", "canonical_source": "https://dev.to/jessin_ra_84ab54c4f940c6a/my-ai-agents-spend-10-minutes-every-night-rewriting-their-own-memory-33in", "published_at": "2026-06-16 14:34:34+00:00", "updated_at": "2026-06-16 14:47:10.151063+00:00", "lang": "en", "topics": ["ai-agents", "developer-tools", "machine-learning", "large-language-models", "ai-infrastructure"], "entities": ["Lorekeeper", "LongMemEval-S", "Letta", "Apache 2.0", "jessira"], "alternates": {"html": "https://wpnews.pro/news/my-ai-agents-spend-10-minutes-every-night-rewriting-their-own-memory", "markdown": "https://wpnews.pro/news/my-ai-agents-spend-10-minutes-every-night-rewriting-their-own-memory.md", "text": "https://wpnews.pro/news/my-ai-agents-spend-10-minutes-every-night-rewriting-their-own-memory.txt", "jsonld": "https://wpnews.pro/news/my-ai-agents-spend-10-minutes-every-night-rewriting-their-own-memory.jsonld"}}