Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
fix(pi): honor recallExcludeUris and recallQueryFilters (#5368)
KorenKrita75830be2ec92
diff --git a/examples/pi-coding-agent-extension/README.md b/examples/pi-coding-agent-extension/README.mdindex e40ac5ccc..4d08929a9 100644--- a/examples/pi-coding-agent-extension/README.md+++ b/examples/pi-coding-agent-extension/README.md@@ -148,6 +148,8 @@ All fields below live in `ovcli.conf`'s `plugin` section, or in the `plugin.pi`| `recallLimit` | `10` | Legacy quota-scaling input converted to six coding quotas, not a final cap || `scoreThreshold` | `0.35` | Min relevance score (0–1) || `minQueryLength` | `3` | Skip recall for queries shorter than N characters |+| `recallQueryFilters` | `[]` | sed-style rules applied to the prompt before recall (`s///`, `d//`, `k//`) |+| `recallExcludeUris` | `[]` | URIs the recall search must never return (sent as `exclude_uris`) || `recallLedger` | `true` | Persist injected blocks and re-apply them to historical user messages so provider prompt-prefix caches keep hitting |### Recall injection ledgerdiff --git a/examples/pi-coding-agent-extension/config.ts b/examples/pi-coding-agent-extension/config.tsindex 0cff597cc..4c2a942e6 100644--- a/examples/pi-coding-agent-extension/config.ts+++ b/examples/pi-coding-agent-extension/config.ts@@ -32,6 +32,8 @@ export interface OVConfig {recallLedger: boolean;scoreThreshold: number;minQueryLength: number;+ recallQueryFilters: string[];+ recallExcludeUris: string[];profileTokenBudget: number;skillCatalog: boolean;skillCatalogTokenBudget: number;diff --git a/examples/pi-coding-agent-extension/package-lock.json b/examples/pi-coding-agent-extension/package-lock.jsonindex c902f963a..acec93146 100644--- a/examples/pi-coding-agent-extension/package-lock.json+++ b/examples/pi-coding-agent-extension/package-lock.json@@ -1,12 +1,12 @@{"name": "openviking-pi-extension",- "version": "0.4.5",+ "version": "0.4.6","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "openviking-pi-extension",- "version": "0.4.5",+ "version": "0.4.6","dependencies": {"@modelcontextprotocol/client": "2.0.0"},diff --git a/examples/pi-coding-agent-extension/package.json b/examples/pi-coding-agent-extension/package.jsonindex 11e514987..d1600353b 100644--- a/examples/pi-coding-agent-extension/package.json+++ b/examples/pi-coding-agent-extension/package.json@@ -1,6 +1,6 @@{"name": "openviking-pi-extension",- "version": "0.4.5",+ "version": "0.4.6","description": "OpenViking memory and context extension for the pi coding agent","private": true,"type": "module",diff --git a/examples/pi-coding-agent-extension/recall.ts b/examples/pi-coding-agent-extension/recall.tsindex 7af3b0a6d..7869ab40e 100644--- a/examples/pi-coding-agent-extension/recall.ts+++ b/examples/pi-coding-agent-extension/recall.ts@@ -1,6 +1,7 @@import type { OVClient } from "./client.js";import type { OVConfig } from "./config.js";import { buildRecallBlock, isRecallEnabled } from "./shared/recall-core.mjs";+import { applyInputFilters, compileInputFilters } from "./shared/input-filters.mjs";import { RecallLedger, ledgerKey } from "./lib/recall-ledger.mjs";export interface RecallCache {@@ -48,7 +49,19 @@ export class RecallManager {this.cache = { block: null, promptText: userQuery };return null;}- if (userQuery.trim().length < this.config.minQueryLength) {+ // Filters run before the length gate, so a prompt whose only content was a+ // stripped prefix counts as short rather than searching for the rest.+ let query = userQuery;+ const queryFilters = compileInputFilters(this.config.recallQueryFilters);+ if (queryFilters.rules.length) {+ const verdict = applyInputFilters(query, queryFilters.rules, { role: "user" });+ if (verdict.dropped) {+ this.cache = { block: null, promptText: userQuery };+ return null;+ }+ query = verdict.text;+ }+ if (query.trim().length < this.config.minQueryLength) {this.cache = { block: null, promptText: userQuery };return null;}@@ -59,7 +72,7 @@ export class RecallManager {// deadline, and ignoring it would abort a request still inside its fuse.(path, init, options) => this.client.fetchJSON(path, init, options),this.config,- userQuery,+ query,{actorPeerId: this.config.peerId,// Under `actor` scope the effective peer is the only one asked, so a@@ -68,6 +81,7 @@ export class RecallManager {// Passing the OV session id is what turns on server-side query// expansion and the cross-turn dedup ledger.sessionId: this.sessionId() ?? "",+ excludeUris: this.config.recallExcludeUris,},);this.cache = { block, promptText: userQuery };diff --git a/examples/pi-coding-agent-extension/tests/recall-deferred.test.mjs b/examples/pi-coding-agent-extension/tests/recall-deferred.test.mjsindex f48642fe3..096625f38 100644--- a/examples/pi-coding-agent-extension/tests/recall-deferred.test.mjs+++ b/examples/pi-coding-agent-extension/tests/recall-deferred.test.mjs@@ -135,3 +135,45 @@ test("a queued short prompt clears the previous recall block", async () => {assert.deepEqual(recall.injectRecall(messages), messages);assert.equal(messages[0].content, "x");});++test("recall forwards recallExcludeUris as exclude_uris", async () => {+ const bodies = [];+ const client = {+ fetchJSON: async (path, init) => {+ bodies.push(JSON.parse(init.body));+ return { ok: true, result: { rendered: "- memory" } };+ },+ };+ const excluded = ["viking://user/default/resources", "viking://agent/skills"];+ const recall = new RecallManager(client, config({ recallExcludeUris: excluded }), () => "pi-session");++ recall.queueSearch("project conventions");+ await recall.searchPending();+ assert.deepEqual(bodies[0].exclude_uris, excluded);+});++test("recallQueryFilters drop or rewrite the prompt before it is searched", async () => {+ const bodies = [];+ const client = {+ fetchJSON: async (path, init) => {+ bodies.push(JSON.parse(init.body));+ return { ok: true, result: { rendered: "- memory" } };+ },+ };+ const recall = new RecallManager(client, config({+ recallQueryFilters: ["s/^\\s*ultrathink\\s+//i", "d/^\\s*(ok|yes)\\s*$/i"],+ }));++ recall.queueSearch("ok");+ assert.equal(await recall.searchPending(), null);+ assert.equal(bodies.length, 0, "a dropped prompt must not reach the server");++ recall.queueSearch("ultrathink project conventions");+ await recall.searchPending();+ assert.equal(bodies.length, 1);+ assert.equal(bodies[0].query, "project conventions");++ recall.queueSearch("ultrathink ab");+ assert.equal(await recall.searchPending(), null, "the length gate applies to the filtered text");+ assert.equal(bodies.length, 1);+});