From 1d8004df74658fa0a1e98a35b8b105acd1f2f057 Mon Sep 17 00:00:00 2001 From: Prasanna721 Date: Tue, 17 Feb 2026 17:59:02 -0800 Subject: [PATCH] fix: add entity context for memory extraction and skip cron, exec providers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Improvements for openclaw-supermemory v2 - memory.ts — Added ENTITY_CONTEXT that tells Supermemory to only create memories from user messages, treat agent responses as context, and ignore noise like greetings/status updates - client.ts — Added entityContext parameter to addMemory() so it gets passed through to the Supermemory API - hooks/capture.ts — Skip capturing heartbeat, cron-event, and exec-event agent turns. Pass ENTITY_CONTEXT on every capture. Added logging to track what gets captured vs skipped - hooks/recall.ts — Tightened the memory injection prompt so the agent uses recalled memories silently and only surfaces them when the conversation naturally calls for it --- client.ts | 2 ++ hooks/capture.ts | 17 +++++++++++++++-- hooks/recall.ts | 4 ++-- memory.ts | 3 +++ package.json | 2 +- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/client.ts b/client.ts index df5cac2..269a3ac 100644 --- a/client.ts +++ b/client.ts @@ -62,6 +62,7 @@ export class SupermemoryClient { metadata?: Record, customId?: string, containerTag?: string, + entityContext?: string, ): Promise<{ id: string }> { const cleaned = sanitizeContent(content) const tag = containerTag ?? this.containerTag @@ -78,6 +79,7 @@ export class SupermemoryClient { containerTag: tag, ...(metadata && { metadata }), ...(customId && { customId }), + ...(entityContext && { entityContext }), }) log.debugResponse("add", { id: result.id }) diff --git a/hooks/capture.ts b/hooks/capture.ts index a0c63dc..4b73979 100644 --- a/hooks/capture.ts +++ b/hooks/capture.ts @@ -1,7 +1,7 @@ import type { SupermemoryClient } from "../client.ts" import type { SupermemoryConfig } from "../config.ts" import { log } from "../logger.ts" -import { buildDocumentId } from "../memory.ts" +import { buildDocumentId, ENTITY_CONTEXT } from "../memory.ts" function getLastTurn(messages: unknown[]): unknown[] { let lastUserIdx = -1 @@ -24,7 +24,18 @@ export function buildCaptureHandler( cfg: SupermemoryConfig, getSessionKey: () => string | undefined, ) { - return async (event: Record) => { + return async ( + event: Record, + ctx: Record, + ) => { + log.info( + `agent_end fired: provider="${ctx.messageProvider}" success=${event.success}`, + ) + const provider = ctx.messageProvider + if (provider === "exec-event" || provider === "cron-event") { + return + } + if ( !event.success || !Array.isArray(event.messages) || @@ -95,6 +106,8 @@ export function buildCaptureHandler( content, { source: "openclaw", timestamp: new Date().toISOString() }, customId, + undefined, + ENTITY_CONTEXT, ) } catch (err) { log.error("capture failed", err) diff --git a/hooks/recall.ts b/hooks/recall.ts index ddd2d4e..3f0fbc9 100644 --- a/hooks/recall.ts +++ b/hooks/recall.ts @@ -107,9 +107,9 @@ function formatContext( } const intro = - "The following is recalled context about the user. Reference it only when relevant to the conversation." + "The following is background context about the user from long-term memory. Use this context silently to inform your understanding — only reference it when the user's message is directly related to something in these memories." const disclaimer = - "Use these memories naturally when relevant — including indirect connections — but don't force them into every response or make assumptions beyond what's stated." + "Do not proactively bring up memories. Only use them when the conversation naturally calls for it." return `\n${intro}\n\n${sections.join("\n\n")}\n\n${disclaimer}\n` } diff --git a/memory.ts b/memory.ts index eace91d..a65c51c 100644 --- a/memory.ts +++ b/memory.ts @@ -16,6 +16,9 @@ export function detectCategory(text: string): MemoryCategory { return "other" } +export const ENTITY_CONTEXT = + "Messages are tagged with [role: user] and [role: assistant]. Only create memories from what the user actually said — their preferences, decisions, and important personal details. Agent (assistant) responses are just context, not facts to remember. Only remember things that will be useful later. Ignore noise like greetings or status updates." + export function buildDocumentId(sessionKey: string): string { const sanitized = sessionKey .replace(/[^a-zA-Z0-9_]/g, "_") diff --git a/package.json b/package.json index 2f25d11..0004e96 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@supermemory/openclaw-supermemory", - "version": "1.0.5", + "version": "2.0.0", "type": "module", "description": "OpenClaw Supermemory memory plugin", "license": "MIT",