Engineering

Engineering

Add Memory to OpenClaw: The Complete Mem0 Integration Guide (2026)

Add Memory to OpenClaw: The Complete Mem0 Integration Guide (2026)

Add Memory to OpenClaw: The Complete Mem0 Integration Guide (2026)

Add Memory to OpenClaw: The Complete Mem0 Integration Guide (2026) — thumbnail image

We recently built memory for OpenClaw and received a large number of people testing OpenClaw with Mem0.

If you haven't tried that setup yet, this tutorial is for you. If you're looking for a quicker overview first, see the OpenClaw + Mem0 landing page — this post is the technical deep-dive; that page is the fast summary.

When you run OpenClaw for the first time, it collects information about you and writes it into memory files that the agent can reference during conversations. The agent may ask about your work, your preferences, or how you want it to behave. As you keep using it, responses may begin to reflect that information, which makes the agent feel like it is learning over time.

But as conversations grow longer or span multiple sessions, that expectation starts to break down. Details you shared earlier stop showing up in responses. Information that felt important to the task is no longer recalled. In some cases, the agent behaves as if the information were never provided at all.

This happens because OpenClaw's default memory system does not guarantee persistence or memory recall. Memory storage and retrieval are left to the LLM, guided by prompts, heuristics, and a small set of Markdown files.

The model decides what to save, when to search memory, and whether previously stored information is relevant enough to be loaded back into the current context. There is simply no guarantee that information will be persisted or reloaded when needed.

This article shows how to add enforced, persistent memory to OpenClaw using the Mem0 plugin, @mem0/openclaw-mem0.

TL;DR

  • OpenClaw provides memory files and memory tools, but it does not guarantee when information is saved or recalled

  • Memory persistence and retrieval are optional behaviors controlled by prompts and model heuristics

  • Long conversations and context compaction reduce the reliability of recall

  • @mem0/openclaw-mem0 Enforces automatic memory capture outside the agent lifecycle

  • Relevant memory is injected into every response automatically

  • Memory survives restarts and session boundaries, making agents reliable across runs

What persistent memory means in OpenClaw agents

In OpenClaw, persistent memory refers to memory that is stored outside the agent's execution lifecycle and can be reintroduced after a session ends or the process restarts.

Agents do not run forever. Sessions end. Context gets trimmed. Processes restart. If memory only lives inside the active prompt, it will disappear. Persistent memory solves that by living outside the agent lifecycle and being reintroduced when needed.

Without it, agents rely on short-term context and best-effort recall. With it, agents can actually build on past interactions over time.

How OpenClaw's memory system works, and why it fails for long-term recall

Out of the box, OpenClaw stores memory as Markdown files on disk.

ls
ls
ls

You will see files like:

AGENTS.md
IDENTITY.md
MEMORY.md
USER.md
AGENTS.md
IDENTITY.md
MEMORY.md
USER.md
AGENTS.md
IDENTITY.md
MEMORY.md
USER.md

As you talk to your agent, OpenClaw gives the LLM access to memory tools such as memory_search and memory_get. At first glance, this looks reasonable. Memory exists, and tools exist.

The problem is how those tools are used.

  • Saving memory: When you tell your agent something important, OpenClaw does not force it into memory. The LLM decides if the information is worth saving. If it decides no, the information is ignored forever. There is no guarantee it will be saved.

  • Recall: Even when something was saved, recall is still not guaranteed. OpenClaw provides tools likememory_search, but the agent must decide to call them. Most of the time, it chooses to answer from its training data instead.

User: I usually build backend APIs in Python
Agent: Okay, noted

[new session]

User: Suggest a project idea for me
Agent: You could build a mobile app or a game
User: I usually build backend APIs in Python
Agent: Okay, noted

[new session]

User: Suggest a project idea for me
Agent: You could build a mobile app or a game
User: I usually build backend APIs in Python
Agent: Okay, noted

[new session]

User: Suggest a project idea for me
Agent: You could build a mobile app or a game
  • Context compaction: To avoid hitting token limits, OpenClaw compacts context while older messages are summarized or removed from the active conversation. If the agent does not decide to search memory again after compaction, it answers without that context entirely.

  • Built-in memory search: OpenClaw builds a vector index over Markdown memory files, but in practice, search results are inconsistent, search calls may fail silently, and the agent may not call search at all.

By now, the pattern is obvious. Information may exist on disk, but there is no guarantee it will be saved, searched, or reintroduced when needed.

