Skip to content

Commit 4baac27

Browse files
authored
fix: Update cloud plugin code (#1385)
## Description This PR updates the MemOS-Cloud-OpenClaw-Plugin to the latest version via git subtree . - Summary of change : Synced the latest commits from the upstream plugin repository ( MemTensor/MemOS-Cloud-OpenClaw-Plugin ) into the apps/MemOS-Cloud-OpenClaw-Plugin directory. - Problem it solves : Ensures the main MemOS repository uses the most up-to-date version of the OpenClaw plugin, including recent bug fixes and feature enhancements. - Implementation approach : Used git subtree pull --prefix=apps/MemOS-Cloud-OpenClaw-Plugin to sync the changes from the upstream plugin repository. ## Type of change Please delete options that are not relevant. - [x] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) ## How Has This Been Tested? I have verified the plugin functionality in the local development environment. - [ ] Unit Test - [x] Test Script Or Test Steps (please provide) 1. Started the local MemOS development server. 2. Verified that the `MemOS-Cloud-OpenClaw-Plugin` loads correctly without errors. 3. Tested the core functionalities of the updated plugin - [ ] Pipeline Automated API Test (please provide) ## Checklist - [x] I have performed a self-review of my own code | 我已自行检查了自己的代码 - [ ] I have commented my code in hard-to-understand areas | 我已在难以理解的地方对代码进行了注释 - [x] I have added tests that prove my fix is effective or that my feature works | 我已添加测试以证明我的修复有效或功能正常 - [ ] I have created related documentation issue/PR in [MemOS-Docs](https://github.com/MemTensor/MemOS-Docs) (if applicable) | 我已在 [MemOS-Docs](https://github.com/MemTensor/MemOS-Docs) 中创建了相关的文档 issue/PR(如果适用) - [ ] I have linked the issue to this PR (if applicable) | 我已将 issue 链接到此 PR(如果适用) - [ ] I have mentioned the person who will review this PR | 我已提及将审查此 PR 的人 ## Reviewer Checklist - [ ] closes #xxxx (Replace xxxx with the GitHub issue number) - [ ] Made sure Checks passed - [ ] Tests have been provided
2 parents 27c9e71 + f6d2357 commit 4baac27

10 files changed

Lines changed: 1625 additions & 71 deletions

File tree

apps/MemOS-Cloud-OpenClaw-Plugin/README.md

Lines changed: 149 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Make sure it’s enabled in `~/.openclaw/openclaw.json`:
4444
},
4545
"load": {
4646
"paths": [
47-
"C:\\Users\\YourName\\.openclaw\\extensions\\memos-cloud-openclaw-plugin\\package"
47+
"C:\\Users\\YourName\\.openclaw\\extensions\\memos-cloud-openclaw-plugin"
4848
]
4949
}
5050
}
@@ -55,7 +55,8 @@ Make sure it’s enabled in `~/.openclaw/openclaw.json`:
5555
Restart the gateway after config changes.
5656

5757
## Environment Variables
58-
The plugin tries env files in order (**openclaw → moltbot → clawdbot**). For each key, the first file with a value wins.
58+
The plugin resolves runtime config in this order: **plugin config → env files → process environment**.
59+
Among env files, it tries them in order (**openclaw → moltbot → clawdbot**). For each key, the first file with a value wins.
5960
If none of these files exist (or the key is missing), it falls back to the process environment.
6061

