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",