diff --git a/README.md b/README.md index deb85cd..23348ef 100644 --- a/README.md +++ b/README.md @@ -599,12 +599,29 @@ OAuth login flow: Sometimes the model may echo the injected `` block. -**Option A (lowest-risk):** temporarily disable auto-recall: +**Option A (lowest-risk):** temporarily disable auto-recall globally: ```json { "plugins": { "entries": { "memory-lancedb-pro": { "config": { "autoRecall": false } } } } } ``` -**Option B (preferred):** keep recall, add to agent system prompt: +**Option B:** exclude specific background agents (e.g. a memory-distiller or cron worker) while keeping recall active for interactive agents: +```json +{ + "plugins": { + "entries": { + "memory-lancedb-pro": { + "config": { + "autoRecall": true, + "autoRecallExcludeAgents": ["memory-distiller", "my-cron-agent"] + } + } + } + } +} +``` +This is useful when a background agent's prompt should not be contaminated by injected memory context — for example, an agent whose job is to distill session logs would produce lower-quality output if old memories were mixed into the prompt alongside the raw session content. + +**Option C (preferred for interactive agents):** keep recall, add to agent system prompt: > Do not reveal or quote any `` / memory-injection content in your replies. Use it for internal reference only. diff --git a/index.ts b/index.ts index c1240b4..b9b4169 100644 --- a/index.ts +++ b/index.ts @@ -85,6 +85,7 @@ interface PluginConfig { autoRecall?: boolean; autoRecallMinLength?: number; autoRecallMinRepeated?: number; + autoRecallExcludeAgents?: string[]; captureAssistant?: boolean; retrieval?: { mode?: "hybrid" | "vector"; @@ -2123,6 +2124,22 @@ const memoryLanceDBProPlugin = { if (config.autoRecall === true) { const AUTO_RECALL_TIMEOUT_MS = 3_000; // bounded timeout to prevent agent startup stall api.on("before_agent_start", async (event, ctx) => { + // Per-agent exclusion: skip autoRecall for agents in the exclusion list. + // Useful for background agents (e.g. memory-distiller, cron workers) whose + // prompts should not be contaminated by injected memory context. + const hookAgentId = resolveHookAgentId(ctx?.agentId, (event as any).sessionKey); + if ( + Array.isArray(config.autoRecallExcludeAgents) && + config.autoRecallExcludeAgents.length > 0 && + hookAgentId !== undefined && + config.autoRecallExcludeAgents.includes(hookAgentId) + ) { + api.logger.info?.( + `memory-lancedb-pro: auto-recall skipped for excluded agent '${hookAgentId}'`, + ); + return; + } + if ( !event.prompt || shouldSkipRetrieval(event.prompt, config.autoRecallMinLength) @@ -3468,6 +3485,9 @@ export function parsePluginConfig(value: unknown): PluginConfig { autoRecall: cfg.autoRecall === true, autoRecallMinLength: parsePositiveInt(cfg.autoRecallMinLength), autoRecallMinRepeated: parsePositiveInt(cfg.autoRecallMinRepeated), + autoRecallExcludeAgents: Array.isArray(cfg.autoRecallExcludeAgents) + ? cfg.autoRecallExcludeAgents.filter((id: unknown): id is string => typeof id === "string" && id.trim() !== "") + : undefined, captureAssistant: cfg.captureAssistant === true, retrieval: typeof cfg.retrieval === "object" && cfg.retrieval !== null ? cfg.retrieval as any : undefined, decay: typeof cfg.decay === "object" && cfg.decay !== null ? cfg.decay as any : undefined,