6162
**Where to configure**
@@ -91,21 +92,31 @@ MEMOS_API_KEY=YOUR_TOKEN
9192
- `MEMOS_BASE_URL` (default: `https://memos.memtensor.cn/api/openmem/v1`)
9293
- `MEMOS_API_KEY` (required; Token auth) — get it at https://memos-dashboard.openmem.net/cn/apikeys/
9394
- `MEMOS_USER_ID` (optional; default: `openclaw-user`)
95+
- `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`)
9496
- `MEMOS_CONVERSATION_ID` (optional override)
97+
- `MEMOS_KNOWLEDGEBASE_IDS` (optional; comma-separated global knowledge base IDs for `/search/memory`, e.g., `"kb-123, kb-456"`)
98+
- `MEMOS_ALLOW_KNOWLEDGEBASE_IDS` (optional; comma-separated knowledge base IDs for `/add/message`, e.g., `"kb-123"`)
99+
- `MEMOS_TAGS` (optional; comma-separated tags for `/add/message`, default: `"openclaw"`, e.g., `"openclaw, dev"`)
95100
- `MEMOS_RECALL_GLOBAL` (default: `true`; when true, search does **not** pass conversation_id)
96101
- `MEMOS_MULTI_AGENT_MODE` (default: `false`; enable multi-agent data isolation)
102+
- `MEMOS_ALLOWED_AGENTS` (optional; comma-separated allowlist for multi-agent mode, e.g. `"agent1,agent2"`; empty means all agents enabled)
97103
- `MEMOS_CONVERSATION_PREFIX` / `MEMOS_CONVERSATION_SUFFIX` (optional)
98104
- `MEMOS_CONVERSATION_SUFFIX_MODE` (`none` | `counter`, default: `none`)
99105
- `MEMOS_CONVERSATION_RESET_ON_NEW` (default: `true`, requires hooks.internal.enabled)
100106
- `MEMOS_RECALL_FILTER_ENABLED` (default: `false`; run model-based memory filtering before injection)
101107
- `MEMOS_RECALL_FILTER_BASE_URL` (OpenAI-compatible base URL, e.g. `http://127.0.0.1:11434/v1`)
102108
- `MEMOS_RECALL_FILTER_API_KEY` (optional; required if your endpoint needs auth)
103109
- `MEMOS_RECALL_FILTER_MODEL` (model name used to filter recall candidates)
104-
- `MEMOS_RECALL_FILTER_TIMEOUT_MS` (default: `6000`)
105-
- `MEMOS_RECALL_FILTER_RETRIES` (default: `0`)
110+
- `MEMOS_RECALL_FILTER_TIMEOUT_MS` (default: `30000`)
111+
- `MEMOS_RECALL_FILTER_RETRIES` (default: `1`)
106112
- `MEMOS_RECALL_FILTER_CANDIDATE_LIMIT` (default: `30` per category)
107113
- `MEMOS_RECALL_FILTER_MAX_ITEM_CHARS` (default: `500`)
108114
- `MEMOS_RECALL_FILTER_FAIL_OPEN` (default: `true`; fallback to unfiltered recall on failure)
115+
- `MEMOS_CAPTURE_STRATEGY` (default: `last_turn`)
116+
- `MEMOS_ASYNC_MODE` (default: `true`; non-blocking memory addition)
117+
- `MEMOS_THROTTLE_MS` (default: `0`; throttle memory requests)
118+
- `MEMOS_INCLUDE_ASSISTANT` (default: `true`; include assistant messages in memory)
119+
- `MEMOS_MAX_MESSAGE_CHARS` (default: `20000`; max characters for message history)
109120

110121
## Optional Plugin Config
111122
In `plugins.entries.memos-cloud-openclaw-plugin.config`:
@@ -114,6 +125,7 @@ In `plugins.entries.memos-cloud-openclaw-plugin.config`:
114125
"baseUrl": "https://memos.memtensor.cn/api/openmem/v1",
115126
"apiKey": "YOUR_API_KEY",
116127
"userId": "memos_user_123",
128+
"useDirectSessionUserId": false,
117129
"conversationId": "openclaw-main",
118130
"queryPrefix": "important user context preferences decisions ",
119131
"recallEnabled": true,
@@ -136,16 +148,19 @@ In `plugins.entries.memos-cloud-openclaw-plugin.config`:
136148
"tags": ["openclaw"],
137149
"agentId": "",
138150
"multiAgentMode": false,
151+
"allowedAgents": [],
139152
"asyncMode": true,
140153
"recallFilterEnabled": false,
141154
"recallFilterBaseUrl": "http://127.0.0.1:11434/v1",
142155
"recallFilterApiKey": "",
143156
"recallFilterModel": "qwen2.5:7b",
144-
"recallFilterTimeoutMs": 6000,
145-
"recallFilterRetries": 0,
157+
"recallFilterTimeoutMs": 30000,
158+
"recallFilterRetries": 1,
146159
"recallFilterCandidateLimit": 30,
147160
"recallFilterMaxItemChars": 500,
148-
"recallFilterFailOpen": true
161+
"recallFilterFailOpen": true,
162+
"throttleMs": 0,
163+
"maxMessageChars": 20000
149164
}
150165
```
151166

@@ -167,6 +182,133 @@ The plugin provides native support for multi-agent architectures (via the `agent
167182
- **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.
168183
- **Static Override**: You can also force a specific agent ID by setting `"agentId": "your_agent_id"` in the plugin's `config`.
169184

