Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/openclaw-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Once installed, the plugin provides these agent tools:

`add_resource` is hidden from agents by default (`enableAddResourceTool=false`), while manual `/add-resource` remains available. Configure `recallTargetTypes` to choose default recall targets (`user`, `agent`, `resource`); legacy `recallResources=true` appends `resource` only when `recallTargetTypes` is unset.

Set `recallExcludeUris` (comma-separated subtree URIs) to keep generated directory files such as `viking://user/memories/skills` or `viking://agent/skills` out of auto-recall: they are forwarded to the context search as `exclude_uris`, so boilerplate matches never consume the recall budget.

## Data Flow & Privacy

- **What is sent**: User/assistant message text from each turn (after stripping injected memory blocks and metadata noise).
Expand Down
2 changes: 2 additions & 0 deletions examples/openclaw-plugin/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ Agent 会自动完成安装 → 配置 → 重启 → 验证。详见 [INSTALL-A

插件还提供手动 slash command:`/add-resource`、`/add-skill`、`/ov-search`、`/ov-recall-trace`。Agent 可见的 `add_resource` 工具默认禁用(`enableAddResourceTool=false`),避免搜索/检索阶段误触发资源导入;如确实要允许 Agent 导入资源,可显式设置 `enableAddResourceTool=true`,否则使用手动 `/add-resource`。

设置 `recallExcludeUris`(逗号分隔的子树 URI)可以把 `viking://user/memories/skills`、`viking://agent/skills` 这类生成的目录文件挡在自动召回之外:它们会作为 `exclude_uris` 发给 context search,避免样板内容白白消耗召回配额。

## 数据流与隐私

- **发送内容**:每轮 user/assistant 消息文本(已剥离注入的记忆块和元数据噪音)。
Expand Down
1 change: 1 addition & 0 deletions examples/openclaw-plugin/auto-recall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ export async function buildAutoRecallContext(params: {
peerScope: "actor",
actorPeerId,
requestTimeoutMs: cfg.autoRecallTimeoutMs,
excludeUris: Array.isArray(cfg.recallExcludeUris) ? cfg.recallExcludeUris : [],
});
} catch (error) {
requestError = error;
Expand Down
7 changes: 6 additions & 1 deletion examples/openclaw-plugin/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export type SearchContextOptions = {
peerScope?: "actor" | "all";
actorPeerId?: string;
requestTimeoutMs?: number;
/** Subtree URIs forwarded to the server as exclude_uris; empty means no exclusions. */
excludeUris?: string[];
};

export type FsListEntry = string | Record<string, unknown>;
Expand Down Expand Up @@ -506,7 +508,10 @@ export class OpenVikingClient {
timeoutMs: this.timeoutMs,
};
const body = {
...buildContextSearchBody(contractConfig, { sessionId: options.sessionId }),
...buildContextSearchBody(contractConfig, {
sessionId: options.sessionId,
excludeUris: options.excludeUris,
}),
...(options.dedupTurns === 0 ? { dedup_turns: 0 } : {}),
query,
...(options.contextType !== undefined ? { context_type: options.contextType } : {}),
Expand Down
20 changes: 19 additions & 1 deletion examples/openclaw-plugin/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ export type MemoryOpenVikingConfig = {
traceRecallIncludeRawUserPreview?: boolean;
/** Auto-recall target resource types. Empty means the backward-compatible memory recall set. */
recallTargetTypes?: Array<"resource" | "user" | "agent"> | string;
/**
* Subtree URIs the auto-recall context search must never return, forwarded
* to the server as `exclude_uris`. Without it, generated directory files
* (viking://user/<space>/skills, viking://user/<space>/resources,
* viking://agent/skills) match like ordinary content and consume the
* per-turn recall budget with boilerplate.
*/
recallExcludeUris?: Array<string> | string;
/** Agent-visible add_resource tool is disabled by default; manual /add-resource remains available. */
enableAddResourceTool?: boolean;
/** Agent-visible tool allowlist. Supports exact tool names or groups such as "memory" and "resource_query". */
Expand All @@ -133,14 +141,15 @@ export type MemoryOpenVikingConfig = {

/** Runtime config after memoryOpenVikingConfigSchema.parse() has applied defaults. */
export type ParsedMemoryOpenVikingConfig = Required<
Omit<MemoryOpenVikingConfig, "agentExperience" | "recallTargetTypes" | "apiKey" | "peer_role">
Omit<MemoryOpenVikingConfig, "agentExperience" | "recallTargetTypes" | "recallExcludeUris" | "apiKey" | "peer_role">
> & {
/** parse() resolves SecretRef values, so the runtime shape is always a plain string. */
apiKey: string;
/** Runtime uses the canonical name; legacy `person` input normalizes to `sender`. */
peer_role: "none" | "assistant" | "sender";
agentExperience: Required<NonNullable<MemoryOpenVikingConfig["agentExperience"]>>;
recallTargetTypes: Array<"resource" | "user" | "agent">;
recallExcludeUris: string[];
};

const DEFAULT_BASE_URL = "http://127.0.0.1:1933";
Expand Down Expand Up @@ -570,6 +579,7 @@ export const memoryOpenVikingConfigSchema = {
"traceRecallIncludeContentByDefault",
"traceRecallIncludeRawUserPreview",
"recallTargetTypes",
"recallExcludeUris",
"enableAddResourceTool",
"enabledTools",
"disabledTools",
Expand Down Expand Up @@ -647,6 +657,7 @@ export const memoryOpenVikingConfigSchema = {
cfg.recallTargetTypes,
!("recallTargetTypes" in cfg) && recallResources,
);
const recallExcludeUris = [...new Set(toStringArray(cfg.recallExcludeUris, []))];
const { enabledTools, disabledTools } = normalizeEnabledTools(cfg);

return {
Expand Down Expand Up @@ -766,6 +777,7 @@ export const memoryOpenVikingConfigSchema = {
traceRecallIncludeContentByDefault: cfg.traceRecallIncludeContentByDefault === true,
traceRecallIncludeRawUserPreview: cfg.traceRecallIncludeRawUserPreview === true,
recallTargetTypes,
recallExcludeUris,
recallCompress,
enableAddResourceTool: cfg.enableAddResourceTool === true,
enabledTools,
Expand Down Expand Up @@ -899,6 +911,12 @@ export const memoryOpenVikingConfigSchema = {
help: "Comma-separated auto-recall and default memory_recall targets: user, agent, resource. Session history is available through ov_archive_search and ov_archive_expand.",
advanced: true,
},
recallExcludeUris: {
label: "Recall Exclude URIs",
placeholder: "viking://user/memories/skills,viking://agent/skills",
help: "Comma-separated subtree URIs the auto-recall context search must never return (sent as exclude_uris). Keeps generated directory files from consuming the recall budget.",
advanced: true,
},
recallLimit: {
label: "Recall Limit",
placeholder: String(DEFAULT_RECALL_LIMIT),
Expand Down
27 changes: 27 additions & 0 deletions examples/openclaw-plugin/tests/ut/build-memory-lines.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,33 @@ describe("buildAutoRecallContext trace", () => {
expect(recorded.searches.map((search) => search.resourceType)).toEqual(["user"]);
});

it("forwards configured recallExcludeUris to the context search", async () => {
const cfg = makeCfg({ recallExcludeUris: "viking://user/memories/skills,viking://agent/skills" });
const client = {
healthCheck: vi.fn().mockResolvedValue(undefined),
searchContext: vi.fn().mockResolvedValue({
entries: [],
rendered: "",
stats: { candidates: 0, used_tokens: 0 },
}),
find: vi.fn(),
read: vi.fn(),
};

await buildAutoRecallContext({
cfg,
client: client as any,
agentId: "agent-1",
queryText: "where are the project docs?",
logger: { info: vi.fn(), warn: vi.fn() },
});

expect(client.searchContext).toHaveBeenCalledTimes(1);
expect(client.searchContext.mock.calls[0]?.[1]).toMatchObject({
excludeUris: ["viking://user/memories/skills", "viking://agent/skills"],
});
});

it("uses configured autoRecallTimeoutMs for both the request and outer budget", async () => {
vi.useFakeTimers();
try {
Expand Down
30 changes: 30 additions & 0 deletions examples/openclaw-plugin/tests/ut/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,36 @@ describe("OpenVikingClient canonical namespace policy", () => {
expect(routingDebugLog).toHaveBeenCalledWith(expect.stringContaining('"query_expansion":"auto"'));
});

it("forwards excludeUris as exclude_uris on the context search body", async () => {
const transport = vi.fn().mockResolvedValue(okResponse({ entries: [], rendered: "", stats: {} }));
const client = new OpenVikingClient(
"http://127.0.0.1:1933", "", "agent", 5000,
"", "", undefined, false, true, { transport },
);

await client.searchContext("deployment preferences", {
excludeUris: ["viking://user/memories/skills", "viking://agent/skills"],
});

const [, init] = transport.mock.calls[0] as [string, RequestInit];
expect(JSON.parse(String(init.body))).toMatchObject({
exclude_uris: ["viking://user/memories/skills", "viking://agent/skills"],
});
});

it("omits exclude_uris when no excludeUris are configured", async () => {
const transport = vi.fn().mockResolvedValue(okResponse({ entries: [], rendered: "", stats: {} }));
const client = new OpenVikingClient(
"http://127.0.0.1:1933", "", "agent", 5000,
"", "", undefined, false, true, { transport },
);

await client.searchContext("deployment preferences");

const [, init] = transport.mock.calls[0] as [string, RequestInit];
expect(JSON.parse(String(init.body))).not.toHaveProperty("exclude_uris");
});

it("normalizes context entries through the shared response contract", async () => {
const transport = vi.fn().mockResolvedValue(okResponse({
entries: [{
Expand Down
23 changes: 23 additions & 0 deletions examples/openclaw-plugin/tests/ut/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,29 @@ describe("memoryOpenVikingConfigSchema.parse()", () => {
).toThrow("recallTargetTypes contains unknown resource types: session");
});

it("normalizes recallExcludeUris from arrays and comma/newline-separated strings", () => {
const fromArray = memoryOpenVikingConfigSchema.parse({
recallExcludeUris: [" viking://user/memories/skills ", "viking://agent/skills", ""],
});
expect(fromArray.recallExcludeUris).toEqual([
"viking://user/memories/skills",
"viking://agent/skills",
]);

const fromString = memoryOpenVikingConfigSchema.parse({
recallExcludeUris: "viking://user/memories/skills, viking://agent/skills\nviking://user/memories/skills",
});
expect(fromString.recallExcludeUris).toEqual([
"viking://user/memories/skills",
"viking://agent/skills",
]);
});

it("defaults recallExcludeUris to an empty list", () => {
const cfg = memoryOpenVikingConfigSchema.parse({});
expect(cfg.recallExcludeUris).toEqual([]);
});

it("keeps deprecated recallResources as an additive compatibility switch when recallTargetTypes is unset", () => {
const cfg = memoryOpenVikingConfigSchema.parse({ recallResources: true });
expect(cfg.recallTargetTypes).toEqual(["user", "agent", "resource"]);
Expand Down