Skip to content
Open
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
25 changes: 25 additions & 0 deletions commands/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,26 @@ export function registerCliSetup(api: OpenClawPluginApi): void {
console.log(" Invalid value, using default: all")
}

console.log("\nMemory usage display:")
console.log(
" true - Show how many memories were used in each response (recommended)",
)
console.log(
" false - Hide memory usage counts from responses",
)
const showMemoryUsageInput = await ask(
"Show memory usage (true/false) [true]: ",
)
let showMemoryUsage = true
if (showMemoryUsageInput.trim().toLowerCase() === "false") {
showMemoryUsage = false
} else if (
showMemoryUsageInput.trim() &&
showMemoryUsageInput.trim().toLowerCase() !== "true"
) {
console.log(" Invalid value, using default: true")
}

console.log("\nEntity context:")
console.log(
" Instructions that guide what memories are extracted from conversations.",
Expand Down Expand Up @@ -275,6 +295,7 @@ export function registerCliSetup(api: OpenClawPluginApi): void {
if (profileFrequency !== 50)
pluginConfig.profileFrequency = profileFrequency
if (captureMode !== "all") pluginConfig.captureMode = captureMode
if (!showMemoryUsage) pluginConfig.showMemoryUsage = false
if (entityContextInput.trim())
pluginConfig.entityContext = entityContextInput.trim()
if (enableCustomContainerTags)
Expand Down Expand Up @@ -311,6 +332,7 @@ export function registerCliSetup(api: OpenClawPluginApi): void {
console.log(` Max results: ${maxRecallResults}`)
console.log(` Profile freq: ${profileFrequency}`)
console.log(` Capture mode: ${captureMode}`)
console.log(` Memory usage: ${showMemoryUsage}`)
const entityPreview = entityContextInput.trim()
if (entityPreview) {
const truncated =
Expand Down Expand Up @@ -404,6 +426,9 @@ export function registerCliSetup(api: OpenClawPluginApi): void {
console.log(
` Capture mode: ${pluginConfig.captureMode ?? "all"}`,
)
console.log(
` Memory usage: ${pluginConfig.showMemoryUsage ?? true}`,
)
const entityCtx = pluginConfig.entityContext as string | undefined
if (entityCtx) {
const truncated =
Expand Down
25 changes: 25 additions & 0 deletions commands/slash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,31 @@ export function registerCommands(
cfg: SupermemoryConfig,
getSessionKey: () => string | undefined,
): void {
api.registerCommand({
name: "memory-usage",
description: "Toggle memory usage display on/off",
acceptsArgs: true,
requireAuth: false,
handler: async (ctx: { args?: string }) => {
const arg = ctx.args?.trim().toLowerCase()

if (arg === "on" || arg === "true" || arg === "enable") {
cfg.showMemoryUsage = true
return { text: "Memory usage display enabled. The model will now show how many memories were used." }
}

if (arg === "off" || arg === "false" || arg === "disable") {
cfg.showMemoryUsage = false
return { text: "Memory usage display disabled. The model will no longer show memory counts." }
}

// No arg or unrecognized: toggle
cfg.showMemoryUsage = !cfg.showMemoryUsage
const state = cfg.showMemoryUsage ? "enabled" : "disabled"
return { text: `Memory usage display ${state}. Use /memory-usage on|off to set explicitly.` }
},
})

api.registerCommand({
name: "remember",
description: "Save something to memory",
Expand Down
4 changes: 4 additions & 0 deletions config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type SupermemoryConfig = {
captureMode: CaptureMode
entityContext: string
debug: boolean
showMemoryUsage: boolean
enableCustomContainerTags: boolean
customContainers: CustomContainer[]
customContainerInstructions: string
Expand All @@ -33,6 +34,7 @@ const ALLOWED_KEYS = [
"captureMode",
"entityContext",
"debug",
"showMemoryUsage",
"enableCustomContainerTags",
"customContainers",
"customContainerInstructions",
Expand Down Expand Up @@ -125,6 +127,7 @@ export function parseConfig(raw: unknown): SupermemoryConfig {
? cfg.entityContext.trim()
: DEFAULT_ENTITY_CONTEXT,
debug: (cfg.debug as boolean) ?? false,
showMemoryUsage: (cfg.showMemoryUsage as boolean) ?? true,
enableCustomContainerTags:
(cfg.enableCustomContainerTags as boolean) ?? false,
customContainers,
Expand All @@ -149,6 +152,7 @@ export const supermemoryConfigSchema = {
captureMode: { type: "string", enum: ["all", "everything"] },
entityContext: { type: "string" },
debug: { type: "boolean" },
showMemoryUsage: { type: "boolean" },
enableCustomContainerTags: { type: "boolean" },
customContainers: {
type: "array",
Expand Down
11 changes: 10 additions & 1 deletion hooks/recall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function formatContext(
dynamicFacts: string[],
searchResults: ProfileSearchResult[],
maxResults: number,
showMemoryUsage = true,
): string | null {
const deduped = deduplicateMemories(staticFacts, dynamicFacts, searchResults)
const statics = deduped.static.slice(0, maxResults)
Expand All @@ -77,6 +78,8 @@ function formatContext(
if (statics.length === 0 && dynamics.length === 0 && search.length === 0)
return null

const totalMemories = statics.length + dynamics.length + search.length

const sections: string[] = []

if (statics.length > 0) {
Expand Down Expand Up @@ -111,7 +114,12 @@ function formatContext(
const disclaimer =
"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>`
let memoryUsageInstruction = ""
if (showMemoryUsage) {
memoryUsageInstruction = `\n\nIMPORTANT: At the very beginning of your response, include a brief note indicating how many memories from Supermemory were used to inform your response. Format it as: "[Supermemory: ${totalMemories} memories loaded]" — this helps the user understand that OpenClaw is using their long-term memory. If none of the memories are relevant to the current message, say "[Supermemory: ${totalMemories} memories loaded, 0 used]".`
}

return `<supermemory-context>\n${intro}\n\n${sections.join("\n\n")}\n\n${disclaimer}${memoryUsageInstruction}\n</supermemory-context>`
}

function countUserTurns(messages: unknown[]): number {
Expand Down Expand Up @@ -187,6 +195,7 @@ export function buildRecallHandler(
includeProfile ? profile.dynamic : [],
profile.searchResults,
cfg.maxRecallResults,
cfg.showMemoryUsage,
)

const containerContext = formatContainerMetadata(cfg, messageProvider)
Expand Down
Loading