185+
### Per-Agent Memory Toggle
186+
187+
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.
188+
189+
**Environment variable** (in `~/.openclaw/.env`):
190+
```env
191+
MEMOS_MULTI_AGENT_MODE=true
192+
MEMOS_ALLOWED_AGENTS="agent1,agent2"
193+
```
194+
195+
Separate multiple agent IDs with commas.
196+
197+
**Plugin config** (in `openclaw.json`):
198+
```json
199+
{
200+
"plugins": {
201+
"entries": {
202+
"memos-cloud-openclaw-plugin": {
203+
"enabled": true,
204+
"config": {
205+
"multiAgentMode": true,
206+
"allowedAgents": ["agent1", "agent2"]
207+
}
208+
}
209+
}
210+
}
211+
}
212+
```
213+
214+
**Behavior**:
215+
| Config | Effect |
216+
|--------|--------|
217+
| `MEMOS_ALLOWED_AGENTS` unset or empty | All agents have memory enabled |
218+
| `MEMOS_ALLOWED_AGENTS="agent1,agent2"` | Only `agent1` and `agent2` are enabled; others are skipped |
219+
| `MEMOS_ALLOWED_AGENTS="agent1"` | Only `agent1` is enabled; all other agents are skipped |
220+
| `MEMOS_MULTI_AGENT_MODE=false` | Allowlist has no effect; all requests use single-agent mode |
221+
222+
> **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.
223+
224+
### Per-Agent Configuration (agentOverrides)
225+
226+
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.
227+
228+
**Plugin config** (in `openclaw.json`):
229+
```json
230+
{
231+
"plugins": {
232+
"entries": {
233+
"memos-cloud-openclaw-plugin": {
234+
"enabled": true,
235+
"config": {
236+
"multiAgentMode": true,
237+
"allowedAgents": ["default", "research-agent", "coding-agent"],
238+
"knowledgebaseIds": [],
239+
"memoryLimitNumber": 6,
240+
"relativity": 0.45,
241+
242+
"agentOverrides": {
243+
"research-agent": {
244+
"knowledgebaseIds": ["kb-research-papers", "kb-academic"],
245+
"memoryLimitNumber": 12,
246+
"relativity": 0.3,
247+
"includeToolMemory": true,
248+
"captureStrategy": "full_session",
249+
"queryPrefix": "research context: "
250+
},
251+
"coding-agent": {
252+
"knowledgebaseIds": ["kb-codebase", "kb-api-docs"],
253+
"memoryLimitNumber": 9,
254+
"relativity": 0.5,
255+
"addEnabled": false
256+
}
257+
}
258+
}
259+
}
260+
}
261+
}
262+
}
263+
```
264+
265+
**Environment variable** (in `~/.openclaw/.env`):
266+
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`.
267+
```env
268+
MEMOS_AGENT_OVERRIDES='{"research-agent": {"memoryLimitNumber": 12, "relativity": 0.3}, "coding-agent": {"memoryLimitNumber": 9}}'
269+
```
270+
271+
**How it works**:
272+
- Fields in `agentOverrides.<agentId>` override the global defaults for that specific agent.
273+
- Only the fields you specify are overridden; all other parameters inherit from the global config.
274+
- If no override exists for an agent, it uses the global config as-is.
275+
276+
**Overridable fields**:
277+
278+
| Field | Description |
279+
|-------|-------------|
280+
| `knowledgebaseIds` | Knowledge base IDs for `/search/memory` |
281+
| `memoryLimitNumber` | Max memory items to recall |
282+
| `preferenceLimitNumber` | Max preference items to recall |
283+
| `includePreference` | Enable preference recall |
284+
| `includeToolMemory` | Enable tool memory recall |
285+
| `toolMemoryLimitNumber` | Max tool memory items |
286+
| `relativity` | Relevance threshold (0-1) |
287+
| `recallEnabled` | Enable/disable recall for this agent |
288+
| `addEnabled` | Enable/disable memory capture for this agent |
289+
| `captureStrategy` | `last_turn` or `full_session` |
290+
| `queryPrefix` | Prefix for search queries |
291+
| `maxItemChars` | Max chars per memory item in prompt |
292+
| `maxMessageChars` | Max chars per message when adding |
293+
| `includeAssistant` | Include assistant messages in capture |
294+
| `recallGlobal` | Global recall (skip conversation_id) |
295+
| `recallFilterEnabled` | Enable model-based recall filtering |
296+
| `recallFilterModel` | Model for recall filtering |
297+
| `recallFilterBaseUrl` | Base URL for recall filter model |
298+
| `recallFilterApiKey` | API key for recall filter |
299+
| `allowKnowledgebaseIds` | Knowledge bases for `/add/message` |
300+
| `tags` | Tags for `/add/message` |
301+
| `throttleMs` | Throttle interval |
302+
303+
## Direct Session User ID
304+
- **Default behavior**: the plugin still uses the configured `userId` (or `MEMOS_USER_ID`) and stays fully backward compatible.
305+
- **Enable mode**: set `"useDirectSessionUserId": true` in plugin config or `MEMOS_USE_DIRECT_SESSION_USER_ID=true` in env.
306+
- **What it does**: when enabled, session keys like `agent:main:<provider>:direct:<peer-id>` reuse `<peer-id>` as MemOS `user_id`.
307+
- **What it does not do**: non-direct session keys such as `agent:main:<provider>:channel:<channel-id>` keep using the configured fallback `userId`.
308+
- **Request paths affected**: the same resolver is used by both `buildSearchPayload()` and `buildAddMessagePayload()`, so recall and add stay consistent.
309+
- **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`), then process env.
310+
311+
170312
## Notes
171313
- `conversation_id` defaults to OpenClaw `sessionKey` (unless `conversationId` is provided). **TODO**: consider binding to OpenClaw `sessionId` directly.
172314
- Optional **prefix/suffix** via env or config; `conversationSuffixMode=counter` increments on `/new` (requires `hooks.internal.enabled`).

0 commit comments

Comments
 (0)