For short demos, the built-in memory is usually fine. But once you start doing real work, long sessions, agents that run across days, all things fall apart quickly.

Cross-Channel Memory

Everything above happens even within a single conversation thread. The problem compounds when your OpenClaw agent lives in more than one place.

OpenClaw agents commonly run across Telegram, WhatsApp, Discord, and a default chat interface at the same time. With the built-in memory system, there's no consistent guarantee that something you mentioned in one channel is available when you switch to another, since saving and recall both depend on the model deciding to act on the markdown files in front of it during that specific session.

With Mem0, this isn't a special mode you configure, it falls out of how Auto-Capture and Auto-Recall already work. Memory is stored against your user ID, not against a channel or a session. Tell your agent in Telegram that you usually build backend APIs in Python, and Auto-Capture stores that as a memory tied to you. Switch to Discord later and ask for a project idea, and Auto-Recall retrieves that same memory before the agent responds, regardless of which channel it originally came from.

[Telegram] User: I usually build backend APIs in Python
→ Auto-Capture stores this as a user-scoped memory

[Discord, later]

[Telegram] User: I usually build backend APIs in Python
→ Auto-Capture stores this as a user-scoped memory

[Discord, later]

[Telegram] User: I usually build backend APIs in Python
→ Auto-Capture stores this as a user-scoped memory

[Discord, later]

The agent doesn't know or care which channel a memory originated in. It knows the user.

How Mem0 adds persistent memory to OpenClaw agents

@mem0/openclaw-mem0 moves memory control out of the agent loop and into the system layer. It does this through two mechanisms that run on every turn, silently, with no manual configuration required.

  • Auto-Capture: After the agent responds, the exchange is sent to Mem0, which decides what is worth keeping and stores it as structured memory outside the session. Memory capture does not depend on the agent deciding what is important.

  • Auto-Recall: Before the agent responds, memories matching the current message are retrieved and injected directly into the context, long-term memories first, then session memories. The agent reasons with the memory already present. No memory_search call required.

User: I usually build backend APIs in Python

Auto-Capture: detects user preference, stores as user-scoped memory
Auto-Recall: next turn, that memory is already in context before the agent responds
User: I usually build backend APIs in Python

Auto-Capture: detects user preference, stores as user-scoped memory
Auto-Recall: next turn, that memory is already in context before the agent responds
User: I usually build backend APIs in Python

Auto-Capture: detects user preference, stores as user-scoped memory
Auto-Recall: next turn, that memory is already in context before the agent responds
  • Memory survives sessions: You can stop the agent, restart it, continue the conversation. The memory still exists because it lives outside the session. This is what makes it a real memory system for AI agents.

Short-term vs long-term memory

The plugin organises memory into two scopes, and understanding the difference matters for how you use the tools.

  • Session memory (short-term): Auto-capture stores memories scoped to the current session using Mem0's run_id parameter. These are contextual to the ongoing conversation and do not carry forward indefinitely.

  • User memory (long-term): Persists across all sessions for the user. When the agent calls memory_add explicitly, it defaults to long-term storage (longTerm: true).

During auto-recall, both scopes are searched and presented separately, i.e, long-term memories first, then session memories, so the agent has full context before it reasons.

Setting up @mem0/openclaw-mem0 step by step

You no longer need manual config editing to get started. Everything happens inside the OpenClaw chat itself.

Note: Requires OpenClaw >= 2026.4.15. Check your version with openclaw --version. For the canonical technical reference alongside this walkthrough, see docs.mem0.ai/integrations/openclaw.

Step 1: Get the setup command

Setup Mem0 from mem0.ai/claw-setup

Setup Mem0 from mem0.ai/claw-setup
Setup Mem0 from mem0.ai/claw-setup
Setup Mem0 from mem0.ai/claw-setup

Step 2: Send it to your OpenClaw agent

Open any OpenClaw channel including, Telegram, WhatsApp, your default chat, wherever your agent lives. Paste and send the command from the previous step.

OpenClaw responds with a Mem0 setup card and immediately asks:

"What's your email address? I'll send you a verification code to connect your Mem0 account."

Step 3: Enter your email

Type your email address and send it. Mem0 sends back:

"Check your email for a 6-digit code and paste it here."

Step 4: Paste the OTP

Copy the 6-digit code from your inbox and paste it into the chat:

223716
223716
223716

You'll see the confirmation:

"Connected to Mem0."

That's it. No API key. No config file editing. No environment variables. The plugin is now active and auto-capture and auto-recall are running on every turn.

