@memtensor/memos-cloud-openclaw-plugin 0.1.19 → 0.1.20

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/README.md CHANGED
@@ -1,316 +1,316 @@
1
- # MemOS Cloud OpenClaw Plugin (Lifecycle)
2
-
3
- Official plugin maintained by MemTensor.
4
-
5
- A minimal OpenClaw lifecycle plugin that **recalls** memories from MemOS Cloud before each run and **adds** new messages to MemOS Cloud after each run.
6
-
7
- ## Features
8
- - **Recall**: `before_prompt_build` (`before_agent_start` on older OpenClaw hosts) → `/search/memory`
9
- - **Add**: `agent_end` → `/add/message`
10
- - **Config UI**: starting the gateway also starts a local plugin config page for editing `plugins.entries.memos-cloud-openclaw-plugin.config`
11
- - Uses **Token** auth (`Authorization: Token <MEMOS_API_KEY>`)
12
-
13
- ## Config UI
14
- - On gateway start, the plugin launches a local config page and prints the URL in the terminal (default: `http://127.0.0.1:38463`).
15
- - The page reads and writes the host config file directly:
16
- - OpenClaw: `~/.openclaw/openclaw.json`
17
- - Moltbot: `~/.moltbot/moltbot.json`
18
- - ClawDBot: `~/.clawdbot/clawdbot.json`
19
- - If the preferred UI port is already in use, the plugin automatically picks the next free port.
20
- - Saving changes writes `plugins.entries.memos-cloud-openclaw-plugin.config`. (Note: you may need to manually restart the gateway after saving for settings to take effect).
21
-
22
- ## Install
23
-
24
- ### Option A — NPM (Recommended)
25
- ```bash
26
- openclaw plugins install @memtensor/memos-cloud-openclaw-plugin@latest
27
- openclaw gateway restart
28
- ```
29
-
30
- > **Note for Windows Users**:
31
- > If you encounter `Error: spawn EINVAL`, this is a known issue with OpenClaw's plugin installer on Windows. Please use **Option B** (Manual Install) below.
32
-
33
- Make sure it’s enabled in `~/.openclaw/openclaw.json`:
34
- ```json
35
- {
36
- "plugins": {
37
- "entries": {
38
- "memos-cloud-openclaw-plugin": { "enabled": true }
39
- }
40
- }
41
- }
42
- ```
43
-
44
- ### Option B — Manual Install (Workaround for Windows)
45
- 1. Download the latest `.tgz` from [NPM](https://www.npmjs.com/package/@memtensor/memos-cloud-openclaw-plugin).
46
- 2. Extract it to a local folder (e.g., `C:\Users\YourName\.openclaw\extensions\memos-cloud-openclaw-plugin`).
47
- 3. Configure `~/.openclaw/openclaw.json` (or `%USERPROFILE%\.openclaw\openclaw.json`):
48
-
49
- ```json
50
- {
51
- "plugins": {
52
- "entries": {
53
- "memos-cloud-openclaw-plugin": { "enabled": true }
54
- },
55
- "load": {
56
- "paths": [
57
- "C:\\Users\\YourName\\.openclaw\\extensions\\memos-cloud-openclaw-plugin"
58
- ]
59
- }
60
- }
61
- }
62
- ```
63
- *Note: The extracted folder usually contains a `package` subfolder. Point to the folder containing `package.json`.*
64
-
65
- Restart the gateway after config changes.
66
-
67
- ## Environment Variables
68
- The plugin resolves runtime config in this order: **plugin config → env files**. Due to strict security sandboxing, it **does not** read credentials from process environment variables.
69
- For env files, it tries them in order (**openclaw → moltbot → clawdbot**). For each key, the first file with a value wins.
70
-
71
- **Where to configure**
72
- - Files (priority order):
73
- - `~/.openclaw/.env`
74
- - `~/.moltbot/.env`
75
- - `~/.clawdbot/.env`
76
- - Each line is `KEY=value`
77
-
78
- **Quick setup (shell / Windows)**
79
- ```bash
80
- echo 'MEMOS_API_KEY="mpg-..."' >> ~/.openclaw/.env
81
- ```
82
-
83
- If `MEMOS_API_KEY` is missing, the plugin will warn with setup instructions and the API key URL.
84
-
85
- **Minimal config**
86
- ```env
87
- MEMOS_API_KEY=YOUR_TOKEN
88
- ```
89
-
90
- **Optional config**
91
- - `MEMOS_BASE_URL` (default: `https://memos.memtensor.cn/api/openmem/v1`)
92
- - `MEMOS_API_KEY` (required; Token auth) — get it at https://memos-dashboard.openmem.net/cn/apikeys/
93
- - `MEMOS_USER_ID` (optional; default: `openclaw-user`)
94
- - `MEMOS_USE_DIRECT_SESSION_USER_ID` (default: `false`; when enabled, direct session keys like `agent:main:<provider>:direct:<peer-id>` use `<peer-id>` as MemOS `user_id`)
95
- - `MEMOS_CONVERSATION_ID` (optional override)
96
- - `MEMOS_KNOWLEDGEBASE_IDS` (optional; comma-separated global knowledge base IDs for `/search/memory`, e.g., `"kb-123, kb-456"`)
97
- - `MEMOS_ALLOW_KNOWLEDGEBASE_IDS` (optional; comma-separated knowledge base IDs for `/add/message`, e.g., `"kb-123"`)
98
- - `MEMOS_TAGS` (optional; comma-separated tags for `/add/message`, default: `"openclaw"`, e.g., `"openclaw, dev"`)
99
- - `MEMOS_RECALL_GLOBAL` (default: `true`; when true, search does **not** pass conversation_id)
100
- - `MEMOS_MULTI_AGENT_MODE` (default: `false`; enable multi-agent data isolation)
101
- - `MEMOS_ALLOWED_AGENTS` (optional; comma-separated allowlist for multi-agent mode, e.g. `"agent1,agent2"`; empty means all agents enabled)
102
- - `MEMOS_CONVERSATION_PREFIX` / `MEMOS_CONVERSATION_SUFFIX` (optional)
103
- - `MEMOS_CONVERSATION_SUFFIX_MODE` (`none` | `counter`, default: `none`)
104
- - `MEMOS_CONVERSATION_RESET_ON_NEW` (default: `true`, requires hooks.internal.enabled)
105
- - `MEMOS_RECALL_FILTER_ENABLED` (default: `false`; run model-based memory filtering before injection)
106
- - `MEMOS_RECALL_FILTER_BASE_URL` (OpenAI-compatible base URL, e.g. `http://127.0.0.1:11434/v1`)
107
- - `MEMOS_RECALL_FILTER_API_KEY` (optional; required if your endpoint needs auth)
108
- - `MEMOS_RECALL_FILTER_MODEL` (model name used to filter recall candidates)
109
- - `MEMOS_RECALL_FILTER_TIMEOUT_MS` (default: `30000`)
110
- - `MEMOS_RECALL_FILTER_RETRIES` (default: `1`)
111
- - `MEMOS_RECALL_FILTER_CANDIDATE_LIMIT` (default: `30` per category)
112
- - `MEMOS_RECALL_FILTER_MAX_ITEM_CHARS` (default: `500`)
113
- - `MEMOS_RECALL_FILTER_FAIL_OPEN` (default: `true`; fallback to unfiltered recall on failure)
114
- - `MEMOS_CAPTURE_STRATEGY` (default: `last_turn`)
115
- - `MEMOS_ASYNC_MODE` (default: `true`; non-blocking memory addition)
116
- - `MEMOS_THROTTLE_MS` (default: `0`; throttle memory requests)
117
- - `MEMOS_INCLUDE_ASSISTANT` (default: `true`; include assistant messages in memory)
118
- - `MEMOS_MAX_MESSAGE_CHARS` (default: `20000`; max characters for message history)
119
-
120
- ## Optional Plugin Config
121
- In `plugins.entries.memos-cloud-openclaw-plugin.config`:
122
- ```json
123
- {
124
- "baseUrl": "https://memos.memtensor.cn/api/openmem/v1",
125
- "apiKey": "YOUR_API_KEY",
126
- "userId": "memos_user_123",
127
- "useDirectSessionUserId": false,
128
- "conversationId": "openclaw-main",
129
- "queryPrefix": "important user context preferences decisions ",
130
- "recallEnabled": true,
131
- "recallGlobal": true,
132
- "addEnabled": true,
133
- "captureStrategy": "last_turn",
134
- "maxItemChars": 8000,
135
- "includeAssistant": true,
136
- "conversationIdPrefix": "",
137
- "conversationIdSuffix": "",
138
- "conversationSuffixMode": "none",
139
- "resetOnNew": true,
140
- "knowledgebaseIds": [],
141
- "memoryLimitNumber": 6,
142
- "preferenceLimitNumber": 6,
143
- "includePreference": true,
144
- "includeToolMemory": false,
145
- "toolMemoryLimitNumber": 6,
146
- "relativity": 0.45,
147
- "tags": ["openclaw"],
148
- "agentId": "",
149
- "multiAgentMode": false,
150
- "allowedAgents": [],
151
- "asyncMode": true,
152
- "recallFilterEnabled": false,
153
- "recallFilterBaseUrl": "http://127.0.0.1:11434/v1",
154
- "recallFilterApiKey": "",
155
- "recallFilterModel": "qwen2.5:7b",
156
- "recallFilterTimeoutMs": 30000,
157
- "recallFilterRetries": 1,
158
- "recallFilterCandidateLimit": 30,
159
- "recallFilterMaxItemChars": 500,
160
- "recallFilterFailOpen": true,
161
- "throttleMs": 0,
162
- "maxMessageChars": 20000
163
- }
164
- ```
165
-
166
- ## How it Works
167
- - **Recall** (`before_prompt_build`; falls back to `before_agent_start` on older OpenClaw hosts)
168
- - Builds a `/search/memory` request using `user_id`, `query` (= prompt + optional prefix), and optional filters.
169
- - Default **global recall**: when `recallGlobal=true`, it does **not** pass `conversation_id`.
170
- - Optional second-pass filtering: if `recallFilterEnabled=true`, candidates are sent to your configured model and only returned `keep` items are injected.
171
- - Injects a stable MemOS recall protocol via `appendSystemContext`, while the retrieved `<memories>` block remains in `prependContext`.
172
-
173
- - **Add** (`agent_end`)
174
- - Builds a `/add/message` request with the **last turn** by default (user + assistant).
175
- - Sends `messages` with `user_id`, `conversation_id`, and optional `tags/info/agent_id/app_id`.
176
-
177
- ## Multi-Agent Support
178
- The plugin provides native support for multi-agent architectures (via the `agent_id` parameter):
179
- - **Enable Mode**: Set `"multiAgentMode": true` in config or `MEMOS_MULTI_AGENT_MODE=true` in env variables (default is `false`).
180
- - **Dynamic Context**: When enabled, it automatically captures `ctx.agentId` during OpenClaw lifecycle hooks. (Note: the default OpenClaw agent `"main"` is ignored to preserve backwards compatibility for single-agent users).
181
- - **Data Isolation**: The `agent_id` is automatically injected into both `/search/memory` and `/add/message` requests. This ensures completely isolated memory and message histories for different agents, even under the same user or session.
182
- - **Static Override**: You can also force a specific agent ID by setting `"agentId": "your_agent_id"` in the plugin's `config`.
183
-
184
- ### Per-Agent Memory Toggle
185
-
186
- In multi-agent mode, you can use `MEMOS_ALLOWED_AGENTS` to control exactly which agents have memory enabled. Agents not in the allowlist will skip both memory recall and memory capture entirely.
187
-
188
- **Environment variable** (in `~/.openclaw/.env`):
189
- ```env
190
- MEMOS_MULTI_AGENT_MODE=true
191
- MEMOS_ALLOWED_AGENTS="agent1,agent2"
192
- ```
193
-
194
- Separate multiple agent IDs with commas.
195
-
196
- **Plugin config** (in `openclaw.json`):
197
- ```json
198
- {
199
- "plugins": {
200
- "entries": {
201
- "memos-cloud-openclaw-plugin": {
202
- "enabled": true,
203
- "config": {
204
- "multiAgentMode": true,
205
- "allowedAgents": ["agent1", "agent2"]
206
- }
207
- }
208
- }
209
- }
210
- }
211
- ```
212
-
213
- **Behavior**:
214
- | Config | Effect |
215
- |--------|--------|
216
- | `MEMOS_ALLOWED_AGENTS` unset or empty | All agents have memory enabled |
217
- | `MEMOS_ALLOWED_AGENTS="agent1,agent2"` | Only `agent1` and `agent2` are enabled; others are skipped |
218
- | `MEMOS_ALLOWED_AGENTS="agent1"` | Only `agent1` is enabled; all other agents are skipped |
219
- | `MEMOS_MULTI_AGENT_MODE=false` | Allowlist has no effect; all requests use single-agent mode |
220
-
221
- > **Note**: The allowlist only takes effect when `multiAgentMode=true`. When multi-agent mode is off, memory works for all agents and the allowlist is ignored.
222
-
223
- ### Per-Agent Configuration (agentOverrides)
224
-
225
- Beyond simple on/off toggles, you can configure **different memory parameters for each agent** using `agentOverrides`. Each agent can have its own knowledge base, recall limits, relativity threshold, and more.
226
-
227
- **Plugin config** (in `openclaw.json`):
228
- ```json
229
- {
230
- "plugins": {
231
- "entries": {
232
- "memos-cloud-openclaw-plugin": {
233
- "enabled": true,
234
- "config": {
235
- "multiAgentMode": true,
236
- "allowedAgents": ["default", "research-agent", "coding-agent"],
237
- "knowledgebaseIds": [],
238
- "memoryLimitNumber": 6,
239
- "relativity": 0.45,
240
-
241
- "agentOverrides": {
242
- "research-agent": {
243
- "knowledgebaseIds": ["kb-research-papers", "kb-academic"],
244
- "memoryLimitNumber": 12,
245
- "relativity": 0.3,
246
- "includeToolMemory": true,
247
- "captureStrategy": "full_session",
248
- "queryPrefix": "research context: "
249
- },
250
- "coding-agent": {
251
- "knowledgebaseIds": ["kb-codebase", "kb-api-docs"],
252
- "memoryLimitNumber": 9,
253
- "relativity": 0.5,
254
- "addEnabled": false
255
- }
256
- }
257
- }
258
- }
259
- }
260
- }
261
- }
262
- ```
263
-
264
- **Environment variable** (in `~/.openclaw/.env`):
265
- You can use `MEMOS_AGENT_OVERRIDES` to configure a JSON string to override global parameters. Note: `.env` configuration has a lower priority than `agentOverrides` in `openclaw.json`.
266
- ```env
267
- MEMOS_AGENT_OVERRIDES='{"research-agent": {"memoryLimitNumber": 12, "relativity": 0.3}, "coding-agent": {"memoryLimitNumber": 9}}'
268
- ```
269
-
270
- **How it works**:
271
- - Fields in `agentOverrides.<agentId>` override the global defaults for that specific agent.
272
- - Only the fields you specify are overridden; all other parameters inherit from the global config.
273
- - If no override exists for an agent, it uses the global config as-is.
274
-
275
- **Overridable fields**:
276
-
277
- | Field | Description |
278
- |-------|-------------|
279
- | `knowledgebaseIds` | Knowledge base IDs for `/search/memory` |
280
- | `memoryLimitNumber` | Max memory items to recall |
281
- | `preferenceLimitNumber` | Max preference items to recall |
282
- | `includePreference` | Enable preference recall |
283
- | `includeToolMemory` | Enable tool memory recall |
284
- | `toolMemoryLimitNumber` | Max tool memory items |
285
- | `relativity` | Relevance threshold (0-1) |
286
- | `recallEnabled` | Enable/disable recall for this agent |
287
- | `addEnabled` | Enable/disable memory capture for this agent |
288
- | `captureStrategy` | `last_turn` or `full_session` |
289
- | `queryPrefix` | Prefix for search queries |
290
- | `maxItemChars` | Max chars per memory item in prompt |
291
- | `maxMessageChars` | Max chars per message when adding |
292
- | `includeAssistant` | Include assistant messages in capture |
293
- | `recallGlobal` | Global recall (skip conversation_id) |
294
- | `recallFilterEnabled` | Enable model-based recall filtering |
295
- | `recallFilterModel` | Model for recall filtering |
296
- | `recallFilterBaseUrl` | Base URL for recall filter model |
297
- | `recallFilterApiKey` | API key for recall filter |
298
- | `allowKnowledgebaseIds` | Knowledge bases for `/add/message` |
299
- | `tags` | Tags for `/add/message` |
300
- | `throttleMs` | Throttle interval |
301
-
302
- ## Direct Session User ID
303
- - **Default behavior**: the plugin still uses the configured `userId` (or `MEMOS_USER_ID`) and stays fully backward compatible.
304
- - **Enable mode**: set `"useDirectSessionUserId": true` in plugin config or `MEMOS_USE_DIRECT_SESSION_USER_ID=true` in env.
305
- - **What it does**: when enabled, session keys like `agent:main:<provider>:direct:<peer-id>` reuse `<peer-id>` as MemOS `user_id`.
306
- - **What it does not do**: non-direct session keys such as `agent:main:<provider>:channel:<channel-id>` keep using the configured fallback `userId`.
307
- - **Request paths affected**: the same resolver is used by both `buildSearchPayload()` and `buildAddMessagePayload()`, so recall and add stay consistent.
308
- - **Config precedence**: runtime config still follows the same rule as the rest of the plugin - plugin config first, then `.env` files (`~/.openclaw/.env` -> `~/.moltbot/.env` -> `~/.clawdbot/.env`).
309
-
310
-
311
- ## Notes
312
- - `conversation_id` defaults to OpenClaw `sessionKey` (unless `conversationId` is provided). **TODO**: consider binding to OpenClaw `sessionId` directly.
313
- - Optional **prefix/suffix** via env or config; `conversationSuffixMode=counter` increments on `/new` (requires `hooks.internal.enabled`).
314
-
315
- ## Acknowledgements
316
- - Thanks to @anatolykoptev (Contributor) — LinkedIn: https://www.linkedin.com/in/koptev?utm_source=share&utm_campaign=share_via&utm_content=profile&utm_medium=ios_app
1
+ # MemOS Cloud OpenClaw Plugin (Lifecycle)
2
+
3
+ Official plugin maintained by MemTensor.
4
+
5
+ A minimal OpenClaw lifecycle plugin that **recalls** memories from MemOS Cloud before each run and **adds** new messages to MemOS Cloud after each run.
6
+
7
+ ## Features
8
+ - **Recall**: `before_prompt_build` (`before_agent_start` on older OpenClaw hosts) → `/search/memory`
9
+ - **Add**: `agent_end` → `/add/message`
10
+ - **Config UI**: starting the gateway also starts a local plugin config page for editing `plugins.entries.memos-cloud-openclaw-plugin.config`
11
+ - Uses **Token** auth (`Authorization: Token <MEMOS_API_KEY>`)
12
+
13
+ ## Config UI
14
+ - On gateway start, the plugin launches a local config page and prints the URL in the terminal (default: `http://127.0.0.1:38463`).
15
+ - The page reads and writes the host config file directly:
16
+ - OpenClaw: `~/.openclaw/openclaw.json`
17
+ - Moltbot: `~/.moltbot/moltbot.json`
18
+ - ClawDBot: `~/.clawdbot/clawdbot.json`
19
+ - If the preferred UI port is already in use, the plugin automatically picks the next free port.
20
+ - Saving changes writes `plugins.entries.memos-cloud-openclaw-plugin.config`. (Note: you may need to manually restart the gateway after saving for settings to take effect).
21
+
22
+ ## Install
23
+
24
+ ### Option A — NPM (Recommended)
25
+ ```bash
26
+ openclaw plugins install @memtensor/memos-cloud-openclaw-plugin@latest
27
+ openclaw gateway restart
28
+ ```
29
+
30
+ > **Note for Windows Users**:
31
+ > If you encounter `Error: spawn EINVAL`, this is a known issue with OpenClaw's plugin installer on Windows. Please use **Option B** (Manual Install) below.
32
+
33
+ Make sure it’s enabled in `~/.openclaw/openclaw.json`:
34
+ ```json
35
+ {
36
+ "plugins": {
37
+ "entries": {
38
+ "memos-cloud-openclaw-plugin": { "enabled": true }
39
+ }
40
+ }
41
+ }
42
+ ```
43
+
44
+ ### Option B — Manual Install (Workaround for Windows)
45
+ 1. Download the latest `.tgz` from [NPM](https://www.npmjs.com/package/@memtensor/memos-cloud-openclaw-plugin).
46
+ 2. Extract it to a local folder (e.g., `C:\Users\YourName\.openclaw\extensions\memos-cloud-openclaw-plugin`).
47
+ 3. Configure `~/.openclaw/openclaw.json` (or `%USERPROFILE%\.openclaw\openclaw.json`):
48
+
49
+ ```json
50
+ {
51
+ "plugins": {
52
+ "entries": {
53
+ "memos-cloud-openclaw-plugin": { "enabled": true }
54
+ },
55
+ "load": {
56
+ "paths": [
57
+ "C:\\Users\\YourName\\.openclaw\\extensions\\memos-cloud-openclaw-plugin"
58
+ ]
59
+ }
60
+ }
61
+ }
62
+ ```
63
+ *Note: The extracted folder usually contains a `package` subfolder. Point to the folder containing `package.json`.*
64
+
65
+ Restart the gateway after config changes.
66
+
67
+ ## Environment Variables
68
+ The plugin resolves runtime config in this order: **plugin config → env files**. Due to strict security sandboxing, it **does not** read credentials from process environment variables.
69
+ For env files, it tries them in order (**openclaw → moltbot → clawdbot**). For each key, the first file with a value wins.
70
+
71
+ **Where to configure**
72
+ - Files (priority order):
73
+ - `~/.openclaw/.env`
74
+ - `~/.moltbot/.env`
75
+ - `~/.clawdbot/.env`
76
+ - Each line is `KEY=value`
77
+
78
+ **Quick setup (shell / Windows)**
79
+ ```bash
80
+ echo 'MEMOS_API_KEY="mpg-..."' >> ~/.openclaw/.env
81
+ ```
82
+
83
+ If `MEMOS_API_KEY` is missing, the plugin will warn with setup instructions and the API key URL.
84
+
85
+ **Minimal config**
86
+ ```env
87
+ MEMOS_API_KEY=YOUR_TOKEN
88
+ ```
89
+
90
+ **Optional config**
91
+ - `MEMOS_BASE_URL` (default: `https://memos.memtensor.cn/api/openmem/v1`)
92
+ - `MEMOS_API_KEY` (required; Token auth) — get it at https://memos-dashboard.openmem.net/cn/apikeys/
93
+ - `MEMOS_USER_ID` (optional; default: `openclaw-user`)
94
+ - `MEMOS_USE_DIRECT_SESSION_USER_ID` (default: `false`; when enabled, direct session keys like `agent:main:<provider>:direct:<peer-id>` use `<peer-id>` as MemOS `user_id`)
95
+ - `MEMOS_CONVERSATION_ID` (optional override)
96
+ - `MEMOS_KNOWLEDGEBASE_IDS` (optional; comma-separated global knowledge base IDs for `/search/memory`, e.g., `"kb-123, kb-456"`)
97
+ - `MEMOS_ALLOW_KNOWLEDGEBASE_IDS` (optional; comma-separated knowledge base IDs for `/add/message`, e.g., `"kb-123"`)
98
+ - `MEMOS_TAGS` (optional; comma-separated tags for `/add/message`, default: `"openclaw"`, e.g., `"openclaw, dev"`)
99
+ - `MEMOS_RECALL_GLOBAL` (default: `true`; when true, search does **not** pass conversation_id)
100
+ - `MEMOS_MULTI_AGENT_MODE` (default: `false`; enable multi-agent data isolation)
101
+ - `MEMOS_ALLOWED_AGENTS` (optional; comma-separated allowlist for multi-agent mode, e.g. `"agent1,agent2"`; empty means all agents enabled)
102
+ - `MEMOS_CONVERSATION_PREFIX` / `MEMOS_CONVERSATION_SUFFIX` (optional)
103
+ - `MEMOS_CONVERSATION_SUFFIX_MODE` (`none` | `counter`, default: `none`)
104
+ - `MEMOS_CONVERSATION_RESET_ON_NEW` (default: `true`, requires hooks.internal.enabled)
105
+ - `MEMOS_RECALL_FILTER_ENABLED` (default: `false`; run model-based memory filtering before injection)
106
+ - `MEMOS_RECALL_FILTER_BASE_URL` (OpenAI-compatible base URL, e.g. `http://127.0.0.1:11434/v1`)
107
+ - `MEMOS_RECALL_FILTER_API_KEY` (optional; required if your endpoint needs auth)
108
+ - `MEMOS_RECALL_FILTER_MODEL` (model name used to filter recall candidates)
109
+ - `MEMOS_RECALL_FILTER_TIMEOUT_MS` (default: `30000`)
110
+ - `MEMOS_RECALL_FILTER_RETRIES` (default: `1`)
111
+ - `MEMOS_RECALL_FILTER_CANDIDATE_LIMIT` (default: `30` per category)
112
+ - `MEMOS_RECALL_FILTER_MAX_ITEM_CHARS` (default: `500`)
113
+ - `MEMOS_RECALL_FILTER_FAIL_OPEN` (default: `true`; fallback to unfiltered recall on failure)
114
+ - `MEMOS_CAPTURE_STRATEGY` (default: `last_turn`)
115
+ - `MEMOS_ASYNC_MODE` (default: `true`; non-blocking memory addition)
116
+ - `MEMOS_THROTTLE_MS` (default: `0`; throttle memory requests)
117
+ - `MEMOS_INCLUDE_ASSISTANT` (default: `true`; include assistant messages in memory)
118
+ - `MEMOS_MAX_MESSAGE_CHARS` (default: `20000`; max characters for message history)
119
+
120
+ ## Optional Plugin Config
121
+ In `plugins.entries.memos-cloud-openclaw-plugin.config`:
122
+ ```json
123
+ {
124
+ "baseUrl": "https://memos.memtensor.cn/api/openmem/v1",
125
+ "apiKey": "YOUR_API_KEY",
126
+ "userId": "memos_user_123",
127
+ "useDirectSessionUserId": false,
128
+ "conversationId": "openclaw-main",
129
+ "queryPrefix": "important user context preferences decisions ",
130
+ "recallEnabled": true,
131
+ "recallGlobal": true,
132
+ "addEnabled": true,
133
+ "captureStrategy": "last_turn",
134
+ "maxItemChars": 8000,
135
+ "includeAssistant": true,
136
+ "conversationIdPrefix": "",
137
+ "conversationIdSuffix": "",
138
+ "conversationSuffixMode": "none",
139
+ "resetOnNew": true,
140
+ "knowledgebaseIds": [],
141
+ "memoryLimitNumber": 6,
142
+ "preferenceLimitNumber": 6,
143
+ "includePreference": true,
144
+ "includeToolMemory": false,
145
+ "toolMemoryLimitNumber": 6,
146
+ "relativity": 0.45,
147
+ "tags": ["openclaw"],
148
+ "agentId": "",
149
+ "multiAgentMode": false,
150
+ "allowedAgents": [],
151
+ "asyncMode": true,
152
+ "recallFilterEnabled": false,
153
+ "recallFilterBaseUrl": "http://127.0.0.1:11434/v1",
154
+ "recallFilterApiKey": "",
155
+ "recallFilterModel": "qwen2.5:7b",
156
+ "recallFilterTimeoutMs": 30000,
157
+ "recallFilterRetries": 1,
158
+ "recallFilterCandidateLimit": 30,
159
+ "recallFilterMaxItemChars": 500,
160
+ "recallFilterFailOpen": true,
161
+ "throttleMs": 0,
162
+ "maxMessageChars": 20000
163
+ }
164
+ ```
165
+
166
+ ## How it Works
167
+ - **Recall** (`before_prompt_build`; falls back to `before_agent_start` on older OpenClaw hosts)
168
+ - Builds a `/search/memory` request using `user_id`, `query` (= prompt + optional prefix), and optional filters.
169
+ - Default **global recall**: when `recallGlobal=true`, it does **not** pass `conversation_id`.
170
+ - Optional second-pass filtering: if `recallFilterEnabled=true`, candidates are sent to your configured model and only returned `keep` items are injected.
171
+ - Injects a stable MemOS recall protocol via `appendSystemContext`, while the retrieved `<memories>` block remains in `prependContext`.
172
+
173
+ - **Add** (`agent_end`)
174
+ - Builds a `/add/message` request with the **last turn** by default (user + assistant).
175
+ - Sends `messages` with `user_id`, `conversation_id`, and optional `tags/info/agent_id/app_id`.
176
+
177
+ ## Multi-Agent Support
178
+ The plugin provides native support for multi-agent architectures (via the `agent_id` parameter):
179
+ - **Enable Mode**: Set `"multiAgentMode": true` in config or `MEMOS_MULTI_AGENT_MODE=true` in env variables (default is `false`).
180
+ - **Dynamic Context**: When enabled, it automatically captures `ctx.agentId` during OpenClaw lifecycle hooks. (Note: the default OpenClaw agent `"main"` is ignored to preserve backwards compatibility for single-agent users).
181
+ - **Data Isolation**: The `agent_id` is automatically injected into both `/search/memory` and `/add/message` requests. This ensures completely isolated memory and message histories for different agents, even under the same user or session.
182
+ - **Static Override**: You can also force a specific agent ID by setting `"agentId": "your_agent_id"` in the plugin's `config`.
183
+
184
+ ### Per-Agent Memory Toggle
185
+
186
+ In multi-agent mode, you can use `MEMOS_ALLOWED_AGENTS` to control exactly which agents have memory enabled. Agents not in the allowlist will skip both memory recall and memory capture entirely.
187
+
188
+ **Environment variable** (in `~/.openclaw/.env`):
189
+ ```env
190
+ MEMOS_MULTI_AGENT_MODE=true
191
+ MEMOS_ALLOWED_AGENTS="agent1,agent2"
192
+ ```
193
+
194
+ Separate multiple agent IDs with commas.
195
+
196
+ **Plugin config** (in `openclaw.json`):
197
+ ```json
198
+ {
199
+ "plugins": {
200
+ "entries": {
201
+ "memos-cloud-openclaw-plugin": {
202
+ "enabled": true,
203
+ "config": {
204
+ "multiAgentMode": true,
205
+ "allowedAgents": ["agent1", "agent2"]
206
+ }
207
+ }
208
+ }
209
+ }
210
+ }
211
+ ```
212
+
213
+ **Behavior**:
214
+ | Config | Effect |
215
+ |--------|--------|
216
+ | `MEMOS_ALLOWED_AGENTS` unset or empty | All agents have memory enabled |
217
+ | `MEMOS_ALLOWED_AGENTS="agent1,agent2"` | Only `agent1` and `agent2` are enabled; others are skipped |
218
+ | `MEMOS_ALLOWED_AGENTS="agent1"` | Only `agent1` is enabled; all other agents are skipped |
219
+ | `MEMOS_MULTI_AGENT_MODE=false` | Allowlist has no effect; all requests use single-agent mode |
220
+
221
+ > **Note**: The allowlist only takes effect when `multiAgentMode=true`. When multi-agent mode is off, memory works for all agents and the allowlist is ignored.
222
+
223
+ ### Per-Agent Configuration (agentOverrides)
224
+
225
+ Beyond simple on/off toggles, you can configure **different memory parameters for each agent** using `agentOverrides`. Each agent can have its own knowledge base, recall limits, relativity threshold, and more.
226
+
227
+ **Plugin config** (in `openclaw.json`):
228
+ ```json
229
+ {
230
+ "plugins": {
231
+ "entries": {
232
+ "memos-cloud-openclaw-plugin": {
233
+ "enabled": true,
234
+ "config": {
235
+ "multiAgentMode": true,
236
+ "allowedAgents": ["default", "research-agent", "coding-agent"],
237
+ "knowledgebaseIds": [],
238
+ "memoryLimitNumber": 6,
239
+ "relativity": 0.45,
240
+
241
+ "agentOverrides": {
242
+ "research-agent": {
243
+ "knowledgebaseIds": ["kb-research-papers", "kb-academic"],
244
+ "memoryLimitNumber": 12,
245
+ "relativity": 0.3,
246
+ "includeToolMemory": true,
247
+ "captureStrategy": "full_session",
248
+ "queryPrefix": "research context: "
249
+ },
250
+ "coding-agent": {
251
+ "knowledgebaseIds": ["kb-codebase", "kb-api-docs"],
252
+ "memoryLimitNumber": 9,
253
+ "relativity": 0.5,
254
+ "addEnabled": false
255
+ }
256
+ }
257
+ }
258
+ }
259
+ }
260
+ }
261
+ }
262
+ ```
263
+
264
+ **Environment variable** (in `~/.openclaw/.env`):
265
+ You can use `MEMOS_AGENT_OVERRIDES` to configure a JSON string to override global parameters. Note: `.env` configuration has a lower priority than `agentOverrides` in `openclaw.json`.
266
+ ```env
267
+ MEMOS_AGENT_OVERRIDES='{"research-agent": {"memoryLimitNumber": 12, "relativity": 0.3}, "coding-agent": {"memoryLimitNumber": 9}}'
268
+ ```
269
+
270
+ **How it works**:
271
+ - Fields in `agentOverrides.<agentId>` override the global defaults for that specific agent.
272
+ - Only the fields you specify are overridden; all other parameters inherit from the global config.
273
+ - If no override exists for an agent, it uses the global config as-is.
274
+
275
+ **Overridable fields**:
276
+
277
+ | Field | Description |
278
+ |-------|-------------|
279
+ | `knowledgebaseIds` | Knowledge base IDs for `/search/memory` |
280
+ | `memoryLimitNumber` | Max memory items to recall |
281
+ | `preferenceLimitNumber` | Max preference items to recall |
282
+ | `includePreference` | Enable preference recall |
283
+ | `includeToolMemory` | Enable tool memory recall |
284
+ | `toolMemoryLimitNumber` | Max tool memory items |
285
+ | `relativity` | Relevance threshold (0-1) |
286
+ | `recallEnabled` | Enable/disable recall for this agent |
287
+ | `addEnabled` | Enable/disable memory capture for this agent |
288
+ | `captureStrategy` | `last_turn` or `full_session` |
289
+ | `queryPrefix` | Prefix for search queries |
290
+ | `maxItemChars` | Max chars per memory item in prompt |
291
+ | `maxMessageChars` | Max chars per message when adding |
292
+ | `includeAssistant` | Include assistant messages in capture |
293
+ | `recallGlobal` | Global recall (skip conversation_id) |
294
+ | `recallFilterEnabled` | Enable model-based recall filtering |
295
+ | `recallFilterModel` | Model for recall filtering |
296
+ | `recallFilterBaseUrl` | Base URL for recall filter model |
297
+ | `recallFilterApiKey` | API key for recall filter |
298
+ | `allowKnowledgebaseIds` | Knowledge bases for `/add/message` |
299
+ | `tags` | Tags for `/add/message` |
300
+ | `throttleMs` | Throttle interval |
301
+
302
+ ## Direct Session User ID
303
+ - **Default behavior**: the plugin still uses the configured `userId` (or `MEMOS_USER_ID`) and stays fully backward compatible.
304
+ - **Enable mode**: set `"useDirectSessionUserId": true` in plugin config or `MEMOS_USE_DIRECT_SESSION_USER_ID=true` in env.
305
+ - **What it does**: when enabled, session keys like `agent:main:<provider>:direct:<peer-id>` reuse `<peer-id>` as MemOS `user_id`.
306
+ - **What it does not do**: non-direct session keys such as `agent:main:<provider>:channel:<channel-id>` keep using the configured fallback `userId`.
307
+ - **Request paths affected**: the same resolver is used by both `buildSearchPayload()` and `buildAddMessagePayload()`, so recall and add stay consistent.
308
+ - **Config precedence**: runtime config still follows the same rule as the rest of the plugin - plugin config first, then `.env` files (`~/.openclaw/.env` -> `~/.moltbot/.env` -> `~/.clawdbot/.env`).
309
+
310
+
311
+ ## Notes
312
+ - `conversation_id` defaults to OpenClaw `sessionKey` (unless `conversationId` is provided). **TODO**: consider binding to OpenClaw `sessionId` directly.
313
+ - Optional **prefix/suffix** via env or config; `conversationSuffixMode=counter` increments on `/new` (requires `hooks.internal.enabled`).
314
+
315
+ ## Acknowledgements
316
+ - Thanks to @anatolykoptev (Contributor) — LinkedIn: https://www.linkedin.com/in/koptev?utm_source=share&utm_campaign=share_via&utm_content=profile&utm_medium=ios_app
@@ -2,7 +2,7 @@
2
2
  "id": "memos-cloud-openclaw-plugin",
3
3
  "name": "MemOS Cloud OpenClaw Plugin",
4
4
  "description": "MemOS Cloud recall + add memory via lifecycle hooks",
5
- "version": "0.1.19",
5
+ "version": "0.1.20",
6
6
  "kind": "lifecycle",
7
7
  "main": "./index.js",
8
8
  "activation": {