From 8b9f11df395e8b61a59cc8483cd2165092d7f393 Mon Sep 17 00:00:00 2001 From: kartik-mem0 Date: Mon, 6 Apr 2026 14:00:31 +0530 Subject: [PATCH] fix: double add and update call --- openclaw/index.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/openclaw/index.ts b/openclaw/index.ts index 0435f3490..41b7beab7 100644 --- a/openclaw/index.ts +++ b/openclaw/index.ts @@ -775,6 +775,20 @@ function registerHooks( // Update shared state for tools (best-effort — tools don't have ctx) if (sessionId) session.setCurrentSessionId(sessionId); + const MEMORY_WRITE_TOOLS = new Set(["memory_add", "memory_update"]); + const agentUsedWriteTool = event.messages.some((msg: any) => { + if (msg?.role !== "assistant" || !Array.isArray(msg?.content)) return false; + return msg.content.some( + (block: any) => block?.type === "tool_use" && MEMORY_WRITE_TOOLS.has(block.name), + ); + }); + if (agentUsedWriteTool) { + api.logger.info( + "openclaw-mem0: skipping auto-capture — agent already used memory tools this turn", + ); + return; + } + // --- Build capture payload synchronously (cheap), then fire-and-forget --- // Patterns indicating an assistant message contains a summary of