@memtensor/memos-cloud-openclaw-plugin 0.1.7 → 0.1.8-beta.1

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,145 +1,155 @@
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_agent_start` → `/search/memory`
9
- - **Add**: `agent_end` → `/add/message`
10
- - Uses **Token** auth (`Authorization: Token <MEMOS_API_KEY>`)
11
-
12
- ## Install
13
-
14
- ### Option A — NPM (Recommended)
15
- ```bash
16
- openclaw plugins install @memtensor/memos-cloud-openclaw-plugin@latest
17
- openclaw gateway restart
18
- ```
19
-
20
- > **Note for Windows Users**:
21
- > 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.
22
-
23
- Make sure it’s enabled in `~/.openclaw/openclaw.json`:
24
- ```json
25
- {
26
- "plugins": {
27
- "entries": {
28
- "memos-cloud-openclaw-plugin": { "enabled": true }
29
- }
30
- }
31
- }
32
- ```
33
-
34
- ### Option B — Manual Install (Workaround for Windows)
35
- 1. Download the latest `.tgz` from [NPM](https://www.npmjs.com/package/@memtensor/memos-cloud-openclaw-plugin).
36
- 2. Extract it to a local folder (e.g., `C:\Users\YourName\.openclaw\extensions\memos-cloud-openclaw-plugin`).
37
- 3. Configure `~/.openclaw/openclaw.json` (or `%USERPROFILE%\.openclaw\openclaw.json`):
38
-
39
- ```json
40
- {
41
- "plugins": {
42
- "entries": {
43
- "memos-cloud-openclaw-plugin": { "enabled": true }
44
- },
45
- "load": {
46
- "paths": [
47
- "C:\\Users\\YourName\\.openclaw\\extensions\\memos-cloud-openclaw-plugin\\package"
48
- ]
49
- }
50
- }
51
- }
52
- ```
53
- *Note: The extracted folder usually contains a `package` subfolder. Point to the folder containing `package.json`.*
54
-
55
- Restart the gateway after config changes.
56
-
57
- ## Environment Variables
58
- The plugin tries env files in order (**openclaw → moltbot → clawdbot**). For each key, the first file with a value wins.
59
- If none of these files exist (or the key is missing), it falls back to the process environment.
60
-
61
- **Where to configure**
62
- - Files (priority order):
63
- - `~/.openclaw/.env`
64
- - `~/.moltbot/.env`
65
- - `~/.clawdbot/.env`
66
- - Each line is `KEY=value`
67
-
68
- **Quick setup (shell)**
69
- ```bash
70
- echo 'export MEMOS_API_KEY="mpg-..."' >> ~/.zshrc
71
- source ~/.zshrc
72
- # or
73
-
74
- echo 'export MEMOS_API_KEY="mpg-..."' >> ~/.bashrc
75
- source ~/.bashrc
76
- ```
77
-
78
- **Quick setup (Windows PowerShell)**
79
- ```powershell
80
- [System.Environment]::SetEnvironmentVariable("MEMOS_API_KEY", "mpg-...", "User")
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_CONVERSATION_ID` (optional override)
95
- - `MEMOS_RECALL_GLOBAL` (default: `true`; when true, search does **not** pass conversation_id)
96
- - `MEMOS_CONVERSATION_PREFIX` / `MEMOS_CONVERSATION_SUFFIX` (optional)
97
- - `MEMOS_CONVERSATION_SUFFIX_MODE` (`none` | `counter`, default: `none`)
98
- - `MEMOS_CONVERSATION_RESET_ON_NEW` (default: `true`, requires hooks.internal.enabled)
99
-
100
- ## Optional Plugin Config
101
- In `plugins.entries.memos-cloud-openclaw-plugin.config`:
102
- ```json
103
- {
104
- "baseUrl": "https://memos.memtensor.cn/api/openmem/v1",
105
- "apiKey": "YOUR_API_KEY",
106
- "userId": "memos_user_123",
107
- "conversationId": "openclaw-main",
108
- "queryPrefix": "important user context preferences decisions ",
109
- "recallEnabled": true,
110
- "recallGlobal": true,
111
- "addEnabled": true,
112
- "captureStrategy": "last_turn",
113
- "includeAssistant": true,
114
- "conversationIdPrefix": "",
115
- "conversationIdSuffix": "",
116
- "conversationSuffixMode": "none",
117
- "resetOnNew": true,
118
- "knowledgebaseIds": [],
119
- "memoryLimitNumber": 6,
120
- "preferenceLimitNumber": 6,
121
- "includePreference": true,
122
- "includeToolMemory": false,
123
- "toolMemoryLimitNumber": 6,
124
- "relativity": 0.45,
125
- "tags": ["openclaw"],
126
- "asyncMode": true
127
- }
128
- ```
129
-
130
- ## How it Works
131
- - **Recall** (`before_agent_start`)
132
- - Builds a `/search/memory` request using `user_id`, `query` (= prompt + optional prefix), and optional filters.
133
- - Default **global recall**: when `recallGlobal=true`, it does **not** pass `conversation_id`.
134
- - Formats a MemOS prompt (Role/System/Memory/Skill/Protocols) from `/search/memory` results, then injects via `prependContext`.
135
-
136
- - **Add** (`agent_end`)
137
- - Builds a `/add/message` request with the **last turn** by default (user + assistant).
138
- - Sends `messages` with `user_id`, `conversation_id`, and optional `tags/info/agent_id/app_id`.
139
-
140
- ## Notes
141
- - `conversation_id` defaults to OpenClaw `sessionKey` (unless `conversationId` is provided). **TODO**: consider binding to OpenClaw `sessionId` directly.
142
- - Optional **prefix/suffix** via env or config; `conversationSuffixMode=counter` increments on `/new` (requires `hooks.internal.enabled`).
143
-
144
- ## Acknowledgements
145
- - 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_agent_start` → `/search/memory`
9
+ - **Add**: `agent_end` → `/add/message`
10
+ - Uses **Token** auth (`Authorization: Token <MEMOS_API_KEY>`)
11
+
12
+ ## Install
13
+
14
+ ### Option A — NPM (Recommended)
15
+ ```bash
16
+ openclaw plugins install @memtensor/memos-cloud-openclaw-plugin@latest
17
+ openclaw gateway restart
18
+ ```
19
+
20
+ > **Note for Windows Users**:
21
+ > 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.
22
+
23
+ Make sure it’s enabled in `~/.openclaw/openclaw.json`:
24
+ ```json
25
+ {
26
+ "plugins": {
27
+ "entries": {
28
+ "memos-cloud-openclaw-plugin": { "enabled": true }
29
+ }
30
+ }
31
+ }
32
+ ```
33
+
34
+ ### Option B — Manual Install (Workaround for Windows)
35
+ 1. Download the latest `.tgz` from [NPM](https://www.npmjs.com/package/@memtensor/memos-cloud-openclaw-plugin).
36
+ 2. Extract it to a local folder (e.g., `C:\Users\YourName\.openclaw\extensions\memos-cloud-openclaw-plugin`).
37
+ 3. Configure `~/.openclaw/openclaw.json` (or `%USERPROFILE%\.openclaw\openclaw.json`):
38
+
39
+ ```json
40
+ {
41
+ "plugins": {
42
+ "entries": {
43
+ "memos-cloud-openclaw-plugin": { "enabled": true }
44
+ },
45
+ "load": {
46
+ "paths": [
47
+ "C:\\Users\\YourName\\.openclaw\\extensions\\memos-cloud-openclaw-plugin\\package"
48
+ ]
49
+ }
50
+ }
51
+ }
52
+ ```
53
+ *Note: The extracted folder usually contains a `package` subfolder. Point to the folder containing `package.json`.*
54
+
55
+ Restart the gateway after config changes.
56
+
57
+ ## Environment Variables
58
+ The plugin tries env files in order (**openclaw → moltbot → clawdbot**). For each key, the first file with a value wins.
59
+ If none of these files exist (or the key is missing), it falls back to the process environment.
60
+
61
+ **Where to configure**
62
+ - Files (priority order):
63
+ - `~/.openclaw/.env`
64
+ - `~/.moltbot/.env`
65
+ - `~/.clawdbot/.env`
66
+ - Each line is `KEY=value`
67
+
68
+ **Quick setup (shell)**
69
+ ```bash
70
+ echo 'export MEMOS_API_KEY="mpg-..."' >> ~/.zshrc
71
+ source ~/.zshrc
72
+ # or
73
+
74
+ echo 'export MEMOS_API_KEY="mpg-..."' >> ~/.bashrc
75
+ source ~/.bashrc
76
+ ```
77
+
78
+ **Quick setup (Windows PowerShell)**
79
+ ```powershell
80
+ [System.Environment]::SetEnvironmentVariable("MEMOS_API_KEY", "mpg-...", "User")
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_CONVERSATION_ID` (optional override)
95
+ - `MEMOS_RECALL_GLOBAL` (default: `true`; when true, search does **not** pass conversation_id)
96
+ - `MEMOS_MULTI_AGENT_MODE` (default: `false`; enable multi-agent data isolation)
97
+ - `MEMOS_CONVERSATION_PREFIX` / `MEMOS_CONVERSATION_SUFFIX` (optional)
98
+ - `MEMOS_CONVERSATION_SUFFIX_MODE` (`none` | `counter`, default: `none`)
99
+ - `MEMOS_CONVERSATION_RESET_ON_NEW` (default: `true`, requires hooks.internal.enabled)
100
+
101
+ ## Optional Plugin Config
102
+ In `plugins.entries.memos-cloud-openclaw-plugin.config`:
103
+ ```json
104
+ {
105
+ "baseUrl": "https://memos.memtensor.cn/api/openmem/v1",
106
+ "apiKey": "YOUR_API_KEY",
107
+ "userId": "memos_user_123",
108
+ "conversationId": "openclaw-main",
109
+ "queryPrefix": "important user context preferences decisions ",
110
+ "recallEnabled": true,
111
+ "recallGlobal": true,
112
+ "addEnabled": true,
113
+ "captureStrategy": "last_turn",
114
+ "includeAssistant": true,
115
+ "conversationIdPrefix": "",
116
+ "conversationIdSuffix": "",
117
+ "conversationSuffixMode": "none",
118
+ "resetOnNew": true,
119
+ "knowledgebaseIds": [],
120
+ "memoryLimitNumber": 6,
121
+ "preferenceLimitNumber": 6,
122
+ "includePreference": true,
123
+ "includeToolMemory": false,
124
+ "toolMemoryLimitNumber": 6,
125
+ "relativity": 0.45,
126
+ "tags": ["openclaw"],
127
+ "agentId": "",
128
+ "multiAgentMode": false,
129
+ "asyncMode": true
130
+ }
131
+ ```
132
+
133
+ ## How it Works
134
+ - **Recall** (`before_agent_start`)
135
+ - Builds a `/search/memory` request using `user_id`, `query` (= prompt + optional prefix), and optional filters.
136
+ - Default **global recall**: when `recallGlobal=true`, it does **not** pass `conversation_id`.
137
+ - Formats a MemOS prompt (Role/System/Memory/Skill/Protocols) from `/search/memory` results, then injects via `prependContext`.
138
+
139
+ - **Add** (`agent_end`)
140
+ - Builds a `/add/message` request with the **last turn** by default (user + assistant).
141
+ - Sends `messages` with `user_id`, `conversation_id`, and optional `tags/info/agent_id/app_id`.
142
+
143
+ ## Multi-Agent Support
144
+ The plugin provides native support for multi-agent architectures (via the `agent_id` parameter):
145
+ - **Enable Mode**: Set `"multiAgentMode": true` in config or `MEMOS_MULTI_AGENT_MODE=true` in env variables (default is `false`).
146
+ - **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).
147
+ - **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.
148
+ - **Static Override**: You can also force a specific agent ID by setting `"agentId": "your_agent_id"` in the plugin's `config`.
149
+
150
+ ## Notes
151
+ - `conversation_id` defaults to OpenClaw `sessionKey` (unless `conversationId` is provided). **TODO**: consider binding to OpenClaw `sessionId` directly.
152
+ - Optional **prefix/suffix** via env or config; `conversationSuffixMode=counter` increments on `/new` (requires `hooks.internal.enabled`).
153
+
154
+ ## Acknowledgements
155
+ - 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
package/README_ZH.md CHANGED
@@ -1,151 +1,161 @@
1
- # MemOS Cloud OpenClaw Plugin(Lifecycle 插件)
2
-
3
- 官方维护:MemTensor。
4
-
5
- 这是一个最小可用的 OpenClaw lifecycle 插件,功能是:
6
- - **召回记忆**:在每轮对话前从 MemOS Cloud 检索记忆并注入上下文
7
- - **添加记忆**:在每轮对话结束后把消息写回 MemOS Cloud
8
-
9
- ## 功能
10
- - **Recall**:`before_agent_start` → `/search/memory`
11
- - **Add**:`agent_end` → `/add/message`
12
- - 使用 **Token** 认证(`Authorization: Token <MEMOS_API_KEY>`)
13
-
14
- ## 安装
15
-
16
- ### 方式 A — NPM(推荐)
17
- ```bash
18
- openclaw plugins install @memtensor/memos-cloud-openclaw-plugin@latest
19
- openclaw gateway restart
20
- ```
21
-
22
- > **Windows 用户注意**:
23
- > 如果遇到 `Error: spawn EINVAL` 报错,这是 OpenClaw Windows 安装器的已知问题。请使用下方的 **方式 B**(手动安装)。
24
-
25
- 确认 `~/.openclaw/openclaw.json` 中已启用:
26
- ```json
27
- {
28
- "plugins": {
29
- "entries": {
30
- "memos-cloud-openclaw-plugin": { "enabled": true }
31
- }
32
- }
33
- }
34
- ```
35
-
36
- ### 方式 B — 手动安装(Windows 解决方案)
37
- 1. 从 [NPM](https://www.npmjs.com/package/@memtensor/memos-cloud-openclaw-plugin) 下载最新的 `.tgz` 包。
38
- 2. 解压到本地目录(例如 `C:\Users\YourName\.openclaw\extensions\memos-cloud-openclaw-plugin`)。
39
- 3. 修改配置 `~/.openclaw/openclaw.json`(或 `%USERPROFILE%\.openclaw\openclaw.json`):
40
-
41
- ```json
42
- {
43
- "plugins": {
44
- "entries": {
45
- "memos-cloud-openclaw-plugin": { "enabled": true }
46
- },
47
- "load": {
48
- "paths": [
49
- "C:\\Users\\YourName\\.openclaw\\extensions\\memos-cloud-openclaw-plugin\\package"
50
- ]
51
- }
52
- }
53
- }
54
- ```
55
- *注意:解压后的文件夹通常包含一个 `package` 子文件夹,请指向包含 `package.json` 的那层目录。*
56
-
57
- 修改配置后需要重启 gateway。
58
-
59
- ## 环境变量
60
- 插件按顺序读取 env 文件(**openclaw → moltbot → clawdbot**),每个键优先使用最先匹配到的值。
61
- 若三个文件都不存在(或该键未找到),才会回退到进程环境变量。
62
-
63
- **配置位置**
64
- - 文件(优先级顺序):
65
- - `~/.openclaw/.env`
66
- - `~/.moltbot/.env`
67
- - `~/.clawdbot/.env`
68
- - 每行格式:`KEY=value`
69
-
70
- **快速配置(Shell)**
71
- ```bash
72
- echo 'export MEMOS_API_KEY="mpg-..."' >> ~/.zshrc
73
- source ~/.zshrc
74
- # 或者
75
-
76
- echo 'export MEMOS_API_KEY="mpg-..."' >> ~/.bashrc
77
- source ~/.bashrc
78
- ```
79
-
80
- **快速配置(Windows PowerShell)**
81
- ```powershell
82
- [System.Environment]::SetEnvironmentVariable("MEMOS_API_KEY", "mpg-...", "User")
83
- ```
84
-
85
- 若未读取到 `MEMOS_API_KEY`,插件会提示配置方式并附 API Key 获取地址。
86
-
87
- **最小配置**
88
- ```env
89
- MEMOS_API_KEY=YOUR_TOKEN
90
- ```
91
-
92
- **可选配置**
93
- - `MEMOS_BASE_URL`(默认 `https://memos.memtensor.cn/api/openmem/v1`)
94
- - `MEMOS_API_KEY`(必填,Token 认证)—— 获取地址:https://memos-dashboard.openmem.net/cn/apikeys/
95
- - `MEMOS_USER_ID`(可选,默认 `openclaw-user`)
96
- - `MEMOS_CONVERSATION_ID`(可选覆盖)
97
- - `MEMOS_RECALL_GLOBAL`(默认 `true`;为 true 时检索不传 conversation_id)
98
- - `MEMOS_CONVERSATION_PREFIX` / `MEMOS_CONVERSATION_SUFFIX`(可选)
99
- - `MEMOS_CONVERSATION_SUFFIX_MODE`(`none` | `counter`,默认 `none`)
100
- - `MEMOS_CONVERSATION_RESET_ON_NEW`(默认 `true`,需 hooks.internal.enabled)
101
-
102
- ## 可选插件配置
103
- `plugins.entries.memos-cloud-openclaw-plugin.config` 中设置:
104
- ```json
105
- {
106
- "baseUrl": "https://memos.memtensor.cn/api/openmem/v1",
107
- "apiKey": "YOUR_API_KEY",
108
- "userId": "memos_user_123",
109
- "conversationId": "openclaw-main",
110
- "queryPrefix": "important user context preferences decisions ",
111
- "recallEnabled": true,
112
- "recallGlobal": true,
113
- "addEnabled": true,
114
- "captureStrategy": "last_turn",
115
- "includeAssistant": true,
116
- "conversationIdPrefix": "",
117
- "conversationIdSuffix": "",
118
- "conversationSuffixMode": "none",
119
- "resetOnNew": true,
120
- "memoryLimitNumber": 6,
121
- "preferenceLimitNumber": 6,
122
- "knowledgebaseIds": [],
123
- "includePreference": true,
124
- "includeToolMemory": false,
125
- "toolMemoryLimitNumber": 6,
126
- "tags": ["openclaw"],
127
- "asyncMode": true
128
- }
129
- ```
130
-
131
- ## 工作原理
132
- ### 1) 召回(before_agent_start)
133
- - 组装 `/search/memory` 请求
134
- - `user_id`、`query`(= prompt + 可选前缀)
135
- - 默认**全局召回**:`recallGlobal=true` 时不传 `conversation_id`
136
- - 可选 `filter` / `knowledgebase_ids`
137
- - 使用 `/search/memory` 结果按 MemOS 提示词模板(Role/System/Memory/Skill/Protocols)拼装,并通过 `prependContext` 注入
138
-
139
- ### 2) 添加(agent_end)
140
- - 默认只写**最后一轮**(user + assistant)
141
- - 构造 `/add/message` 请求:
142
- - `user_id`、`conversation_id`
143
- - `messages` 列表
144
- - 可选 `tags / info / agent_id / app_id`
145
-
146
- ## 说明
147
- - 未显式指定 `conversation_id` 时,默认使用 OpenClaw `sessionKey`。**TODO**:后续考虑直接绑定 OpenClaw `sessionId`。
148
- - 可配置前后缀;`conversationSuffixMode=counter` 时会在 `/new` 递增(需 `hooks.internal.enabled`)。
149
-
150
- ## 致谢
151
- - 感谢 @anatolykoptev(Contributor)— 领英: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
+ 官方维护:MemTensor。
4
+
5
+ 这是一个最小可用的 OpenClaw lifecycle 插件,功能是:
6
+ - **召回记忆**:在每轮对话前从 MemOS Cloud 检索记忆并注入上下文
7
+ - **添加记忆**:在每轮对话结束后把消息写回 MemOS Cloud
8
+
9
+ ## 功能
10
+ - **Recall**:`before_agent_start` → `/search/memory`
11
+ - **Add**:`agent_end` → `/add/message`
12
+ - 使用 **Token** 认证(`Authorization: Token <MEMOS_API_KEY>`)
13
+
14
+ ## 安装
15
+
16
+ ### 方式 A — NPM(推荐)
17
+ ```bash
18
+ openclaw plugins install @memtensor/memos-cloud-openclaw-plugin@latest
19
+ openclaw gateway restart
20
+ ```
21
+
22
+ > **Windows 用户注意**:
23
+ > 如果遇到 `Error: spawn EINVAL` 报错,这是 OpenClaw Windows 安装器的已知问题。请使用下方的 **方式 B**(手动安装)。
24
+
25
+ 确认 `~/.openclaw/openclaw.json` 中已启用:
26
+ ```json
27
+ {
28
+ "plugins": {
29
+ "entries": {
30
+ "memos-cloud-openclaw-plugin": { "enabled": true }
31
+ }
32
+ }
33
+ }
34
+ ```
35
+
36
+ ### 方式 B — 手动安装(Windows 解决方案)
37
+ 1. 从 [NPM](https://www.npmjs.com/package/@memtensor/memos-cloud-openclaw-plugin) 下载最新的 `.tgz` 包。
38
+ 2. 解压到本地目录(例如 `C:\Users\YourName\.openclaw\extensions\memos-cloud-openclaw-plugin`)。
39
+ 3. 修改配置 `~/.openclaw/openclaw.json`(或 `%USERPROFILE%\.openclaw\openclaw.json`):
40
+
41
+ ```json
42
+ {
43
+ "plugins": {
44
+ "entries": {
45
+ "memos-cloud-openclaw-plugin": { "enabled": true }
46
+ },
47
+ "load": {
48
+ "paths": [
49
+ "C:\\Users\\YourName\\.openclaw\\extensions\\memos-cloud-openclaw-plugin\\package"
50
+ ]
51
+ }
52
+ }
53
+ }
54
+ ```
55
+ *注意:解压后的文件夹通常包含一个 `package` 子文件夹,请指向包含 `package.json` 的那层目录。*
56
+
57
+ 修改配置后需要重启 gateway。
58
+
59
+ ## 环境变量
60
+ 插件按顺序读取 env 文件(**openclaw → moltbot → clawdbot**),每个键优先使用最先匹配到的值。
61
+ 若三个文件都不存在(或该键未找到),才会回退到进程环境变量。
62
+
63
+ **配置位置**
64
+ - 文件(优先级顺序):
65
+ - `~/.openclaw/.env`
66
+ - `~/.moltbot/.env`
67
+ - `~/.clawdbot/.env`
68
+ - 每行格式:`KEY=value`
69
+
70
+ **快速配置(Shell)**
71
+ ```bash
72
+ echo 'export MEMOS_API_KEY="mpg-..."' >> ~/.zshrc
73
+ source ~/.zshrc
74
+ # 或者
75
+
76
+ echo 'export MEMOS_API_KEY="mpg-..."' >> ~/.bashrc
77
+ source ~/.bashrc
78
+ ```
79
+
80
+ **快速配置(Windows PowerShell)**
81
+ ```powershell
82
+ [System.Environment]::SetEnvironmentVariable("MEMOS_API_KEY", "mpg-...", "User")
83
+ ```
84
+
85
+ 若未读取到 `MEMOS_API_KEY`,插件会提示配置方式并附 API Key 获取地址。
86
+
87
+ **最小配置**
88
+ ```env
89
+ MEMOS_API_KEY=YOUR_TOKEN
90
+ ```
91
+
92
+ **可选配置**
93
+ - `MEMOS_BASE_URL`(默认 `https://memos.memtensor.cn/api/openmem/v1`)
94
+ - `MEMOS_API_KEY`(必填,Token 认证)—— 获取地址:https://memos-dashboard.openmem.net/cn/apikeys/
95
+ - `MEMOS_USER_ID`(可选,默认 `openclaw-user`)
96
+ - `MEMOS_CONVERSATION_ID`(可选覆盖)
97
+ - `MEMOS_RECALL_GLOBAL`(默认 `true`;为 true 时检索不传 conversation_id)
98
+ - `MEMOS_MULTI_AGENT_MODE`(默认 `false`;是否开启多 Agent 数据隔离模式)
99
+ - `MEMOS_CONVERSATION_PREFIX` / `MEMOS_CONVERSATION_SUFFIX`(可选)
100
+ - `MEMOS_CONVERSATION_SUFFIX_MODE`(`none` | `counter`,默认 `none`)
101
+ - `MEMOS_CONVERSATION_RESET_ON_NEW`(默认 `true`,需 hooks.internal.enabled)
102
+
103
+ ## 可选插件配置
104
+ 在 `plugins.entries.memos-cloud-openclaw-plugin.config` 中设置:
105
+ ```json
106
+ {
107
+ "baseUrl": "https://memos.memtensor.cn/api/openmem/v1",
108
+ "apiKey": "YOUR_API_KEY",
109
+ "userId": "memos_user_123",
110
+ "conversationId": "openclaw-main",
111
+ "queryPrefix": "important user context preferences decisions ",
112
+ "recallEnabled": true,
113
+ "recallGlobal": true,
114
+ "addEnabled": true,
115
+ "captureStrategy": "last_turn",
116
+ "includeAssistant": true,
117
+ "conversationIdPrefix": "",
118
+ "conversationIdSuffix": "",
119
+ "conversationSuffixMode": "none",
120
+ "resetOnNew": true,
121
+ "memoryLimitNumber": 6,
122
+ "preferenceLimitNumber": 6,
123
+ "knowledgebaseIds": [],
124
+ "includePreference": true,
125
+ "includeToolMemory": false,
126
+ "toolMemoryLimitNumber": 6,
127
+ "tags": ["openclaw"],
128
+ "agentId": "",
129
+ "multiAgentMode": false,
130
+ "asyncMode": true
131
+ }
132
+ ```
133
+
134
+ ## 工作原理
135
+ ### 1) 召回(before_agent_start)
136
+ - 组装 `/search/memory` 请求
137
+ - `user_id`、`query`(= prompt + 可选前缀)
138
+ - 默认**全局召回**:`recallGlobal=true` 时不传 `conversation_id`
139
+ - 可选 `filter` / `knowledgebase_ids`
140
+ - 使用 `/search/memory` 结果按 MemOS 提示词模板(Role/System/Memory/Skill/Protocols)拼装,并通过 `prependContext` 注入
141
+
142
+ ### 2) 添加(agent_end)
143
+ - 默认只写**最后一轮**(user + assistant)
144
+ - 构造 `/add/message` 请求:
145
+ - `user_id`、`conversation_id`
146
+ - `messages` 列表
147
+ - 可选 `tags / info / agent_id / app_id`
148
+
149
+ ## 多Agent支持(Multi-Agent)
150
+ 插件内置对多Agent模式的支持(`agent_id` 参数):
151
+ - **开启模式**:需要在配置中设置 `"multiAgentMode": true` 或在环境变量中设置 `MEMOS_MULTI_AGENT_MODE=true`(默认为 `false`)。
152
+ - **动态获取**:开启后,执行生命周期钩子时会自动读取上下文中的 `ctx.agentId`。(注:OpenClaw 的默认 Agent `"main"` 会被自动忽略,以保证老用户的单 Agent 数据兼容性)。
153
+ - **数据隔离**:在调用 `/search/memory`(检索记忆)和 `/add/message`(添加记录)时会自动附带该 `agent_id`,从而保证即使是同一用户下的不同 Agent 之间,记忆和反馈数据也是完全隔离的。
154
+ - **静态配置**:如果需要,也可在上述插件的 `config` 中显式指定 `"agentId": "your_agent_id"` 作为固定值。
155
+
156
+ ## 说明
157
+ - 未显式指定 `conversation_id` 时,默认使用 OpenClaw `sessionKey`。**TODO**:后续考虑直接绑定 OpenClaw `sessionId`。
158
+ - 可配置前后缀;`conversationSuffixMode=counter` 时会在 `/new` 递增(需 `hooks.internal.enabled`)。
159
+
160
+ ## 致谢
161
+ - 感谢 @anatolykoptev(Contributor)— 领英:https://www.linkedin.com/in/koptev?utm_source=share&utm_campaign=share_via&utm_content=profile&utm_medium=ios_app