@memtensor/memos-cloud-openclaw-plugin 0.1.8 → 0.1.10-beta.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/LICENSE +201 -201
- package/README.md +175 -155
- package/README_ZH.md +180 -161
- package/clawdbot.plugin.json +6 -1
- package/index.js +478 -285
- package/lib/check-update.js +270 -0
- package/lib/memos-cloud-api.js +573 -449
- package/moltbot.plugin.json +6 -1
- package/openclaw.plugin.json +6 -1
- package/package.json +46 -46
- package/scripts/sync-version.js +45 -45
- package/test/query-strip.test.mjs +152 -0
package/README_ZH.md
CHANGED
|
@@ -1,161 +1,180 @@
|
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
"
|
|
117
|
-
"
|
|
118
|
-
"
|
|
119
|
-
"
|
|
120
|
-
"
|
|
121
|
-
"
|
|
122
|
-
"
|
|
123
|
-
"
|
|
124
|
-
"
|
|
125
|
-
"
|
|
126
|
-
"
|
|
127
|
-
"
|
|
128
|
-
"
|
|
129
|
-
"
|
|
130
|
-
"
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
-
|
|
158
|
-
-
|
|
159
|
-
|
|
160
|
-
|
|
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_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
|
+
- `MEMOS_RECALL_FILTER_ENABLED`(默认 `false`;开启后先用你指定的模型过滤召回记忆再注入)
|
|
103
|
+
- `MEMOS_RECALL_FILTER_BASE_URL`(OpenAI 兼容接口,例如 `http://127.0.0.1:11434/v1`)
|
|
104
|
+
- `MEMOS_RECALL_FILTER_API_KEY`(可选,若你的接口需要鉴权)
|
|
105
|
+
- `MEMOS_RECALL_FILTER_MODEL`(用于筛选记忆的模型名)
|
|
106
|
+
- `MEMOS_RECALL_FILTER_TIMEOUT_MS`(默认 `6000`)
|
|
107
|
+
- `MEMOS_RECALL_FILTER_RETRIES`(默认 `0`)
|
|
108
|
+
- `MEMOS_RECALL_FILTER_CANDIDATE_LIMIT`(默认每类 `30` 条)
|
|
109
|
+
- `MEMOS_RECALL_FILTER_MAX_ITEM_CHARS`(默认 `500`)
|
|
110
|
+
- `MEMOS_RECALL_FILTER_FAIL_OPEN`(默认 `true`;筛选失败时回退为“不过滤”)
|
|
111
|
+
|
|
112
|
+
## 可选插件配置
|
|
113
|
+
在 `plugins.entries.memos-cloud-openclaw-plugin.config` 中设置:
|
|
114
|
+
```json
|
|
115
|
+
{
|
|
116
|
+
"baseUrl": "https://memos.memtensor.cn/api/openmem/v1",
|
|
117
|
+
"apiKey": "YOUR_API_KEY",
|
|
118
|
+
"userId": "memos_user_123",
|
|
119
|
+
"conversationId": "openclaw-main",
|
|
120
|
+
"queryPrefix": "important user context preferences decisions ",
|
|
121
|
+
"recallEnabled": true,
|
|
122
|
+
"recallGlobal": true,
|
|
123
|
+
"addEnabled": true,
|
|
124
|
+
"captureStrategy": "last_turn",
|
|
125
|
+
"includeAssistant": true,
|
|
126
|
+
"conversationIdPrefix": "",
|
|
127
|
+
"conversationIdSuffix": "",
|
|
128
|
+
"conversationSuffixMode": "none",
|
|
129
|
+
"resetOnNew": true,
|
|
130
|
+
"memoryLimitNumber": 6,
|
|
131
|
+
"preferenceLimitNumber": 6,
|
|
132
|
+
"knowledgebaseIds": [],
|
|
133
|
+
"includePreference": true,
|
|
134
|
+
"includeToolMemory": false,
|
|
135
|
+
"toolMemoryLimitNumber": 6,
|
|
136
|
+
"tags": ["openclaw"],
|
|
137
|
+
"agentId": "",
|
|
138
|
+
"multiAgentMode": false,
|
|
139
|
+
"asyncMode": true,
|
|
140
|
+
"recallFilterEnabled": false,
|
|
141
|
+
"recallFilterBaseUrl": "http://127.0.0.1:11434/v1",
|
|
142
|
+
"recallFilterApiKey": "",
|
|
143
|
+
"recallFilterModel": "qwen2.5:7b",
|
|
144
|
+
"recallFilterTimeoutMs": 6000,
|
|
145
|
+
"recallFilterRetries": 0,
|
|
146
|
+
"recallFilterCandidateLimit": 30,
|
|
147
|
+
"recallFilterMaxItemChars": 500,
|
|
148
|
+
"recallFilterFailOpen": true
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## 工作原理
|
|
153
|
+
### 1) 召回(before_agent_start)
|
|
154
|
+
- 组装 `/search/memory` 请求
|
|
155
|
+
- `user_id`、`query`(= prompt + 可选前缀)
|
|
156
|
+
- 默认**全局召回**:`recallGlobal=true` 时不传 `conversation_id`
|
|
157
|
+
- 可选 `filter` / `knowledgebase_ids`
|
|
158
|
+
- (可选)若开启 `recallFilterEnabled`,会先把 `memory/preference/tool_memory` 候选发给你配置的模型做二次筛选,只保留 `keep` 的条目
|
|
159
|
+
- 将稳定的 MemOS 召回协议通过 `appendSystemContext` 注入,而检索到的 `<memories>` 数据块继续通过 `prependContext` 注入
|
|
160
|
+
|
|
161
|
+
### 2) 添加(agent_end)
|
|
162
|
+
- 默认只写**最后一轮**(user + assistant)
|
|
163
|
+
- 构造 `/add/message` 请求:
|
|
164
|
+
- `user_id`、`conversation_id`
|
|
165
|
+
- `messages` 列表
|
|
166
|
+
- 可选 `tags / info / agent_id / app_id`
|
|
167
|
+
|
|
168
|
+
## 多Agent支持(Multi-Agent)
|
|
169
|
+
插件内置对多Agent模式的支持(`agent_id` 参数):
|
|
170
|
+
- **开启模式**:需要在配置中设置 `"multiAgentMode": true` 或在环境变量中设置 `MEMOS_MULTI_AGENT_MODE=true`(默认为 `false`)。
|
|
171
|
+
- **动态获取**:开启后,执行生命周期钩子时会自动读取上下文中的 `ctx.agentId`。(注:OpenClaw 的默认 Agent `"main"` 会被自动忽略,以保证老用户的单 Agent 数据兼容性)。
|
|
172
|
+
- **数据隔离**:在调用 `/search/memory`(检索记忆)和 `/add/message`(添加记录)时会自动附带该 `agent_id`,从而保证即使是同一用户下的不同 Agent 之间,记忆和反馈数据也是完全隔离的。
|
|
173
|
+
- **静态配置**:如果需要,也可在上述插件的 `config` 中显式指定 `"agentId": "your_agent_id"` 作为固定值。
|
|
174
|
+
|
|
175
|
+
## 说明
|
|
176
|
+
- 未显式指定 `conversation_id` 时,默认使用 OpenClaw `sessionKey`。**TODO**:后续考虑直接绑定 OpenClaw `sessionId`。
|
|
177
|
+
- 可配置前后缀;`conversationSuffixMode=counter` 时会在 `/new` 递增(需 `hooks.internal.enabled`)。
|
|
178
|
+
|
|
179
|
+
## 致谢
|
|
180
|
+
- 感谢 @anatolykoptev(Contributor)— 领英:https://www.linkedin.com/in/koptev?utm_source=share&utm_campaign=share_via&utm_content=profile&utm_medium=ios_app
|
package/clawdbot.plugin.json
CHANGED
|
@@ -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.
|
|
5
|
+
"version": "0.1.10-beta.0",
|
|
6
6
|
"kind": "lifecycle",
|
|
7
7
|
"main": "./index.js",
|
|
8
8
|
"configSchema": {
|
|
@@ -78,6 +78,11 @@
|
|
|
78
78
|
"description": "Max chars per message when adding",
|
|
79
79
|
"default": 20000
|
|
80
80
|
},
|
|
81
|
+
"maxItemChars": {
|
|
82
|
+
"type": "integer",
|
|
83
|
+
"description": "Max chars per memory item when injecting prompt",
|
|
84
|
+
"default": 8000
|
|
85
|
+
},
|
|
81
86
|
"includeAssistant": {
|
|
82
87
|
"type": "boolean",
|
|
83
88
|
"default": true
|