Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

Enhance OpenViking Status Checks in the OpenClaw Plugin (#453)

AutoCoder226db50da155
diff --git a/examples/openclaw-memory-plugin/INSTALL-ZH.md b/examples/openclaw-memory-plugin/INSTALL-ZH.md
index e7c57b652..6dfa6111c 100644
--- a/examples/openclaw-memory-plugin/INSTALL-ZH.md
+++ b/examples/openclaw-memory-plugin/INSTALL-ZH.md
@@ -401,6 +401,22 @@ call "%USERPROFILE%\.openclaw\openviking.env.bat" && openclaw gateway
> alias openclaw-start='source ~/.openclaw/openviking.env && openclaw gateway'
> ```
+### 5.1 启用或关闭记忆插件
+
+关闭 OpenViking 记忆插件:
+
+```bash
+openclaw config set plugins.slots.memory none
+```
+
+启用 OpenViking 记忆插件:
+
+```bash
+openclaw config set plugins.slots.memory memory-openviking
+```
+
+如果 gateway 已在运行,修改 slot 后请重启 gateway 使配置生效。
+
插件会自动启动和停止 OpenViking 服务。
---
diff --git a/examples/openclaw-memory-plugin/INSTALL.md b/examples/openclaw-memory-plugin/INSTALL.md
index 52406a77b..f3c0a7b56 100644
--- a/examples/openclaw-memory-plugin/INSTALL.md
+++ b/examples/openclaw-memory-plugin/INSTALL.md
@@ -401,6 +401,22 @@ call "%USERPROFILE%\.openclaw\openviking.env.bat" && openclaw gateway
> alias openclaw-start='source ~/.openclaw/openviking.env && openclaw gateway'
> ```
+### 5.1 Enable or Disable the Memory Plugin
+
+Disable the OpenViking memory plugin:
+
+```bash
+openclaw config set plugins.slots.memory none
+```
+
+Enable the OpenViking memory plugin:
+
+```bash
+openclaw config set plugins.slots.memory memory-openviking
+```
+
+If the gateway is already running, restart it after changing the slot.
+
The plugin automatically starts and stops the OpenViking server.
---
diff --git a/examples/openclaw-memory-plugin/index.ts b/examples/openclaw-memory-plugin/index.ts
index 7b3cdbf44..6aae9e558 100644
--- a/examples/openclaw-memory-plugin/index.ts
+++ b/examples/openclaw-memory-plugin/index.ts
@@ -1,6 +1,7 @@
import { spawn, execSync } from "node:child_process";
import { createHash } from "node:crypto";
import { readFileSync, existsSync } from "node:fs";
+import { Socket } from "node:net";
import { join } from "node:path";
import { homedir, tmpdir, platform } from "node:os";
@@ -901,6 +902,90 @@ function withTimeout<T>(promise: Promise<T>, timeoutMs: number, timeoutMessage:
});
}
+function quickTcpProbe(host: string, port: number, timeoutMs: number): Promise<boolean> {
+ return new Promise((resolve) => {
+ const socket = new Socket();
+ let done = false;
+ const finish = (ok: boolean) => {
+ if (done) {
+ return;
+ }
+ done = true;
+ socket.destroy();
+ resolve(ok);
+ };
+ socket.setTimeout(timeoutMs);
+ socket.once("connect", () => finish(true));
+ socket.once("timeout", () => finish(false));
+ socket.once("error", () => finish(false));
+ try {
+ socket.connect(port, host);
+ } catch {
+ finish(false);
+ }
+ });
+}
+
+async function quickHealthCheck(baseUrl: string, timeoutMs: number): Promise<boolean> {
+ const controller = new AbortController();
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
+ try {
+ const response = await fetch(`${baseUrl}/health`, {
+ method: "GET",
+ signal: controller.signal,
+ });
+ if (!response.ok) {
+ return false;
+ }
+ const body = (await response.json().catch(() => ({}))) as { status?: string };
+ return body.status === "ok";
+ } catch {
+ return false;
+ } finally {
+ clearTimeout(timer);
+ }
+}
+
+async function quickRecallPrecheck(
+ mode: "local" | "remote",
+ baseUrl: string,
+ defaultPort: number,
+ localProcess: ReturnType<typeof spawn> | null,
+): Promise<{ ok: true } | { ok: false; reason: string }> {
+ const healthOk = await quickHealthCheck(baseUrl, 500);
+ if (healthOk) {
+ return { ok: true };
+ }
+
+ let host = "127.0.0.1";
+ let port = defaultPort;
+ try {
+ const parsed = new URL(baseUrl);
+ if (parsed.hostname) {
+ host = parsed.hostname;
+ }
+ if (parsed.port) {
+ const parsedPort = Number(parsed.port);
+ if (Number.isFinite(parsedPort) && parsedPort > 0) {
+ port = parsedPort;
+ }
+ }
+ } catch {
+ // Keep defaults when baseUrl is malformed.
+ }
+
+ if (mode === "local") {
+ const portOk = await quickTcpProbe(host, port, 200);
+ if (!portOk) {
+ return { ok: false, reason: `local port unavailable (${host}:${port})` };
+ }
+ if (localProcess && (localProcess.killed || localProcess.exitCode !== null || localProcess.signalCode !== null)) {
+ return { ok: false, reason: "local process is not running" };
+ }
+ }
+ return { ok: false, reason: "health check failed" };
+}
+
const memoryPlugin = {
id: "memory-openviking",
name: "Memory (OpenViking)",
@@ -1196,54 +1281,49 @@ const memoryPlugin = {
const prependContextParts: string[] = [];
if (cfg.autoRecall && queryText.length >= 5) {
- if (cfg.mode === "local" && localUnavailableReason) {
+ const precheck = await quickRecallPrecheck(cfg.mode, cfg.baseUrl, cfg.port, localProcess);
+ if (!precheck.ok) {
api.logger.info?.(
- `memory-openviking: skipping auto-recall because local mode is unavailable (${localUnavailableReason})`,
+ `memory-openviking: skipping auto-recall because precheck failed (${precheck.reason})`,
);
} else {
- try {
- const candidateLimit = Math.max(cfg.recallLimit * 4, cfg.recallLimit);
- const result = await withTimeout(
- getClient().then((client) =>
- client.find(queryText, {
- targetUri: cfg.targetUri,
- limit: candidateLimit,
- scoreThreshold: 0,
- }),
- ),
- autoRecallTimeoutMs,
- `OpenViking auto-recall timeout after ${autoRecallTimeoutMs}ms`,
- );
- const processed = postProcessMemories(result.memories ?? [], {
- limit: candidateLimit,
- scoreThreshold: cfg.recallScoreThreshold,
- });
- const memories = pickMemoriesForInjection(processed, cfg.recallLimit, queryText);
- if (memories.length > 0) {
- const memoryContext = memories
- .map((item) => `- [${item.category ?? "memory"}] ${item.abstract ?? item.uri}`)
- .join("\n");
- api.logger.info?.(
- `memory-openviking: injecting ${memories.length} memories into context`,
- );
- api.logger.info?.(
- `memory-openviking: inject-detail ${toJsonLog({ count: memories.length, memories: summarizeInjectionMemories(memories) })}`,
+ try {
+ const candidateLimit = Math.max(cfg.recallLimit * 4, cfg.recallLimit);
+ const result = await withTimeout(
+ getClient().then((client) =>
+ client.find(queryText, {
+ targetUri: cfg.targetUri,
+ limit: candidateLimit,
+ scoreThreshold: 0,
+ }),
+ ),
+ autoRecallTimeoutMs,
+ `OpenViking auto-recall timeout after ${autoRecallTimeoutMs}ms`,
);
- prependContextParts.push(
- "<relevant-memories>\nThe following OpenViking memories may be relevant:\n" +
- `${memoryContext}\n` +
- "</relevant-memories>",
- );
- }
- } catch (err) {
- if (cfg.mode === "local") {
- const message = String(err).toLowerCase();
- if (message.includes("timeout") || message.includes("unavailable")) {
- markLocalUnavailable("auto-recall timeout", err);
+ const processed = postProcessMemories(result.memories ?? [], {
+ limit: candidateLimit,
+ scoreThreshold: cfg.recallScoreThreshold,
+ });
+ const memories = pickMemoriesForInjection(processed, cfg.recallLimit, queryText);
+ if (memories.length > 0) {
+ const memoryContext = memories
+ .map((item) => `- [${item.category ?? "memory"}] ${item.abstract ?? item.uri}`)
+ .join("\n");
+ api.logger.info?.(
+ `memory-openviking: injecting ${memories.length} memories into context`,
+ );
+ api.logger.info?.(
+ `memory-openviking: inject-detail ${toJsonLog({ count: memories.length, memories: summarizeInjectionMemories(memories) })}`,
+ );
+ prependContextParts.push(
+ "<relevant-memories>\nThe following OpenViking memories may be relevant:\n" +
+ `${memoryContext}\n` +
+ "</relevant-memories>",
+ );
}
+ } catch (err) {
+ api.logger.warn(`memory-openviking: auto-recall failed: ${String(err)}`);
}
- api.logger.warn(`memory-openviking: auto-recall failed: ${String(err)}`);
- }
}
}
diff --git a/examples/openclaw-memory-plugin/install.ps1 b/examples/openclaw-memory-plugin/install.ps1
index 48dbbfd50..fa4fd38e4 100644
--- a/examples/openclaw-memory-plugin/install.ps1
+++ b/examples/openclaw-memory-plugin/install.ps1
@@ -331,7 +331,7 @@ function Configure-OpenClawPlugin {
mode = "local"
configPath = $ovConfPath
port = $ServerPort
- targetUri = "viking://"
+ targetUri = "viking://user/memories"
autoRecall = $true
autoCapture = $true
}
diff --git a/examples/openclaw-memory-plugin/install.sh b/examples/openclaw-memory-plugin/install.sh
index 214cae960..241b0b3a6 100644
--- a/examples/openclaw-memory-plugin/install.sh
+++ b/examples/openclaw-memory-plugin/install.sh
@@ -524,7 +524,7 @@ configure_openclaw_plugin() {
openclaw config set plugins.entries.memory-openviking.config.mode local
openclaw config set plugins.entries.memory-openviking.config.configPath "${config_path}"
openclaw config set plugins.entries.memory-openviking.config.port "${server_port}"
- openclaw config set plugins.entries.memory-openviking.config.targetUri viking://
+ openclaw config set plugins.entries.memory-openviking.config.targetUri viking://user/memories
openclaw config set plugins.entries.memory-openviking.config.autoRecall true --json
openclaw config set plugins.entries.memory-openviking.config.autoCapture true --json
info "$(tr "OpenClaw plugin configured" "OpenClaw 插件配置完成")"
diff --git a/examples/openclaw-memory-plugin/skills/install-openviking-memory/SKILL.md b/examples/openclaw-memory-plugin/skills/install-openviking-memory/SKILL.md
index a5b306ec2..4a70a7442 100644
--- a/examples/openclaw-memory-plugin/skills/install-openviking-memory/SKILL.md
+++ b/examples/openclaw-memory-plugin/skills/install-openviking-memory/SKILL.md
@@ -241,6 +241,22 @@ call "%USERPROFILE%\.openclaw\openviking.env.bat" && openclaw gateway
> echo 'alias openclaw-start="source ~/.openclaw/openviking.env && openclaw gateway"' >> ~/.bashrc
> ```
+### Enable/Disable the Memory Plugin Slot
+
+Disable the memory plugin:
+
+```bash
+openclaw config set plugins.slots.memory none
+```
+
+Enable the OpenViking memory plugin:
+
+```bash
+openclaw config set plugins.slots.memory memory-openviking
+```
+
+If the gateway is already running, restart it after changing the slot.
+
---
## Uninstall