Prefer to self-host? Use open-source mode

If you want to run everything locally without connecting to Mem0 Cloud, you can still use open-source mode. This path does require a manual config edit. For the fully local, Ollama-based variant of this setup, see Adding Persistent Memory to Local AI Agents with Mem0, OpenClaw, and Ollama.

Open your config file:

Add this under plugins.entries:

OpenClaw treats memory plugins as an exclusive slot. Installing the plugin alone does not activate it — you must also set plugins.slots.memory as shown below.

{
  "plugins": {
    "slots": {
      "memory": "openclaw-mem0"
    },
    "entries": {
      "openclaw-mem0": {
        "enabled": true,
        "config": {
          "mode": "open-source",
          "userId": "your-user-id"
        }
      }
    }
  }
}
{
  "plugins": {
    "slots": {
      "memory": "openclaw-mem0"
    },
    "entries": {
      "openclaw-mem0": {
        "enabled": true,
        "config": {
          "mode": "open-source",
          "userId": "your-user-id"
        }
      }
    }
  }
}
{
  "plugins": {
    "slots": {
      "memory": "openclaw-mem0"
    },
    "entries": {
      "openclaw-mem0": {
        "enabled": true,
        "config": {
          "mode": "open-source",
          "userId": "your-user-id"
        }
      }
    }
  }
}

To customise the embedder, vector store, or LLM:

{
  "plugins": {
    "slots": {
      "memory": "openclaw-mem0"
    },
    "entries": {
      "openclaw-mem0": {
        "enabled": true,
        "config": {
          "mode": "open-source",
          "userId": "your-user-id",
          "oss": {
            "embedder": { "provider": "openai", "config": { "model": "text-embedding-3-small" } },
            "vectorStore": { "provider": "qdrant", "config": { "host": "localhost", "port": 6333 } },
            "llm": { "provider": "openai", "config": { "model": "gpt-4o" } }
          }
        }
      }
    }
  }
}
{
  "plugins": {
    "slots": {
      "memory": "openclaw-mem0"
    },
    "entries": {
      "openclaw-mem0": {
        "enabled": true,
        "config": {
          "mode": "open-source",
          "userId": "your-user-id",
          "oss": {
            "embedder": { "provider": "openai", "config": { "model": "text-embedding-3-small" } },
            "vectorStore": { "provider": "qdrant", "config": { "host": "localhost", "port": 6333 } },
            "llm": { "provider": "openai", "config": { "model": "gpt-4o" } }
          }
        }
      }
    }
  }
}
{
  "plugins": {
    "slots": {
      "memory": "openclaw-mem0"
    },
    "entries": {
      "openclaw-mem0": {
        "enabled": true,
        "config": {
          "mode": "open-source",
          "userId": "your-user-id",
          "oss": {
            "embedder": { "provider": "openai", "config": { "model": "text-embedding-3-small" } },
            "vectorStore": { "provider": "qdrant", "config": { "host": "localhost", "port": 6333 } },
            "llm": { "provider": "openai", "config": { "model": "gpt-4o" } }
          }
        }
      }
    }
  }
}

Restart the gateway after saving:

All oss fields are optional. The defaults use OpenAI embeddings (text-embedding-3-small), an in-memory vector store, and OpenAI LLM. See the Mem0 OSS docs for the full list of available providers.

What tools your agent now has access to

Once the plugin is enabled, your agent gains eight memory tools automatically:

Tool

Description

memory_search

Search memories by natural language query. Supports scope, categories, filters.

memory_add

Store facts. Accepts text or facts array, category, importance, metadata.

memory_list

List all memories. Filter by userId, agentId, scope.

memory_get

Retrieve a single memory by ID

memory_update

Update a memory's text in place. Preserves history.

memory_delete

Delete by memoryId, query, or all: true.

memory_event_list

List recent background processing events (platform mode only).

memory_event_status

Get status of a specific event by ID (platform mode only).

For normal usage you do not need to call these manually. Auto-capture and auto-recall handle most cases. They are there when you need explicit control.

Verifying that persistent memory works

At this point, everything should be wired up. The only thing left is to confirm memory actually persists.

Start by telling your agent something worth remembering:

User: I usually build backend APIs in Python
Agent: Got it. I've noted that you build backend APIs in Python.
User: I usually build backend APIs in Python
Agent: Got it. I've noted that you build backend APIs in Python.
User: I usually build backend APIs in Python
Agent: Got it. I've noted that you build backend APIs in Python.

