@dangvv/openclaw-mem0 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/README.md +222 -0
- package/index.ts +1600 -0
- package/openclaw.plugin.json +188 -0
- package/package.json +38 -0
- package/patches/mem0ai+2.3.0.patch +32 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the `@mem0/openclaw-mem0` plugin will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [0.3.0] - 2026-03-10
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
- Updated `mem0ai` dependency which includes the sqlite3 to better-sqlite3 migration for native binding resolution (#4270)
|
|
9
|
+
|
|
10
|
+
## [0.2.0] - 2026-03-09
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- "Understanding userId" section in docs clarifying that `userId` is user-defined
|
|
14
|
+
- Per-agent memory isolation for multi-agent setups via `agentId`
|
|
15
|
+
- Regression tests for per-agent isolation helpers
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
- Updated config examples to use concrete `userId` values instead of placeholders
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
- Migrated platform search to Mem0 v2 API
|
|
22
|
+
|
|
23
|
+
## [0.1.2] - 2026-02-19
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
- Source field for openclaw memory entries
|
|
27
|
+
|
|
28
|
+
### Fixed
|
|
29
|
+
- Auto-recall injection and auto-capture message drop
|
|
30
|
+
|
|
31
|
+
## [0.1.0] - 2026-02-02
|
|
32
|
+
|
|
33
|
+
### Added
|
|
34
|
+
- Initial release of the OpenClaw Mem0 plugin
|
|
35
|
+
- Platform mode (Mem0 Cloud) and open-source mode support
|
|
36
|
+
- Auto-recall: inject relevant memories before each turn
|
|
37
|
+
- Auto-capture: store facts after each turn
|
|
38
|
+
- Configurable `topK`, `threshold`, and `apiVersion` options
|
package/README.md
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
# @mem0/openclaw-mem0
|
|
2
|
+
|
|
3
|
+
Long-term memory for [OpenClaw](https://github.com/openclaw/openclaw) agents, powered by [Mem0](https://mem0.ai).
|
|
4
|
+
|
|
5
|
+
Your agent forgets everything between sessions. This plugin fixes that. It watches conversations, extracts what matters, and brings it back when relevant — automatically.
|
|
6
|
+
|
|
7
|
+
## How it works
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<img src="../docs/images/openclaw-architecture.png" alt="Architecture" width="800" />
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
**Auto-Recall** — Before the agent responds, the plugin searches Mem0 for memories that match the current message and injects them into context.
|
|
14
|
+
|
|
15
|
+
**Auto-Capture** — After the agent responds, the plugin sends the exchange to Mem0. Mem0 decides what's worth keeping — new facts get stored, stale ones updated, duplicates merged.
|
|
16
|
+
|
|
17
|
+
Both run silently. No prompting, no configuration, no manual calls.
|
|
18
|
+
|
|
19
|
+
### Short-term vs long-term memory
|
|
20
|
+
|
|
21
|
+
Memories are organized into two scopes:
|
|
22
|
+
|
|
23
|
+
- **Session (short-term)** — Auto-capture stores memories scoped to the current session via Mem0's `run_id` / `runId` parameter. These are contextual to the ongoing conversation and automatically recalled alongside long-term memories.
|
|
24
|
+
|
|
25
|
+
- **User (long-term)** — The agent can explicitly store long-term memories using the `memory_store` tool (with `longTerm: true`, the default). These persist across all sessions for the user.
|
|
26
|
+
|
|
27
|
+
During **auto-recall**, the plugin searches both scopes and presents them separately — long-term memories first, then session memories — so the agent has full context.
|
|
28
|
+
|
|
29
|
+
The agent tools (`memory_search`, `memory_list`) accept a `scope` parameter (`"session"`, `"long-term"`, or `"all"`) to control which memories are queried. The `memory_store` tool accepts a `longTerm` boolean (default: `true`) to choose where to store.
|
|
30
|
+
|
|
31
|
+
All new parameters are optional and backward-compatible — existing configurations work without changes.
|
|
32
|
+
|
|
33
|
+
### Per-agent memory isolation
|
|
34
|
+
|
|
35
|
+
In multi-agent setups, each agent automatically gets its own memory namespace. Session keys following the pattern `agent:<agentId>:<uuid>` are parsed to derive isolated namespaces (`${userId}:agent:${agentId}`). Single-agent deployments are unaffected — plain session keys and `agent:main:*` keys resolve to the configured `userId`.
|
|
36
|
+
|
|
37
|
+
**How it works:**
|
|
38
|
+
|
|
39
|
+
- The agent's session key is inspected on every recall/capture cycle
|
|
40
|
+
- If the key matches `agent:<name>:<uuid>`, memories are stored under `userId:agent:<name>`
|
|
41
|
+
- Different agents never see each other's memories unless explicitly queried
|
|
42
|
+
|
|
43
|
+
**Explicit cross-agent queries:**
|
|
44
|
+
|
|
45
|
+
All memory tools (`memory_search`, `memory_store`, `memory_list`, `memory_forget`) accept an optional `agentId` parameter to query another agent's namespace:
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
memory_search({ query: "user's tech stack", agentId: "researcher" })
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Resolution priority: explicit `agentId` > explicit `userId` > session-derived > configured default.
|
|
52
|
+
|
|
53
|
+
## Setup
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
openclaw plugins install @mem0/openclaw-mem0
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Understanding `userId`
|
|
60
|
+
|
|
61
|
+
The `userId` field is a **string you choose** to uniquely identify the user whose memories are being stored. It is **not** something you look up in the Mem0 dashboard — you define it yourself.
|
|
62
|
+
|
|
63
|
+
Pick any stable, unique identifier for the user. Common choices:
|
|
64
|
+
|
|
65
|
+
- Your application's internal user ID (e.g. `"user_123"`, `"alice@example.com"`)
|
|
66
|
+
- A UUID (e.g. `"550e8400-e29b-41d4-a716-446655440000"`)
|
|
67
|
+
- A simple username (e.g. `"alice"`)
|
|
68
|
+
|
|
69
|
+
All memories are scoped to this `userId` — different values create separate memory namespaces. If you don't set it, it defaults to `"default"`, which means all users share the same memory space.
|
|
70
|
+
|
|
71
|
+
> **Tip:** In a multi-user application, set `userId` dynamically per user (e.g. from your auth system) rather than hardcoding a single value.
|
|
72
|
+
|
|
73
|
+
### Platform (Mem0 Cloud)
|
|
74
|
+
|
|
75
|
+
Get an API key from [app.mem0.ai](https://app.mem0.ai), then add to your `openclaw.json`:
|
|
76
|
+
|
|
77
|
+
```json5
|
|
78
|
+
// plugins.entries
|
|
79
|
+
"openclaw-mem0": {
|
|
80
|
+
"enabled": true,
|
|
81
|
+
"config": {
|
|
82
|
+
"apiKey": "${MEM0_API_KEY}",
|
|
83
|
+
"userId": "alice" // any unique identifier you choose for this user
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Open-Source (Self-hosted)
|
|
89
|
+
|
|
90
|
+
No Mem0 key needed. Requires `OPENAI_API_KEY` for default embeddings/LLM.
|
|
91
|
+
|
|
92
|
+
```json5
|
|
93
|
+
"openclaw-mem0": {
|
|
94
|
+
"enabled": true,
|
|
95
|
+
"config": {
|
|
96
|
+
"mode": "open-source",
|
|
97
|
+
"userId": "alice" // any unique identifier you choose for this user
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Sensible defaults out of the box. To customize the embedder, vector store, or LLM:
|
|
103
|
+
|
|
104
|
+
```json5
|
|
105
|
+
"config": {
|
|
106
|
+
"mode": "open-source",
|
|
107
|
+
"userId": "your-user-id",
|
|
108
|
+
"oss": {
|
|
109
|
+
"embedder": { "provider": "openai", "config": { "model": "text-embedding-3-small" } },
|
|
110
|
+
"vectorStore": { "provider": "qdrant", "config": { "host": "localhost", "port": 6333 } },
|
|
111
|
+
"llm": { "provider": "openai", "config": { "model": "gpt-4o" } }
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
To enable graph memory in open-source mode, set `enableGraph: true` and provide a graph backend in `oss.graphStore`:
|
|
117
|
+
|
|
118
|
+
```json5
|
|
119
|
+
"config": {
|
|
120
|
+
"mode": "open-source",
|
|
121
|
+
"userId": "your-user-id",
|
|
122
|
+
"enableGraph": true,
|
|
123
|
+
"oss": {
|
|
124
|
+
"graphStore": {
|
|
125
|
+
"provider": "neo4j",
|
|
126
|
+
"config": {
|
|
127
|
+
"url": "${NEO4J_URL}",
|
|
128
|
+
"username": "${NEO4J_USERNAME}",
|
|
129
|
+
"password": "${NEO4J_PASSWORD}",
|
|
130
|
+
"database": "neo4j"
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
When graph memory is enabled in OSS mode, Mem0 search returns normal vector hits plus related entities in a `relations` payload. This plugin includes those relations in `memory_search` output and auto-recall context.
|
|
138
|
+
|
|
139
|
+
All `oss` fields are optional. See [Mem0 OSS docs](https://docs.mem0.ai/open-source/node-quickstart) for providers.
|
|
140
|
+
|
|
141
|
+
## Agent tools
|
|
142
|
+
|
|
143
|
+
The agent gets five tools it can call during conversations:
|
|
144
|
+
|
|
145
|
+
| Tool | Description |
|
|
146
|
+
|------|-------------|
|
|
147
|
+
| `memory_search` | Search memories by natural language. Optional `agentId` to scope to a specific agent. |
|
|
148
|
+
| `memory_list` | List all stored memories for a user. Optional `agentId` to scope to a specific agent. |
|
|
149
|
+
| `memory_store` | Explicitly save a fact. Optional `agentId` to store under a specific agent's namespace. |
|
|
150
|
+
| `memory_get` | Retrieve a memory by ID |
|
|
151
|
+
| `memory_forget` | Delete by ID or by query. Optional `agentId` to scope deletion to a specific agent. |
|
|
152
|
+
|
|
153
|
+
## CLI
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
# Search all memories (long-term + session)
|
|
157
|
+
openclaw mem0 search "what languages does the user know"
|
|
158
|
+
|
|
159
|
+
# Search only long-term memories
|
|
160
|
+
openclaw mem0 search "what languages does the user know" --scope long-term
|
|
161
|
+
|
|
162
|
+
# Search only session/short-term memories
|
|
163
|
+
openclaw mem0 search "what languages does the user know" --scope session
|
|
164
|
+
|
|
165
|
+
# Stats
|
|
166
|
+
openclaw mem0 stats
|
|
167
|
+
|
|
168
|
+
# Search a specific agent's memories
|
|
169
|
+
openclaw mem0 search "user preferences" --agent researcher
|
|
170
|
+
|
|
171
|
+
# Stats for a specific agent
|
|
172
|
+
openclaw mem0 stats --agent researcher
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Options
|
|
176
|
+
|
|
177
|
+
### General
|
|
178
|
+
|
|
179
|
+
| Key | Type | Default | |
|
|
180
|
+
|-----|------|---------|---|
|
|
181
|
+
| `mode` | `"platform"` \| `"open-source"` | `"platform"` | Which backend to use |
|
|
182
|
+
| `userId` | `string` | `"default"` | Any unique identifier you choose for the user (e.g. `"alice"`, `"user_123"`). All memories are scoped to this value. Not found in any dashboard — you define it yourself. |
|
|
183
|
+
| `autoRecall` | `boolean` | `true` | Inject memories before each turn |
|
|
184
|
+
| `autoCapture` | `boolean` | `true` | Store facts after each turn |
|
|
185
|
+
| `topK` | `number` | `5` | Max memories per recall |
|
|
186
|
+
| `searchThreshold` | `number` | `0.3` | Min similarity (0–1) |
|
|
187
|
+
|
|
188
|
+
### Platform mode
|
|
189
|
+
|
|
190
|
+
| Key | Type | Default | |
|
|
191
|
+
|-----|------|---------|---|
|
|
192
|
+
| `apiKey` | `string` | — | **Required.** Mem0 API key (supports `${MEM0_API_KEY}`) |
|
|
193
|
+
| `orgId` | `string` | — | Organization ID |
|
|
194
|
+
| `projectId` | `string` | — | Project ID |
|
|
195
|
+
| `enableGraph` | `boolean` | `false` | Entity graph for relationships. In open-source mode, requires `oss.graphStore`. |
|
|
196
|
+
| `customInstructions` | `string` | *(built-in)* | Extraction rules — what to store, how to format |
|
|
197
|
+
| `customCategories` | `object` | *(12 defaults)* | Category name → description map for tagging |
|
|
198
|
+
|
|
199
|
+
### Open-source mode
|
|
200
|
+
|
|
201
|
+
Works with zero extra config. The `oss` block lets you swap out any component:
|
|
202
|
+
|
|
203
|
+
| Key | Type | Default | |
|
|
204
|
+
|-----|------|---------|---|
|
|
205
|
+
| `customPrompt` | `string` | *(built-in)* | Extraction prompt for memory processing |
|
|
206
|
+
| `oss.embedder.provider` | `string` | `"openai"` | Embedding provider (`"openai"`, `"ollama"`, etc.) |
|
|
207
|
+
| `oss.embedder.config` | `object` | — | Provider config: `apiKey`, `model`, `baseURL` |
|
|
208
|
+
| `oss.vectorStore.provider` | `string` | `"memory"` | Vector store (`"memory"`, `"qdrant"`, `"chroma"`, etc.) |
|
|
209
|
+
| `oss.vectorStore.config` | `object` | — | Provider config: `host`, `port`, `collectionName`, `dimension` |
|
|
210
|
+
| `oss.llm.provider` | `string` | `"openai"` | LLM provider (`"openai"`, `"anthropic"`, `"ollama"`, etc.) |
|
|
211
|
+
| `oss.llm.config` | `object` | — | Provider config: `apiKey`, `model`, `baseURL`, `temperature` |
|
|
212
|
+
| `oss.graphStore.provider` | `string` | — | Graph backend (`"neo4j"`, `"memgraph"`, `"neptune"`, `"kuzu"`, etc.) |
|
|
213
|
+
| `oss.graphStore.config` | `object` | — | Provider config: backend connection details such as `url`, `username`, `password`, `database` |
|
|
214
|
+
| `oss.graphStore.customPrompt` | `string` | — | Optional graph extraction prompt override |
|
|
215
|
+
| `oss.graphStore.threshold` | `number` | provider default | Optional graph matching threshold |
|
|
216
|
+
| `oss.historyDbPath` | `string` | — | SQLite path for memory edit history |
|
|
217
|
+
|
|
218
|
+
Everything inside `oss` is optional — defaults use OpenAI embeddings (`text-embedding-3-small`), in-memory vector store, and OpenAI LLM. Override only what you need.
|
|
219
|
+
|
|
220
|
+
## License
|
|
221
|
+
|
|
222
|
+
Apache 2.0
|