Skip to content

Commit 84fc9f3

Browse files
committed
Detect allowPromptInjection in the plugin and skip meaningless auto-recall early.
-When allowPromptInjection=false, the OpenClaw framework strips prompt mutation fields from before_agent_start results, leaving undefined. -The ?? fallback in attempt.ts then invokes the hook a second time. MemOS's auto-recall (LLM + embedding search) runs twice per message, and both results are discarded.
1 parent 6a43b49 commit 84fc9f3

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

apps/memos-local-openclaw/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,18 @@ const memosLocalPlugin = {
211211

212212
api.logger.info(`memos-local: initialized (db: ${ctx.config.storage!.dbPath})`);
213213

214+
// ─── Check allowPromptInjection policy ───
215+
// When allowPromptInjection=false, the prompt mutation fields (such as prependContext) in the hook return value
216+
// will be stripped by the framework. Skip auto-recall to avoid unnecessary LLM/embedding calls.
217+
const pluginEntry = (api.config as any)?.plugins?.entries?.[api.id];
218+
const allowPromptInjection = pluginEntry?.hooks?.allowPromptInjection !== false;
219+
if (!allowPromptInjection) {
220+
api.logger.info("memos-local: allowPromptInjection=false, auto-recall disabled");
221+
}
222+
else {
223+
api.logger.info("memos-local: allowPromptInjection=true, auto-recall enabled");
224+
}
225+
214226
const trackTool = (toolName: string, fn: (...args: any[]) => Promise<any>) =>
215227
async (...args: any[]) => {
216228
const t0 = performance.now();
@@ -860,6 +872,7 @@ const memosLocalPlugin = {
860872
let lastRecalledSummaries: string[] = [];
861873

862874
api.on("before_agent_start", async (event: { prompt?: string; messages?: unknown[]; agentId?: string }) => {
875+
if (!allowPromptInjection) return {};
863876
lastRecalledChunkIds = new Set();
864877
lastRecalledSummaries = [];
865878
if (!event.prompt || event.prompt.length < 3) return;

0 commit comments

Comments
 (0)