You should see this in your logs immediately:

21:49:09 [plugins] openclaw-mem0: auto-captured 1 memories
21:49:09 [plugins] openclaw-mem0: auto-captured 1 memories
21:49:09 [plugins] openclaw-mem0: auto-captured 1 memories

Stop the agent. Start it again so you are in a new session:

Ask something that depends on that memory:

User: Suggest a project idea for me
Agent: Since you build backend APIs in Python, you could build a small API 
       gateway with rate limiting and API key support

User: Suggest a project idea for me
Agent: Since you build backend APIs in Python, you could build a small API 
       gateway with rate limiting and API key support

User: Suggest a project idea for me
Agent: Since you build backend APIs in Python, you could build a small API 
       gateway with rate limiting and API key support

Then confirm the memory exists directly using the CLI:

# Search by exact phrase
openclaw mem0 search "backend APIs in Python"

# Search by natural language
openclaw mem0 search "what does the user usually build"

# Search only long-term memories
openclaw mem0 search "backend APIs" --scope long-term

# Search only session memories
openclaw mem0 search "backend APIs" --scope session

# List all memories
openclaw mem0 list

# List with filters
openclaw mem0 list --user-id alice --top-k 20
# Search by exact phrase
openclaw mem0 search "backend APIs in Python"

# Search by natural language
openclaw mem0 search "what does the user usually build"

# Search only long-term memories
openclaw mem0 search "backend APIs" --scope long-term

# Search only session memories
openclaw mem0 search "backend APIs" --scope session

# List all memories
openclaw mem0 list

# List with filters
openclaw mem0 list --user-id alice --top-k 20
# Search by exact phrase
openclaw mem0 search "backend APIs in Python"

# Search by natural language
openclaw mem0 search "what does the user usually build"

# Search only long-term memories
openclaw mem0 search "backend APIs" --scope long-term

# Search only session memories
openclaw mem0 search "backend APIs" --scope session

# List all memories
openclaw mem0 list

# List with filters
openclaw mem0 list --user-id alice --top-k 20

You should see:

Found 1 memory
- User usually builds backend APIs in Python
Found 1 memory
- User usually builds backend APIs in Python
Found 1 memory
- User usually builds backend APIs in Python

At this point there is nothing left to assume. The memory exists. It survives restarts. It is injected into every response. The agent is no longer guessing.

Configuration reference

Core options

Key

Type

Default

Description

mode

"platform" / "open-source"

"platform"

Which backend to use

userId

string

OS username

Scope memories per user

autoRecall

boolean

true

Inject memories before each turn

autoCapture

boolean

true

Store facts after each turn

topK

number

5

Max memories injected per recall

searchThreshold

number

0.3

Minimum similarity score (0–1)

Platform mode options

Key

Description

apiKey

Supports ${MEM0_API_KEY} env var syntax

customInstructions

Override what gets extracted and how it is formatted

customCategories

Override the 12 default memory category tags

Open-source mode options (oss)

Key

Default

Description

oss.embedder.provider

"openai"

Embedding provider ("openai", "ollama", etc.)

oss.vectorStore.provider

"memory"

Vector store ("memory", "qdrant", "chroma", etc.)

oss.llm.provider

"openai"

LLM provider ("openai", "anthropic", "ollama", etc.)

oss.historyDbPath

SQLite path for memory edit history

oss.disableHistory

false

Disable memory edit history tracking

Coexisting with OpenClaw's Built-In Systems

It's worth being precise about what Mem0 actually replaces, since "the plugin replaces the default memory behavior" doesn't mean it replaces everything OpenClaw does with context.

OpenClaw's context compaction is separate from its memory system, and it keeps running exactly as before. Compaction manages the active session window: as a conversation grows, older messages still get summarized or trimmed to stay within token limits, whether or not the Mem0 plugin is installed. Mem0 doesn't touch that process and doesn't need to.

What changes is what happens after compaction. Without Mem0, once something is compacted out of the active window, it's gone unless the agent happens to decide to search memory again, which, as covered above, isn't guaranteed. With Mem0, Auto-Recall re-injects relevant memory on every turn from outside the session entirely, so it doesn't matter whether the fact you need was compacted out five messages ago or fifty. The memory isn't being recovered from the trimmed context, it was never depending on that context to begin with.

In short: compaction still manages what's active in the conversation window. Mem0 manages what's true about the user and persists regardless of what the conversation window currently contains. The two operate at different layers and don't conflict.

Start building agents that actually remember

