Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class SupermemoryClient {
metadata?: Record<string, string | number | boolean>,
customId?: string,
containerTag?: string,
entityContext?: string,
): Promise<{ id: string }> {
const cleaned = sanitizeContent(content)
const tag = containerTag ?? this.containerTag
Expand All @@ -78,6 +79,7 @@ export class SupermemoryClient {
containerTag: tag,
...(metadata && { metadata }),
...(customId && { customId }),
...(entityContext && { entityContext }),
})

log.debugResponse("add", { id: result.id })
Expand Down
17 changes: 15 additions & 2 deletions hooks/capture.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,7 +24,18 @@ export function buildCaptureHandler(
cfg: SupermemoryConfig,
getSessionKey: () => string | undefined,
) {
return async (event: Record<string, unknown>) => {
return async (
event: Record<string, unknown>,
ctx: Record<string, unknown>,
) => {
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) ||
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions hooks/recall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<supermemory-context>\n${intro}\n\n${sections.join("\n\n")}\n\n${disclaimer}\n</supermemory-context>`
}
Expand Down
3 changes: 3 additions & 0 deletions memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, "_")
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down