AI agent persistent memory means storing knowledge outside the context window and retrieving only what's relevant per request. Two options as of August 2026: Cloudflare Agent Memory (managed, five-channel retrieval, private beta) and Memmy (open-source, local-first, unified across Claude Code and Codex). Both solve context rot -- the silent killer of long-running agents.
I've been running production agents for over a year. The pattern I keep seeing: agent works great for 20 turns, then falls apart. Not because the model is bad -- because the context rotted. Here's how to fix it with the two best options available right now.
What is context rot and why does it kill production agents?
Context rot is the degradation in AI agent output quality as the context window fills up. Models don't give equal attention to all tokens -- information buried in the middle of the window gets less reliable retrieval than content near the start or end. A 2026 analysis of enterprise AI deployments found that 65% of agent failures were attributable to context drift or memory loss during multi-step reasoning, not model incapability.
The numbers are specific. Zylos AI research (2026) found that context degradation begins at approximately 50% of the nominal window capacity. Information in the middle of a long context suffers accuracy drops of 30% or more. Even with 200K token windows, most production agents break before hitting 130K -- because the problem isn't window size, it's what happens as it fills.
The result: your agent forgets decisions made three tasks ago, contradicts itself, and repeats work. Long-running workflows -- multi-day builds, production codebases, customer support agents -- hit this wall fast. Bigger context windows don't fix context rot, they just delay it.
What's the difference between context-stuffing and real memory?
Context-stuffing means loading everything into the prompt -- full conversation history, all project files, every past decision. Real memory means extracting structured knowledge, storing it outside the context window, and injecting only the relevant slice at query time. Context-stuffing degrades proportionally with session length. Real memory doesn't, because the raw tokens get discarded after extraction.
Think of it like RAM vs disk. Your context window is RAM -- fast but finite. External memory is disk -- slower to query but it doesn't fill up mid-session. Context-stuffing is additive (you keep piling tokens until you hit the wall). Real memory is selective: extract, discard raw conversation, retrieve only what's relevant to the current query via semantic search.
In August 2026, this problem is dominating GitHub Trending. TencentDB-Agent-Memory hit 7,800+ stars with benchmarked results: 61.38% token usage reduction and a 51.52% pass rate improvement, with PersonaMem accuracy jumping from 48% to 76% when integrated with OpenClaw. And two new tools launched this week during Cloudflare Agents Week (August 2-7): Cloudflare Agent Memory and Memmy.
Want the templates from this tutorial?
I share every workflow, prompt, and template inside the free AI Creator Hub on Skool. 500+ builders sharing what actually works.
Join Free on Skool
Option 1: Cloudflare Agent Memory (managed service, private beta)
Cloudflare Agent Memory is a managed persistent memory service launched during Agents Week 2026 and currently in private beta. It extracts structured memories from conversations using a five-channel parallel retrieval pipeline -- full-text search, exact fact-key lookup, raw message search, direct vector search, and HyDE (hypothetical document embedding) vector search -- all merged via Reciprocal Rank Fusion. It runs entirely on Cloudflare's edge infrastructure with no external dependencies to wire up.
Under the hood, each memory profile gets its own Durable Object with SQLite backing. Memories are classified into four types at ingestion:
- Facts -- atomic stable knowledge ("project uses GraphQL")
- Events -- time-specific occurrences (deployments, decisions)
- Instructions -- reusable procedures and workflows
- Tasks -- ephemeral state, excluded from vector index but full-text searchable
Cloudflare's model choices here are worth noting. They default to Llama 4 Scout (17B, 16-expert MoE) for extraction and classification tasks, then switch to Nemotron 3 (120B MoE) only for synthesis, where the larger model meaningfully improves output quality. Their finding: "a bigger, more powerful model isn't always better." Extraction is a structured task; the smaller model handles it fine and runs faster.
The API from a Cloudflare Worker with the Agent Memory binding looks like this:
// Ingest a conversation (call at compaction or session end)
await env.AGENT_MEMORY.ingest({
profile: "user-123",
messages: conversation.messages
});
// Recall relevant context (call at session start)
const context = await env.AGENT_MEMORY.recall({
profile: "user-123",
query: "What database does this project use?"
});
// Explicitly store a known fact
await env.AGENT_MEMORY.remember({
profile: "user-123",
content: "Project uses PostgreSQL with Drizzle ORM"
});
There's also a REST API for agents running outside Workers -- so if you're running Claude Code locally, you can push session memories to Cloudflare's edge between sessions. Full announcement and waitlist on the Cloudflare blog.
Current status: Private beta, waitlist open. No pricing announced yet.
Best for: Teams already building agents on Cloudflare Workers who want managed memory with edge distribution and no retrieval pipeline to maintain.
Option 2: Memmy (open-source, local-first, unified across tools)
Memmy is an open-source local memory hub that gives Claude Code, Cursor, Codex, OpenClaw, and Hermes Agent a single shared persistent memory layer. Where Cloudflare's solution is managed and cloud-hosted, Memmy runs entirely on your machine. It scans historical conversations from all connected agents, distills them into long-term memory using the MemOS engine, and installs memory-accessing skills into each agent so they retrieve shared context without leaving their native environments.
The three-layer architecture:
- Memory Layer -- Local-first storage with hybrid retrieval. Distills conversations into searchable structured knowledge.
- Agent Runtime -- Handles reasoning, task orchestration, tool integration, and MCP connections.
- Integration Layer -- Connects external tools (GitHub, Notion, Slack, Jira) and messaging platforms (Telegram, Discord, WeChat).
The core value proposition: if you use Claude Code for one codebase and Codex for another, they share zero context. You explain the same architectural decision twice. Memmy fixes this by acting as the single source of truth -- both agents write to and read from the same memory store. The OpenAI-compatible API on port 18990 means any agent that supports OpenAI-format API calls can plug in.
Setup requires Node.js 22 or higher:
git clone https://github.com/MemTensor/memmy-agent.git
cd memmy-agent
bash scripts/dev-start.sh
Desktop app and CLI/TUI modes are also available. Free trial tokens on registration, then BYOK (bring your own API keys) for ongoing use. All memory data stays on your machine by default -- nothing goes to a third-party server for the memory layer itself.
Current status: 550 GitHub stars, 54 forks, 44 commits on main. Early but functional.
Best for: Solo developers and small teams using multiple AI coding agents who want unified memory without cloud dependency.
How to choose: Cloudflare vs Memmy vs rolling your own
Choose Cloudflare Agent Memory if you're building agent products on Workers and need production-grade managed memory with edge distribution. Choose Memmy if you're a developer using multiple AI coding tools and want them to share knowledge locally. Build your own only if you have specific retrieval requirements neither covers -- and know that building the extraction and retrieval pipeline is several weeks of non-trivial engineering.
Quick decision tree:
- Building an agent product on Cloudflare Workers? -- Cloudflare Agent Memory. Managed infrastructure, five-channel retrieval already engineered, edge-distributed. Join the private beta waitlist.
- Using Claude Code + Codex or Cursor in parallel? -- Memmy. Solve the cross-tool amnesia problem. Local, free, open source.
- Standalone agent with a very long single task? -- TencentDB-Agent-Memory. The 61.38% token reduction is benchmarked, runs locally, zero external API dependencies.
- Enterprise on-prem compliance? -- Self-hosted Memmy or TencentDB-Agent-Memory. Both run without external API calls for the memory layer.
The pattern I see fail the most: developers store raw conversation logs to a database and call it memory. That's not memory -- that's context in a different location. Real memory requires extraction, classification, and semantic retrieval. All three of the solutions above handle this automatically. If you roll your own, that's the work you're signing up for.
The fastest path to production agent memory today
If you want persistent memory for Claude Code right now -- before Cloudflare Agent Memory exits private beta -- Memmy is the fastest path to working cross-session memory. Clone the repo, run the dev server, and your agents can access shared memory via the OpenAI-compatible API. For agents built on Cloudflare Workers, join the waitlist now; private betas on Cloudflare infrastructure tend to move to GA within months.
The architecture pattern that works in production, regardless of which memory layer you choose:
- Session start: Query memory store for user profile, project context, and recent decisions. Inject as a system prompt prefix -- not raw logs, just the recalled relevant slice. Keep it under 2K tokens.
- During session: Let the agent run with a clean context window. Don't front-load everything upfront.
- At compaction or session end: Extract facts, events, and instructions from the conversation. Write to memory store. Discard raw messages.
- Next session: Repeat. The agent picks up where it left off without carrying dead context into the new window.
This is exactly the pattern Cloudflare Agent Memory implements at the infrastructure level -- ingest at compaction, recall at session start. You're choosing where that memory lives and who maintains the retrieval pipeline, not whether the pattern works. It does.
FAQ
What is the difference between AI agent memory and context window?
The context window is temporary working memory -- everything the model can see in a single inference call. Agent memory is external persistent storage that survives across sessions, compaction events, and agent restarts. Memory is extracted from context, stored in structured form (facts, events, instructions), and retrieved semantically when relevant to the current query. Context fills up; well-designed external memory doesn't.
Does Cloudflare Agent Memory work with Claude Code?
Cloudflare Agent Memory is designed for agents running on Cloudflare Workers, but it also exposes a REST API usable from outside Workers. You can integrate it with Claude Code via a custom MCP server that wraps the Agent Memory REST API -- injecting recalled context into your agent's system prompt at session start. The service is waitlist-only as of August 2026. Full details at the Cloudflare Agent Memory docs.
Is Memmy Agent production-ready?
Memmy has 550 GitHub stars and is in active development with 44 commits on main. It's solid for solo developers and small teams testing cross-agent unified memory, but hasn't been benchmarked at enterprise scale yet. For production workloads serving end users, consider waiting for Cloudflare Agent Memory to exit private beta, or building on TencentDB-Agent-Memory (7,800+ stars, 61.38% token reduction, published benchmark results).
How much does AI agent persistent memory cost?
Memmy is free and open-source with BYOK after the trial period. TencentDB-Agent-Memory is open-source with zero external API dependencies -- you pay only for whatever model you already use. Cloudflare Agent Memory hasn't announced pricing; it's in private beta as of August 2026. Expect Cloudflare's pricing to follow their Workers billing model (per-request or per-memory-operation), similar to Vectorize and Durable Objects today.
What causes context rot in AI agents?
Context rot is caused by how transformer attention works: information in the middle of a long context gets less reliable retrieval than content near the start or end of the window. Zylos AI research (2026) shows degradation beginning at 50% of window capacity, with accuracy drops of 30% or more for mid-context content. The fix is external memory -- extract structured knowledge, store it separately, and retrieve only what's relevant rather than accumulating everything in the window.
Want the templates from this tutorial?
I share every workflow, prompt, and template inside the free AI Creator Hub on Skool. 500+ builders sharing what actually works.
Join Free on Skool