OpenClaw agents forget because memory is treated as a suggestion, not a requirement. Facts may or may not be saved. Memory may or may not be searched. Context may disappear at any time due to compaction. When all of that is left to the LLM, forgetting is the expected outcome.

@mem0/openclaw-mem0 changes this by enforcing memory capture and recall at the system layer rather than leaving it to the prompt. Memory is captured outside the agent session. Relevant memory is reintroduced on every turn. Restarts do not matter. Long conversations do not matter. The agent reasons with the same facts every time.

You do not need to rewrite prompts or change how your agent works. You only replace the memory layer.

If you are building agents that run across sessions, handle real user preferences, or are expected to behave consistently over time, persistent memory is not optional. It is the foundation.

The simplest next step is to install the plugin, restart your agent, and watch it stop guessing and start remembering.

Frequently Asked Questions

Q. Do I need to change my agent prompts to use @mem0/openclaw-mem0?

No. The plugin works at the memory layer. Your prompts and agent logic stay the same.

Q. Does this replace OpenClaw's built-in memory tools?

Yes. The plugin replaces the default memory behavior with persistent memory backed by Mem0.

Q. I was using memory_store or memory_forget `before, do those still work?

These tools were renamed to memory_add and memory_delete in the current version. Update any custom prompts or agent code that references the old names.

Q. Why does my OpenClaw agent keep forgetting things?

By default, OpenClaw leaves memory decisions entirely to the model: whether to save something, whether to search for it later, and whether to trust what it finds. If the model decides a detail isn't worth saving, or doesn't think to search memory after context compaction, that information is effectively lost even though nothing actually broke. @mem0/openclaw-mem0 fixes this by moving capture and recall out of the model's discretion and into the system layer, so it happens automatically on every turn instead of depending on the agent choosing to do it.

Q. How is this different from using a MEMORY.md file?

MEMORY.md is one of OpenClaw's default markdown files, and using it depends entirely on the model deciding to write to it and later deciding to read it back. There's no guarantee either happens. Mem0 replaces that voluntary flow with Auto-Capture and Auto-Recall, which run automatically outside the agent's own decision-making, so persistence doesn't depend on the model remembering to use a file.

Q. Can I self-host the Mem0 OpenClaw plugin?

Yes. Open-source mode runs entirely on your own infrastructure, with your choice of embedder, vector store, and LLM provider, configured through openclaw.json. See "Prefer to self-host? Use open-source mode" above for the full setup.

Q. Does the plugin work with OpenClaw's context compaction?

Yes. Compaction continues to manage the active session window exactly as it did before. Mem0 doesn't rely on that window: Auto-Recall reintroduces relevant memory on every turn regardless of what compaction has trimmed, so compacted messages don't translate into forgotten facts. See "Coexisting with OpenClaw's Built-In Systems" above.

Q. How do I configure persistent memory in OpenClaw?

Setup itself requires no manual configuration: send the setup command from mem0.ai/claw-setup to your agent in any channel, verify with the emailed OTP, and Auto-Capture/Auto-Recall are active immediately. If you want to tune behavior beyond the defaults, that's where configuration comes in, see the Configuration reference above for options like topK, searchThreshold, customInstructions, and customCategories.

Q. How do I set up long-term memory in OpenClaw?

Long-term memory happens automatically through normal use, Auto-Capture stores facts as they come up. If you want to guarantee a specific fact is stored as long-term rather than session-scoped, call memory_add explicitly, it defaults to longTerm: true and persists across all future sessions for that user.

Q. What is session memory in OpenClaw, and how is it different from long-term memory?

Session memory is scoped to the current conversation using Mem0's run_id parameter and doesn't carry forward indefinitely. Long-term memory persists across every session for that user. During Auto-Recall, both are searched, with long-term memories surfaced first, then session memories, so the agent has full context regardless of which scope a fact came from.

Q. What are the best practices for managing OpenClaw memory?

A few that follow directly from how the plugin works: use memory_add explicitly for facts you need guaranteed as long-term rather than relying on Auto-Capture's session-scoped default; tune customInstructions and customCategories if the default extraction doesn't match what your agent needs to remember; adjust topK and searchThreshold if recall feels too broad or too narrow; and periodically check what's actually stored with memory_list or the CLI search commands covered in "Verifying that persistent memory works" above, rather than assuming capture is working correctly.

GET TLDR from:

Summarize

Website/Footer

Summarize

Website/Footer

Summarize

Website/Footer

Summarize

Website/Footer