mem9 Fixes AI Coding Agents That Forget Everything Between Sessions
mem9 gives coding agents a shared, persistent memory layer that survives session resets, machine switches, and multi-agent workflows — built on TiDB Cloud
ProTakeaways
- What it is: mem9 is an open-source, Apache-2.0 persistent memory layer for AI coding agents, built by the TiDB team on TiDB Cloud.
- Cross-agent sharing: One memory space serves OpenClaw, Claude Code, OpenCode, Codex, Hermes Agent, Dify, and custom HTTP clients through a single API key.
- Hybrid recall: Combines vector similarity search with keyword search server-side; auto-embeds memories without requiring an OpenAI key.
- Smart ingest: Sessions are processed asynchronously by an LLM that extracts and deduplicates facts before storage, keeping context lean and relevant.
- Pricing: Currently free for all tiers; planned paid plans start at $9/mo (Starter) up to $120/mo (Pro, unlimited memories).
- Self-hostable: The Go server supports TiDB, Postgres, and db9 backends; migrating from cloud to self-hosted requires changing a single tenant record.
mem9 is an open-source persistent memory system for AI coding agents. The core problem it solves is embarrassingly simple to state: every time you close a session, your agent forgets everything. Your preferences, your project conventions, the bugs you already explained , gone. mem9 fixes that with a cloud-backed memory layer that plugs into the agent runtimes you already use.
The amnesia problem, at scale
OpenClaw's default memory writes memories to local .md files. Once hundreds of these accumulate, the agent has no way to scan all of them before each conversation , memory degrades into an archive that requires explicit prompting to retrieve.
That's the single-machine version of the problem. The multi-agent version is worse:
memories cannot be shared across agents. Preferences you've told the main agent are unknown to the coding agent; each agent lives in its own information silo.
OpenClaw's built-in memory is file-backed and local. This works great for single-machine use, but teams and multi-agent setups often need more: cross-machine persistence so memory follows the user, not the laptop; multi-agent sharing so Claude Code, OpenCode, and OpenClaw agents share what they've learned; and cloud-native agents in CI/CD or cron jobs that get persistent memory out of the box.
What mem9 actually is
Your agents forget everything between sessions. mem9 fixes that with persistent memory across sessions and machines, shared memory for multi-agent workflows, and hybrid recall with a visual dashboard. OpenClaw, Hermes Agent, Claude Code, OpenCode, Codex, Dify apps, and custom clients can recall the same facts.
The architecture is deliberately stateless on the client side.
Agent plugins carry zero state , all memory lives in the mem9 server. Tenant isolation gives each team or project its own memory pool. Hybrid search combines vector similarity with keyword matching, with graceful degradation when no embedder is available. Auto-embedding via EMBED_TEXT() generates embeddings server-side, so no OpenAI key is needed.
Under the hood, the hosted mem9 API runs on TiDB Cloud Starter, which provides managed provisioning, native vector search, full-text search, server-side auto-embedding, hybrid search, and MySQL-compatible storage semantics. The reason for choosing a SQL-native backend over a pure vector store is deliberate: agents also need exact filters and chronology, ownership and transactions, permissions and audit trails, and structured queries across users, sessions, and tools. A vector-only store cannot answer questions like "which session wrote this memory" or "what tool calls did this user make in the last hour."
How smart ingest works
When a session ends, mem9 doesn't just dump the raw transcript into a database.
When a conversation ends, the mem9 plugin automatically selects the most recent content from the session's messages (up to 200KB / 20 messages), strips the <relevant-memories> injection block to prevent circular re-writing, and POSTs the selected messages along with session_id and agent_id to the server. The server returns 202 Accepted and asynchronously triggers the reconcile pipeline.
The default ingest mode is smart , an LLM pass (defaulting to gpt-4o-mini) extracts and deduplicates facts before they're stored. You can set MNEMO_INGEST_MODE=raw to skip that step, or swap in any OpenAI-compatible endpoint via MNEMO_LLM_BASE_URL. On the read side, the before_prompt_build lifecycle hook fires before the system prompt is assembled, injecting only the most relevant memories into context , keeping prompts lean.
Supported platforms
mem9 gives OpenClaw, Hermes Agent, Dify, Claude Code, OpenCode, Codex, and custom tools shared persistent memory with hybrid recall and a visual dashboard. Each platform has a dedicated integration shape:
- OpenClaw / ClawHub , a
kind: "memory"plugin that replaces the built-in file-backed memory slot - Claude Code , marketplace plugin with hooks and skills
- OpenCode , plugin SDK loaded from
opencode.json - Codex , managed hooks with project overrides
- Dify , tool plugin for Agent and Workflow apps, with single-space or per-node API keys
- Any HTTP client , direct REST API via
v1alpha2endpoints withX-API-Key
Set X-Mnemo-Agent-Id on authenticated memory, import, and session-message requests when you want the server to distinguish which runtime or agent instance is writing and recalling memories inside the same mem9 space.
This is how a single shared memory space achieves per-agent logical isolation without separate deployments.
Getting started in three steps
For OpenClaw, OpenClaw will automatically install mem9 and provision an API key for you , just paste one command into the chat. For everything else, the setup is three steps:
- Point at the hosted API (
https://api.mem9.ai) or spin up the self-hosted Go server withMNEMO_DSNset to your TiDB/Postgres/db9 connection string. - Set
MEM9_API_URLandMEM9_API_KEYin your environment. - Follow the integration guide for your agent runtime.
export MEM9_API_URL="https://api.mem9.ai"
export MEM9_API_KEY="<your-key>"
# Provision a new memory space
curl -sX POST https://api.mem9.ai/v1alpha1/mem9s
# Write a memory
curl -sX POST https://api.mem9.ai/v1alpha2/mem9s/memories \
-H "X-API-Key: $MEM9_API_KEY" \
-H "Content-Type: application/json" \
-d '{"content": "User prefers pytest over unittest"}'
# Search memories
curl -s "https://api.mem9.ai/v1alpha2/mem9s/memories?q=testing+preferences" \
-H "X-API-Key: $MEM9_API_KEY"Self-hosting is fully supported.
To migrate from cloud to local, only a single tenant record in the control plane needs updating , changing db_host from the cloud address to local TiDB , while all other server logic remains untouched. An independent data plane means the storage backend can be swapped at any time: local TiDB today, PlanetScale or a self-hosted MySQL tomorrow, with zero impact on the layers above.
Benchmarks and known limits
The team benchmarked mem9 on LoCoMo, a long-conversation memory evaluation framework that tests multi-hop reasoning, temporal reasoning, open-domain QA, and single-hop recall. Using qwen3.6-plus as the model, results were: 43.66% F1 score overall, 86.85% LLM score, and 81.43% evidence recall. Single-hop recall scored highest at 51.66% F1 / 89.71% LLM score, while multi-hop reasoning was the weakest category at 17.93% F1. Multi-hop memory , where the agent needs to chain several remembered facts together , remains an open problem across the field.
A practical limitation worth knowing:
OpenClaw does not support per-agent plugin configuration (agents.list[].slots is rejected at the schema level), so it's not possible to configure an independent mem9 instance for each agent.
Digging into the mem9 source code, however, reveals this is not actually a problem: mem9 internally differentiates agent memories by agent_id, and both writes and reads carry this identifier.
Pricing and availability
mem9 is live now and currently free for all tiers while the team builds out billing. The planned tiers are: Free (10,000 memories, 1,000 retrieval calls/month), Starter at $9/mo (50,000 memories), Pro at $120/mo (unlimited memories, 50,000 retrieval calls), and Enterprise with custom pricing. The server is Apache-2.0 licensed and self-hostable against TiDB, Postgres, or a db9 backend.
The bigger picture
TiDB launched the TiDB Agent State Stack at SuperAI Summit Singapore, a unified data foundation that gives AI agents durable memory, persistent state, and continuous context as they scale into production. As organizations move beyond AI pilots, a new challenge is emerging: AI agents struggle to retain memory, maintain state, and preserve context across sessions, workflows, tools, and teams. According to Gartner, fewer than 5% of enterprise applications included task-specific AI agents in 2025, a figure expected to reach 40% by the end of 2026.
mem9 is part of a broader stack alongside drive9, which handles persistent file and artifact storage for agents. mem9 is cognitive memory , the system for compact, revisable agent context: session traces, extracted insights, and durable pinned knowledge that can be carried across runs, shared between agents, and updated as the system learns. The underlying bet is that the industry spent the last year proving that agents can use tools. The next is about proving that agents can remember responsibly. Once memory becomes central to how agents personalize, reason, collaborate, and recover, it stops being a prompt engineering trick and becomes part of the runtime.