@openviking/openclaw-plugin 2026.5.8
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/INSTALL-AGENT.md +355 -0
- package/INSTALL-ZH.md +345 -0
- package/INSTALL.md +362 -0
- package/README.md +315 -0
- package/auto-recall.ts +257 -0
- package/client.ts +828 -0
- package/commands/setup.ts +1002 -0
- package/config.ts +476 -0
- package/context-engine.ts +1700 -0
- package/dist/auto-recall.js +167 -0
- package/dist/client.js +502 -0
- package/dist/commands/setup.js +815 -0
- package/dist/config.js +352 -0
- package/dist/context-engine.js +1324 -0
- package/dist/index.js +1194 -0
- package/dist/memory-ranking.js +221 -0
- package/dist/process-manager.js +127 -0
- package/dist/runtime-utils.js +7 -0
- package/dist/session-transcript-repair.js +427 -0
- package/dist/text-utils.js +453 -0
- package/dist/tool-call-id.js +254 -0
- package/index.ts +1597 -0
- package/install-manifest.json +47 -0
- package/memory-ranking.ts +267 -0
- package/openclaw.plugin.json +331 -0
- package/package.json +75 -0
- package/process-manager.ts +169 -0
- package/runtime-utils.ts +8 -0
- package/session-transcript-repair.ts +530 -0
- package/skills/install-openviking-memory/SKILL.md +665 -0
- package/text-utils.ts +524 -0
- package/tool-call-id.ts +331 -0
package/INSTALL.md
ADDED
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
# Install OpenViking for OpenClaw
|
|
2
|
+
|
|
3
|
+
OpenViking provides long-term memory, knowledge base search, semantic retrieval, and RAG-style context for OpenClaw through the `@openviking/openclaw-plugin` plugin.
|
|
4
|
+
|
|
5
|
+
This guide describes the current plugin install flow. It is written for both people and automation agents.
|
|
6
|
+
|
|
7
|
+
## Do Not Install The Skill By Mistake
|
|
8
|
+
|
|
9
|
+
`@openviking/openclaw-plugin` is an OpenClaw plugin.
|
|
10
|
+
|
|
11
|
+
Do not use this command for plugin installation:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
clawhub install openviking
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
That command installs an AgentSkill named `openviking`, not the OpenClaw plugin.
|
|
18
|
+
|
|
19
|
+
Use this plugin command instead:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
openclaw plugins install @openviking/openclaw-plugin
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Requirements
|
|
26
|
+
|
|
27
|
+
| Component | Required |
|
|
28
|
+
| --- | --- |
|
|
29
|
+
| Node.js | >= 22 |
|
|
30
|
+
| OpenClaw | >= 2026.4.8 |
|
|
31
|
+
|
|
32
|
+
The plugin connects to an existing OpenViking server. It does not start the OpenViking server for you. Start OpenViking first, keep it running, then point the plugin `baseUrl` at that HTTP service. The default local URL is `http://127.0.0.1:1933`.
|
|
33
|
+
|
|
34
|
+
OpenClaw plugin package boundaries:
|
|
35
|
+
|
|
36
|
+
- `2026.4.8` is the minimum supported OpenClaw version for the current plugin.
|
|
37
|
+
- `2026.5.3` starts validating package installs so TypeScript plugin entries need compiled JavaScript output.
|
|
38
|
+
- `2026.5.4` and later stop falling back to `.ts` source for installed/global plugin runtime loading when compiled JavaScript is missing.
|
|
39
|
+
- The recommended `openclaw plugins install @openviking/openclaw-plugin` path installs a published package that already includes `dist/*.js`.
|
|
40
|
+
- `ov-install` is the backup/source install path. Use it when ClawHub or the OpenClaw plugin manager path is unavailable/rate-limited, or when explicitly testing a source ref. For OpenClaw `>= 2026.5.3`, it builds the plugin during installation.
|
|
41
|
+
|
|
42
|
+
Quick check:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
node -v
|
|
46
|
+
openclaw --version
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Start OpenViking Server
|
|
50
|
+
|
|
51
|
+
For a local OpenViking server on the same machine as OpenClaw:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install openviking --upgrade --force-reinstall
|
|
55
|
+
openviking-server init
|
|
56
|
+
openviking-server doctor
|
|
57
|
+
openviking-server
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`openviking-server init` writes the server configuration, `openviking-server doctor` validates local model/provider auth, and `openviking-server` starts the HTTP API. Keep this process running while OpenClaw uses the plugin.
|
|
61
|
+
|
|
62
|
+
To run the server in the background:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
mkdir -p ~/.openviking/data/log
|
|
66
|
+
nohup openviking-server > ~/.openviking/data/log/openviking.log 2>&1 &
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
If OpenViking runs on another machine, start it on a reachable host/port, for example:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
openviking-server --host 0.0.0.0 --port 1933
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Then configure the OpenClaw plugin `baseUrl` to that address, such as `http://your-server:1933`.
|
|
76
|
+
|
|
77
|
+
Verify the server before installing or restarting the plugin:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
curl http://127.0.0.1:1933/health
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Recommended Install Path
|
|
84
|
+
|
|
85
|
+
Use this path for normal users, production installs, and agent-assisted installs.
|
|
86
|
+
|
|
87
|
+
### 1. Install The Plugin
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
openclaw plugins install @openviking/openclaw-plugin
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
If your OpenClaw installation requires an explicit registry prefix, use:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
openclaw plugins install clawhub:@openviking/openclaw-plugin
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### 2. Configure The Plugin
|
|
100
|
+
|
|
101
|
+
For interactive human setup:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
openclaw openviking setup
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
For non-interactive agent setup:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
openclaw openviking setup --base-url <OPENVIKING_URL> --api-key <API_KEY> --json
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Example:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
openclaw openviking setup --base-url http://127.0.0.1:1933 --api-key sk-xxx --json
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
The setup command writes `plugins.entries.openviking.config` and activates `plugins.slots.contextEngine=openviking`.
|
|
120
|
+
|
|
121
|
+
If the OpenViking server is temporarily unreachable but you still want to save the config:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
openclaw openviking setup --base-url <OPENVIKING_URL> --api-key <API_KEY> --allow-offline --json
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
If your API key is a root key, setup may require tenant context:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
openclaw openviking setup \
|
|
131
|
+
--base-url <OPENVIKING_URL> \
|
|
132
|
+
--api-key <ROOT_API_KEY> \
|
|
133
|
+
--account-id <ACCOUNT_ID> \
|
|
134
|
+
--user-id <USER_ID> \
|
|
135
|
+
--json
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
If another context engine already owns the slot, setup will not replace it by default. To intentionally replace the current owner:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
openclaw openviking setup --base-url <OPENVIKING_URL> --api-key <API_KEY> --force-slot --json
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
If you need a custom agent routing prefix (optional; most users leave this empty):
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
openclaw openviking setup --base-url <OPENVIKING_URL> --api-key <API_KEY> --agent-prefix <PREFIX> --json
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### 3. Restart OpenClaw Gateway
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
openclaw gateway restart
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
If your OpenClaw version uses a different restart command, use the equivalent gateway restart for your environment.
|
|
157
|
+
|
|
158
|
+
### 4. Verify
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
openclaw openviking status --json
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Expected result:
|
|
165
|
+
|
|
166
|
+
| JSON field | Expected value |
|
|
167
|
+
| --- | --- |
|
|
168
|
+
| `configured` | `true` |
|
|
169
|
+
| `slotActive` | `true` |
|
|
170
|
+
| `health.ok` | `true` when the server is reachable |
|
|
171
|
+
|
|
172
|
+
You can also inspect the raw OpenClaw config:
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
openclaw config get plugins.entries.openviking.config
|
|
176
|
+
openclaw config get plugins.slots.contextEngine
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
`plugins.slots.contextEngine` should be `openviking`.
|
|
180
|
+
|
|
181
|
+
## Agent Result Handling
|
|
182
|
+
|
|
183
|
+
Automation should prefer `--json` and branch on these fields:
|
|
184
|
+
|
|
185
|
+
| Result | Meaning | Recommended action |
|
|
186
|
+
| --- | --- | --- |
|
|
187
|
+
| `success: true` | Config saved and setup completed | Restart gateway, then run status |
|
|
188
|
+
| `success: false`, `action: "slot_blocked"` | Config may be saved, but another plugin owns `contextEngine` | Ask before rerunning with `--force-slot` |
|
|
189
|
+
| `success: false`, `action: "error"` | Validation failed | Show `error`; do not claim install succeeded |
|
|
190
|
+
| `health.ok: false` | Server unreachable | Check URL/server, or rerun with `--allow-offline` only if the user accepts |
|
|
191
|
+
| `keyProbe.keyType: "root_key"` | Root key needs tenant context | Rerun with `--account-id` and `--user-id` |
|
|
192
|
+
|
|
193
|
+
## Configuration Reference
|
|
194
|
+
|
|
195
|
+
The plugin config lives at:
|
|
196
|
+
|
|
197
|
+
```text
|
|
198
|
+
plugins.entries.openviking.config
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Core fields:
|
|
202
|
+
|
|
203
|
+
| Field | Default | Description |
|
|
204
|
+
| --- | --- | --- |
|
|
205
|
+
| `mode` | `remote` | Legacy compatibility field. Only remote mode is supported. |
|
|
206
|
+
| `baseUrl` | `http://127.0.0.1:1933` | OpenViking HTTP endpoint |
|
|
207
|
+
| `apiKey` | empty | OpenViking API key |
|
|
208
|
+
| `agent_prefix` | empty | Optional prefix for OpenClaw agent IDs. If no agent ID is available, the plugin uses `main`. Interactive setup accepts only letters, digits, `_`, and `-`. |
|
|
209
|
+
| `accountId` | empty | Required when using a root API key |
|
|
210
|
+
| `userId` | empty | Required when using a root API key |
|
|
211
|
+
|
|
212
|
+
Use setup for normal changes when possible:
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
openclaw openviking setup --reconfigure
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Manual config inspection:
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
openclaw config get plugins.entries.openviking.config
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Upgrade
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
openclaw plugins update openviking
|
|
228
|
+
openclaw gateway restart
|
|
229
|
+
openclaw openviking status --json
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Confirm that `configured` and `slotActive` are both `true`.
|
|
233
|
+
|
|
234
|
+
## Uninstall
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
openclaw plugins uninstall openviking
|
|
238
|
+
openclaw config set plugins.slots.contextEngine legacy
|
|
239
|
+
openclaw gateway restart
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Current OpenClaw native uninstall does not always reset `plugins.slots.contextEngine`. The explicit `config set` step avoids leaving the slot pointed at an uninstalled plugin.
|
|
243
|
+
|
|
244
|
+
## Optional Pipeline Health Check
|
|
245
|
+
|
|
246
|
+
After status passes, you can run the bundled end-to-end health check from a repository checkout:
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
python examples/openclaw-plugin/health_check_tools/ov-healthcheck.py
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
This checks the Gateway to OpenViking path by injecting a real conversation and verifying capture, commit, archive, and memory extraction. See [health_check_tools/HEALTHCHECK.md](./health_check_tools/HEALTHCHECK.md).
|
|
253
|
+
|
|
254
|
+
## Backup Path: ov-install
|
|
255
|
+
|
|
256
|
+
`ov-install` is the backup path, not the primary install path. Use it when `openclaw plugins install @openviking/openclaw-plugin` cannot reach ClawHub, is rate-limited, or when you explicitly need to install/test plugin files from a Git branch or source ref.
|
|
257
|
+
|
|
258
|
+
Try the OpenClaw plugin manager first. If that path is unavailable, run:
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
npm install -g openclaw-openviking-setup-helper
|
|
262
|
+
ov-install
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
Useful backup/source flags:
|
|
266
|
+
|
|
267
|
+
| Flag | Meaning |
|
|
268
|
+
| --- | --- |
|
|
269
|
+
| `--workdir PATH` | Target OpenClaw state directory |
|
|
270
|
+
| `--version REF` | Git ref, tag, branch, or release version to install |
|
|
271
|
+
| `--current-version` | Print the version tracked by the helper |
|
|
272
|
+
| `--base-url URL` | OpenViking server URL (enables non-interactive mode) |
|
|
273
|
+
| `--api-key KEY` | OpenViking API key |
|
|
274
|
+
| `--agent-prefix PREFIX` | Agent routing prefix |
|
|
275
|
+
| `--update` | Update an existing helper-managed install |
|
|
276
|
+
|
|
277
|
+
For user-facing installs, use `openclaw plugins install @openviking/openclaw-plugin` first. Choose `ov-install` only as the backup path.
|
|
278
|
+
|
|
279
|
+
## Migrate From ov-install To openclaw plugin install
|
|
280
|
+
|
|
281
|
+
If you previously installed OpenViking with `ov-install`, follow these steps before switching to the recommended `openclaw plugins install` path.
|
|
282
|
+
|
|
283
|
+
### Same Plugin ID (openviking, version >= 0.3.x)
|
|
284
|
+
|
|
285
|
+
The ov-install context-engine deployment writes files to `~/.openclaw/extensions/openviking/`. After installing via npm, OpenClaw may still load from the old directory. Clean it up:
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
# Remove ov-install deployed files
|
|
289
|
+
rm -rf ~/.openclaw/extensions/openviking/
|
|
290
|
+
|
|
291
|
+
# Install via the OpenClaw plugin manager
|
|
292
|
+
openclaw plugins install @openviking/openclaw-plugin
|
|
293
|
+
|
|
294
|
+
# Reconfigure (your existing config in openclaw.json is preserved)
|
|
295
|
+
openclaw openviking setup --reconfigure
|
|
296
|
+
openclaw gateway restart
|
|
297
|
+
openclaw openviking status --json
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
Your existing config fields (`baseUrl`, `apiKey`, `agentId`, etc.) are preserved. The new plugin version reads old field names at runtime — no manual config edits needed.
|
|
301
|
+
|
|
302
|
+
The plugin configuration lives under `plugins.entries.openviking.config`.
|
|
303
|
+
|
|
304
|
+
Get the current full plugin configuration:
|
|
305
|
+
|
|
306
|
+
```bash
|
|
307
|
+
openclaw config get plugins.entries.openviking.config
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### Configuration Parameters
|
|
311
|
+
|
|
312
|
+
The plugin connects to an existing remote OpenViking server.
|
|
313
|
+
|
|
314
|
+
| Parameter | Default | Meaning |
|
|
315
|
+
| --- | --- | --- |
|
|
316
|
+
| `baseUrl` | `http://127.0.0.1:1933` | Remote OpenViking HTTP endpoint |
|
|
317
|
+
| `apiKey` | empty | Optional OpenViking API key |
|
|
318
|
+
| `agent_prefix` | empty | Optional prefix for OpenClaw agent IDs. If no agent ID is available, the plugin uses `main`. Interactive setup accepts only letters, digits, `_`, and `-` |
|
|
319
|
+
|
|
320
|
+
Common settings:
|
|
321
|
+
|
|
322
|
+
```bash
|
|
323
|
+
openclaw config set plugins.entries.openviking.config.baseUrl http://your-server:1933
|
|
324
|
+
openclaw config set plugins.entries.openviking.config.apiKey your-api-key
|
|
325
|
+
openclaw config set plugins.entries.openviking.config.agent_prefix your-prefix
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
## Start
|
|
329
|
+
|
|
330
|
+
After installation (if you skipped reconfigure above):
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
openclaw gateway restart
|
|
334
|
+
openclaw openviking status --json
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### Old Plugin ID (memory-openviking, version < 0.3.x)
|
|
338
|
+
|
|
339
|
+
The old memory plugin used a different plugin ID and slot:
|
|
340
|
+
|
|
341
|
+
```bash
|
|
342
|
+
# Uninstall old plugin
|
|
343
|
+
openclaw plugins uninstall memory-openviking 2>/dev/null || true
|
|
344
|
+
|
|
345
|
+
# Clean up old slot and files
|
|
346
|
+
openclaw config set plugins.slots.memory none
|
|
347
|
+
rm -rf ~/.openclaw/extensions/memory-openviking/
|
|
348
|
+
|
|
349
|
+
# Install new plugin
|
|
350
|
+
openclaw plugins install @openviking/openclaw-plugin
|
|
351
|
+
openclaw openviking setup --base-url <OPENVIKING_URL> --api-key <API_KEY> --json
|
|
352
|
+
openclaw gateway restart
|
|
353
|
+
openclaw openviking status --json
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
Or use the cleanup script:
|
|
357
|
+
|
|
358
|
+
```bash
|
|
359
|
+
bash examples/openclaw-plugin/upgrade_scripts/cleanup-memory-openviking.sh
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
See also: [INSTALL-ZH.md](./INSTALL-ZH.md) and [INSTALL-AGENT.md](./INSTALL-AGENT.md).
|
package/README.md
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
# @openviking/openclaw-plugin — OpenViking OpenClaw Plugin
|
|
2
|
+
|
|
3
|
+
OpenClaw context-engine plugin for OpenViking remote memory, context database, RAG and semantic retrieval.
|
|
4
|
+
|
|
5
|
+
## Important: Plugin vs Skill
|
|
6
|
+
|
|
7
|
+
This page is for the **OpenClaw plugin package**:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
@openviking/openclaw-plugin
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
**Do NOT** install the plugin with `clawhub install openviking` — that installs the `openviking` AgentSkill (under `skills/openviking`), which is a different thing.
|
|
14
|
+
|
|
15
|
+
For **agent-assisted plugin setup**, ask the agent to follow [INSTALL-AGENT.md](./INSTALL-AGENT.md). The primary install path is still `openclaw plugins install @openviking/openclaw-plugin`.
|
|
16
|
+
|
|
17
|
+
## Install (Natural Language)
|
|
18
|
+
|
|
19
|
+
Ask your agent:
|
|
20
|
+
|
|
21
|
+
> Install the OpenClaw plugin @openviking/openclaw-plugin for OpenViking remote memory. My server is at `http://my-server:1933` and my API key is `sk-xxx`.
|
|
22
|
+
|
|
23
|
+
Or in Chinese:
|
|
24
|
+
|
|
25
|
+
> 帮我安装 OpenViking 远程记忆插件 @openviking/openclaw-plugin。我的服务器地址是 `http://my-server:1933`,API key 是 `sk-xxx`。
|
|
26
|
+
|
|
27
|
+
The agent will automatically run install → setup → restart → verify. No manual steps needed.
|
|
28
|
+
|
|
29
|
+
## Install (Command Line)
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
openclaw plugins install @openviking/openclaw-plugin
|
|
33
|
+
openclaw openviking setup --base-url http://my-server:1933 --api-key sk-xxx --json
|
|
34
|
+
openclaw gateway restart
|
|
35
|
+
openclaw openviking status --json
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The `setup` command automatically activates the context-engine slot and validates the server connection.
|
|
39
|
+
|
|
40
|
+
## Search Keywords
|
|
41
|
+
|
|
42
|
+
@openviking/openclaw-plugin, openclaw openviking plugin, openviking remote memory plugin, OpenViking Context Database plugin, install-openviking-memory.
|
|
43
|
+
|
|
44
|
+
## Documentation
|
|
45
|
+
|
|
46
|
+
- Install and upgrade: [INSTALL.md](./INSTALL.md)
|
|
47
|
+
- Chinese design and install guide: [INSTALL-ZH.md](./INSTALL-ZH.md)
|
|
48
|
+
- Agent-oriented operator guide: [INSTALL-AGENT.md](./INSTALL-AGENT.md)
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Technical Overview
|
|
53
|
+
|
|
54
|
+
Use [OpenViking](https://github.com/volcengine/OpenViking) as the long-term memory backend for [OpenClaw](https://github.com/openclaw/openclaw). In OpenClaw, this plugin is registered as the `openviking` context engine.
|
|
55
|
+
|
|
56
|
+
The remainder of this document is an implementation-focused design note for integrators and engineers.
|
|
57
|
+
|
|
58
|
+
## Design Positioning
|
|
59
|
+
|
|
60
|
+
- OpenClaw still owns the agent runtime, prompt orchestration, and tool execution.
|
|
61
|
+
- OpenViking owns long-term memory retrieval, session archiving, archive summaries, and memory extraction.
|
|
62
|
+
- `examples/openclaw-plugin` is not a narrow "memory lookup" plugin. It is an integration layer that spans the OpenClaw lifecycle.
|
|
63
|
+
|
|
64
|
+
In the current implementation, the plugin plays four roles at once:
|
|
65
|
+
|
|
66
|
+
- `context-engine`: implements `assemble`, `afterTurn`, and `compact`
|
|
67
|
+
- hook layer: handles `session_start`, `session_end`, and `before_reset`
|
|
68
|
+
- tool provider: registers memory/archive tools plus OpenViking resource and skill import tools
|
|
69
|
+
- runtime manager: connects to and monitors a remote OpenViking service
|
|
70
|
+
|
|
71
|
+
## Overall Architecture
|
|
72
|
+
|
|
73
|
+

|
|
74
|
+
|
|
75
|
+
The diagram above reflects the current implementation boundary:
|
|
76
|
+
|
|
77
|
+
- OpenClaw remains the primary runtime on the left. The plugin does not take over agent execution.
|
|
78
|
+
- The middle layer combines hooks, the context engine, tools, and runtime management in one plugin registration.
|
|
79
|
+
- All HTTP traffic goes through `OpenVikingClient`, which centralizes `X-OpenViking-*` headers and routing logs.
|
|
80
|
+
- The OpenViking service owns sessions, memories, archives, and Phase 2 extraction, with storage under `viking://user/*`, `viking://agent/*`, and `viking://session/*`.
|
|
81
|
+
|
|
82
|
+
That split lets OpenClaw stay focused on reasoning and orchestration while OpenViking becomes the source of truth for long-lived context.
|
|
83
|
+
|
|
84
|
+
## Identity and Routing
|
|
85
|
+
|
|
86
|
+
The plugin does not send one fixed agent ID to OpenViking. It tries to keep OpenClaw session identity and OpenViking routing aligned.
|
|
87
|
+
|
|
88
|
+
The main rules are:
|
|
89
|
+
|
|
90
|
+
- reuse `sessionId` directly when it is already a UUID
|
|
91
|
+
- prefer `sessionKey` when deriving a stable `ovSessionId`
|
|
92
|
+
- normalize unsafe path characters, or fall back to a stable SHA-256 when needed
|
|
93
|
+
- resolve `X-OpenViking-Agent` per session, not per process
|
|
94
|
+
- when `plugins.entries.openviking.config.agent_prefix` is non-empty, prefix the session agent as `<agent_prefix>_<sessionAgent>`
|
|
95
|
+
- when OpenClaw does not provide a session agent, use its default agent `main`
|
|
96
|
+
- send `X-OpenViking-Agent` on OpenViking requests, including startup health checks
|
|
97
|
+
- only add `X-OpenViking-Account` / `X-OpenViking-User` when `accountId` / `userId` are explicitly configured
|
|
98
|
+
|
|
99
|
+
This matters because the plugin is built to support multi-agent and multi-session OpenClaw usage without mixing memories across sessions.
|
|
100
|
+
|
|
101
|
+
The recommended remote-mode configuration only needs:
|
|
102
|
+
|
|
103
|
+
- `baseUrl`
|
|
104
|
+
- `apiKey`
|
|
105
|
+
- `agent_prefix`
|
|
106
|
+
|
|
107
|
+
In this setup:
|
|
108
|
+
|
|
109
|
+
- `apiKey` should usually be a user key
|
|
110
|
+
- `accountId` / `userId` are advanced options only when the deployment needs explicit identity headers, such as root-key or trusted-server flows
|
|
111
|
+
- `isolateUserScopeByAgent` / `isolateAgentScopeByUser` must match the server-side account namespace policy when using the PR #1356 canonical namespace model
|
|
112
|
+
- `agentScopeMode` is a deprecated compatibility alias for older hash-based routing and should only be used against older servers
|
|
113
|
+
|
|
114
|
+
### Canonical namespace policy
|
|
115
|
+
|
|
116
|
+
For OpenViking servers that include PR #1356, the plugin no longer treats agent or user scope as a locally computed hash. Instead it expands shorthand aliases into canonical URIs using the configured namespace policy:
|
|
117
|
+
|
|
118
|
+
- `viking://user/memories`
|
|
119
|
+
- `viking://user/<user_id>/memories` when `isolateUserScopeByAgent=false`
|
|
120
|
+
- `viking://user/<user_id>/agent/<agent_id>/memories` when `isolateUserScopeByAgent=true`
|
|
121
|
+
- `viking://agent/memories`
|
|
122
|
+
- `viking://agent/<agent_id>/memories` when `isolateAgentScopeByUser=false`
|
|
123
|
+
- `viking://agent/<agent_id>/user/<user_id>/memories` when `isolateAgentScopeByUser=true`
|
|
124
|
+
|
|
125
|
+
The plugin cannot auto-discover this policy today because `/api/v1/system/status` does not expose it. Configure the two booleans explicitly so they stay aligned with the server-side account policy.
|
|
126
|
+
|
|
127
|
+
## assemble Recall Flow
|
|
128
|
+
|
|
129
|
+

|
|
130
|
+
|
|
131
|
+
Auto-recall now runs through `assemble()`. OpenClaw calls the same context engine method in two shapes, and the plugin assigns different responsibilities to each shape:
|
|
132
|
+
|
|
133
|
+
1. Preflight assemble: params include `prompt`; `messages` is still old history. The plugin reads archive/session context back from OpenViking and rebuilds history.
|
|
134
|
+
2. transformContext assemble: params do not include `prompt`; the latest `messages` entry is already the current user turn. The plugin only runs long-term recall and prepends the memory block to that user message content.
|
|
135
|
+
|
|
136
|
+
During recall, the plugin:
|
|
137
|
+
|
|
138
|
+
1. Extracts query text from the latest user message.
|
|
139
|
+
2. Resolves the agent routing for the current `sessionId/sessionKey`.
|
|
140
|
+
3. Runs a quick availability precheck so model requests do not stall when OpenViking is unavailable.
|
|
141
|
+
4. Queries both `viking://user/memories` and `viking://agent/memories` in parallel.
|
|
142
|
+
5. Deduplicates, threshold-filters, reranks, and trims the results under a token budget.
|
|
143
|
+
6. Prepends the selected memories as a `<relevant-memories>` block to the current user message; it does not append a standalone synthetic user message.
|
|
144
|
+
|
|
145
|
+
The reranking logic is not pure vector-score sorting. The current implementation also considers:
|
|
146
|
+
|
|
147
|
+
- whether a result is a leaf memory with `level == 2`
|
|
148
|
+
- whether it looks like a preference memory
|
|
149
|
+
- whether it looks like an event memory
|
|
150
|
+
- lexical overlap with the current query
|
|
151
|
+
|
|
152
|
+
## Session Lifecycle
|
|
153
|
+
|
|
154
|
+

|
|
155
|
+
|
|
156
|
+
Session handling is the main axis of this design. In the current implementation it covers history assembly, incremental append, asynchronous commit, and blocking compaction readback.
|
|
157
|
+
|
|
158
|
+
### What `assemble()` does
|
|
159
|
+
|
|
160
|
+
During preflight, `assemble()` is not just replaying old chat history. It reads session context back from OpenViking under a token budget, then rebuilds OpenClaw-facing messages:
|
|
161
|
+
|
|
162
|
+
- `latest_archive_overview` becomes `[Session History Summary]`
|
|
163
|
+
- `pre_archive_abstracts` becomes `[Archive Index]`
|
|
164
|
+
- active session messages stay in message-block form
|
|
165
|
+
- assistant tool parts become `toolCall` (input compatible: `toolUse`/`input` is normalized to `toolCall`/`arguments`)
|
|
166
|
+
- tool output becomes separate `toolResult`
|
|
167
|
+
- the final message list goes through a tool-use/result pairing repair pass
|
|
168
|
+
|
|
169
|
+
That means OpenClaw sees "compressed history summary + archive index + active messages", not an ever-growing raw transcript.
|
|
170
|
+
|
|
171
|
+
### What `afterTurn()` does
|
|
172
|
+
|
|
173
|
+
`afterTurn()` has a narrower job: append only the new turn into the OpenViking session.
|
|
174
|
+
|
|
175
|
+
- it slices only the newly added messages
|
|
176
|
+
- it keeps only `user` / `assistant` capture text
|
|
177
|
+
- it preserves `toolCall` / `toolResult` content in the serialized turn text
|
|
178
|
+
- it strips injected `<relevant-memories>` blocks and metadata noise before capture
|
|
179
|
+
- it appends the sanitized turn text into the OpenViking session
|
|
180
|
+
|
|
181
|
+
After that, the plugin checks `pending_tokens`. Once the session crosses `commitTokenThreshold`, it triggers `commit(wait=false)`:
|
|
182
|
+
|
|
183
|
+
- archive generation and Phase 2 memory extraction continue asynchronously on the server
|
|
184
|
+
- the current turn is not blocked waiting for extraction
|
|
185
|
+
- if `logFindRequests` is enabled, the logs include the task id and follow-up extraction detail
|
|
186
|
+
|
|
187
|
+
### What `compact()` does
|
|
188
|
+
|
|
189
|
+
`compact()` is the stricter synchronous boundary:
|
|
190
|
+
|
|
191
|
+
- it calls `commit(wait=true)` and blocks for completion
|
|
192
|
+
- when an archive exists, it re-reads `latest_archive_overview`
|
|
193
|
+
- it returns updated token estimates, the latest archive id, and summary content
|
|
194
|
+
- if the summary is too coarse, the model can call `ov_archive_expand` to reopen a specific archive
|
|
195
|
+
|
|
196
|
+
So `afterTurn()` is closer to "incremental append plus threshold-triggered async commit", while `compact()` is the explicit "wait for archive and compaction to finish" boundary.
|
|
197
|
+
|
|
198
|
+
## Tools and Expandability
|
|
199
|
+
|
|
200
|
+
Beyond automatic behavior, the plugin exposes six tools directly:
|
|
201
|
+
|
|
202
|
+
- `memory_recall`: explicit long-term memory search
|
|
203
|
+
- `memory_store`: write text into an OpenViking session and trigger commit
|
|
204
|
+
- `memory_forget`: delete by URI, or search first and remove a single strong match
|
|
205
|
+
- `ov_archive_expand`: expand a concrete archive back into raw messages
|
|
206
|
+
- `ov_import`: import a resource or skill; defaults to resource and uses `kind: "skill"` for skills
|
|
207
|
+
- `memory_search`: search OpenViking resources and skills, especially after importing them
|
|
208
|
+
|
|
209
|
+
They serve different roles:
|
|
210
|
+
|
|
211
|
+
- automatic recall covers the default case where the model does not know what to search yet
|
|
212
|
+
- `memory_recall` gives the model an explicit follow-up search path
|
|
213
|
+
- `memory_store` is for immediately persisting clearly important information
|
|
214
|
+
- `ov_archive_expand` is the "go back to archive detail" escape hatch when summaries are not enough
|
|
215
|
+
- `ov_import` lets the agent complete explicit import requests without asking the user to remember slash commands
|
|
216
|
+
- `memory_search` closes the loop after import by letting the user or agent confirm and consume resources and skills
|
|
217
|
+
|
|
218
|
+
`ov_archive_expand` is especially important because `assemble()` normally returns archive summaries and indexes, not the full raw transcript.
|
|
219
|
+
|
|
220
|
+
### Resource and Skill Import
|
|
221
|
+
|
|
222
|
+
Resource and skill imports are intentionally separate because they land in different OpenViking namespaces and use different server APIs:
|
|
223
|
+
|
|
224
|
+
- resources go through `/api/v1/resources` and land under `viking://resources/...`
|
|
225
|
+
- skills go through `/api/v1/skills` and land under `viking://agent/skills/...`
|
|
226
|
+
|
|
227
|
+
The plugin also registers explicit slash commands for manual imports:
|
|
228
|
+
|
|
229
|
+
```text
|
|
230
|
+
/ov-import ./README.md --to viking://resources/openviking-readme --wait
|
|
231
|
+
/ov-import ./skills/install-openviking-memory --kind skill --wait
|
|
232
|
+
/memory-search "OpenViking install" --uri viking://resources/openviking-readme
|
|
233
|
+
/memory-search "memory install skill" --uri viking://agent/skills
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Resource import supports remote URLs, Git URLs, local files, local directories, and uploaded zip files. OpenViking's built-in parsers cover common documents and media such as Markdown, text, PDF, HTML, Word, PowerPoint, Excel, EPUB, images, audio, and video. Directory imports also accept common code, documentation, and config file extensions such as `.py`, `.js`, `.ts`, `.go`, `.rs`, `.java`, `.cpp`, `.json`, `.yaml`, `.toml`, `.csv`, `.rst`, `.proto`, `.tf`, and `.vue`.
|
|
237
|
+
|
|
238
|
+
For HTTP safety, the plugin never sends a direct local filesystem path to the OpenViking server. Local files and directories are first uploaded through `/api/v1/resources/temp_upload`; directories are zipped locally with a pure JavaScript zip implementation before upload.
|
|
239
|
+
|
|
240
|
+
## Runtime Mode
|
|
241
|
+
|
|
242
|
+

|
|
243
|
+
|
|
244
|
+
The plugin operates exclusively in remote mode as a pure HTTP client:
|
|
245
|
+
|
|
246
|
+
- `baseUrl` and optional `apiKey` come from plugin config
|
|
247
|
+
- no local subprocess is started or managed
|
|
248
|
+
- session context, memory search/read, commit, and archive expansion behavior stays the same
|
|
249
|
+
|
|
250
|
+
The OpenViking service must be deployed and running independently before the plugin can connect to it.
|
|
251
|
+
|
|
252
|
+
## Relationship to the Older Design Draft
|
|
253
|
+
|
|
254
|
+
The repo also contains a more future-looking design draft at `docs/design/openclaw-context-engine-refactor.md`. It is important not to conflate the two:
|
|
255
|
+
|
|
256
|
+
- this README describes current implemented behavior
|
|
257
|
+
- the older draft discusses a stronger future move into context-engine-owned lifecycle control
|
|
258
|
+
- in the current version, the main automatic recall path lives in `assemble()`: preflight rebuilds history, transformContext injects long-term memories
|
|
259
|
+
- in the current version, `afterTurn()` already appends to the OpenViking session, but commit remains threshold-triggered and asynchronous on that path
|
|
260
|
+
- in the current version, `compact()` already uses `commit(wait=true)`, but it is still focused on synchronous commit plus readback rather than owning every orchestration concern
|
|
261
|
+
|
|
262
|
+
That distinction matters, otherwise the future design draft is easy to misread as already shipped behavior.
|
|
263
|
+
|
|
264
|
+
## Operator and Debugging Surfaces
|
|
265
|
+
|
|
266
|
+
If you need to debug this plugin, start with these entry points.
|
|
267
|
+
|
|
268
|
+
### Inspect the current setup
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
openclaw openviking status --json
|
|
272
|
+
openclaw plugins list
|
|
273
|
+
openclaw config get plugins.entries.openviking.config
|
|
274
|
+
openclaw config get plugins.slots.contextEngine
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Watch logs
|
|
278
|
+
|
|
279
|
+
OpenClaw plugin logs:
|
|
280
|
+
|
|
281
|
+
```bash
|
|
282
|
+
openclaw logs --follow
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
OpenViking service logs:
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
cat ~/.openviking/data/log/openviking.log
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### Web Console
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
python -m openviking.console.bootstrap --host 0.0.0.0 --port 8020 --openviking-url http://127.0.0.1:1933
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### `ov tui`
|
|
298
|
+
|
|
299
|
+
```bash
|
|
300
|
+
ov tui
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
### Common things to check
|
|
304
|
+
|
|
305
|
+
| Symptom | More likely cause | First check |
|
|
306
|
+
| --- | --- | --- |
|
|
307
|
+
| `plugins.slots.contextEngine` is not `openviking` | The plugin slot was never set, or another plugin replaced it | `openclaw config get plugins.slots.contextEngine` |
|
|
308
|
+
| Cannot connect to OpenViking service | `baseUrl` is wrong or the service is down | Check `baseUrl` in config and test connectivity manually |
|
|
309
|
+
| recall behaves inconsistently across sessions | Routing identity is not what you expected | Enable `logFindRequests`, then inspect `openclaw logs --follow` |
|
|
310
|
+
| long chats stop extracting memory | `pending_tokens` never crosses the threshold, or Phase 2 fails server-side | Check plugin config and `~/.openviking/data/log/openviking.log` |
|
|
311
|
+
| summaries are too coarse for detailed questions | You need archive-level detail, not just summary | Use an ID from `[Archive Index]` with `ov_archive_expand` |
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
For installation, upgrade, and uninstall operations, use [INSTALL.md](./INSTALL.md).
|