Jari Mustonen 02222b93c5
feat(memory): delegate system prompt section to active memory plugin
Add registerMemoryPromptSection to the plugin API so the active memory
plugin provides its own system prompt builder callback. The built-in
memory-core plugin registers the existing Memory Recall section via
this new API.

When no memory plugin is active (or a plugin does not register a
builder), the memory section is simply omitted from the system prompt.
This lets third-party memory plugins inject their own guidance at the
same position in the prompt.
2026-03-20 06:37:23 -07:00

59 lines
1.9 KiB
TypeScript

import type { MemoryPromptSectionBuilder } from "openclaw/plugin-sdk/memory-core";
import { definePluginEntry } from "openclaw/plugin-sdk/core";
const buildPromptSection: MemoryPromptSectionBuilder = ({ availableTools, citationsMode }) => {
if (!availableTools.has("memory_search") && !availableTools.has("memory_get")) {
return [];
}
const lines = [
"## Memory Recall",
"Before answering anything about prior work, decisions, dates, people, preferences, or todos: run memory_search on MEMORY.md + memory/*.md; then use memory_get to pull only the needed lines. If low confidence after search, say you checked.",
];
if (citationsMode === "off") {
lines.push(
"Citations are disabled: do not mention file paths or line numbers in replies unless the user explicitly asks.",
);
} else {
lines.push(
"Citations: include Source: <path#line> when it helps the user verify memory snippets.",
);
}
lines.push("");
return lines;
};
export default definePluginEntry({
id: "memory-core",
name: "Memory (Core)",
description: "File-backed memory search tools and CLI",
kind: "memory",
register(api) {
api.registerMemoryPromptSection(buildPromptSection);
api.registerTool(
(ctx) => {
const memorySearchTool = api.runtime.tools.createMemorySearchTool({
config: ctx.config,
agentSessionKey: ctx.sessionKey,
});
const memoryGetTool = api.runtime.tools.createMemoryGetTool({
config: ctx.config,
agentSessionKey: ctx.sessionKey,
});
if (!memorySearchTool || !memoryGetTool) {
return null;
}
return [memorySearchTool, memoryGetTool];
},
{ names: ["memory_search", "memory_get"] },
);
api.registerCli(
({ program }) => {
api.runtime.tools.registerMemoryCli(program);
},
{ commands: ["memory"] },
);
},
});