fix(openclaw-agent-memory): wire memory-host hooks for auto-recall (#279)#281
fix(openclaw-agent-memory): wire memory-host hooks for auto-recall (#279)#281MicScalise wants to merge 1 commit into
Conversation
…ateBJones-Projects#279) Closes NateBJones-Projects#279. The plugin registered seven OB1 tools but did not participate in the OpenClaw memory-host lifecycle, so agents only hit OB1 if they remembered to. As a result, recall-before / writeback- after happened only when the prompt or skill explicitly nudged it. Adds two additive memory hooks inside register(api): * registerMemoryPromptSupplement — auto-injects an OB1 discipline block into the system prompt every turn (recall-before / writeback-after, instruction-vs-evidence semantics, and the list of tools currently exposed to the agent). * registerMemoryCorpusSupplement — exposes OB1 as a searchable corpus so OpenClaw's native recall flow queries OB1 alongside whatever other corpora are active. Maps recall responses onto MemoryCorpusSearchResult and inspects single memories via MemoryCorpusGetResult, with provenanceLabel reflecting OB1's use_policy (instruction vs evidence). Both supplements are additive (per the SDK contract) so they coexist with the active exclusive memory plugin. Both no-op cleanly when OB1 is not configured (missing endpoint or workspaceId, missing access key, network failure) — never throws into the host. The hooks are called via (api as any).registerMemory* so the plugin stays compatible with older OpenClaw releases that may not have the methods on the typed surface yet; the typeof checks gate registration on availability. No new tooling, dependencies, or breaking changes. The seven existing tools are unchanged. dist/ is intentionally not committed — maintainers should run `npm run build` to regenerate it.
|
Thanks for the contribution. The implementation is solid — both hooks are gated with One housekeeping item: this PR updates For the maintainer: #281 is the additive-supplement approach to wiring OB1 into OpenClaw's memory lifecycle; #283 is the active-memory-slot approach. That direction choice, and merge ordering across the four-PR cluster (#278, #281, #283, #309), is flagged separately. Recommend maintainer review. — Alan (community reviewer; non-binding) |
Closes #279.
The problem
The
nbj-ob1-agent-memoryplugin registers seven OB1 tools (openbrain_recall,openbrain_writeback, …) and declareskind: "memory", but the runtimeregister(api)body never participates in the OpenClaw memory-host lifecycle. As a result agents only hit OB1 when something in the prompt, skill, or system message explicitly nudges them — recall-before / writeback-after never happens automatically.The fix
Adds two additive memory hooks inside
register(api):registerMemoryPromptSupplement— auto-injects an OB1 discipline block into the system prompt every turn. The block lists currently-loadedopenbrain_*tools, the recall-before / writeback-after workflow, and the instruction-vs-evidence reading rule for returned memories.registerMemoryCorpusSupplement— exposes OB1 as a searchable corpus so OpenClaw's native recall flow queries OB1 alongside whatever else is active.search()mapsrecallresponses ontoMemoryCorpusSearchResult;get()mapsinspectMemoryontoMemoryCorpusGetResult.provenanceLabelreflects OB1'suse_policy(instructionwhencan_use_as_instruction;evidencewhencan_use_as_evidence).Both are additive per the SDK contract, so they coexist with the active exclusive memory plugin. Both no-op cleanly when OB1 is unconfigured (missing
endpoint/workspaceId, unresolved access key, network failure) — never throws into the host.The hooks are called via
(api as any).registerMemory*and gated ontypeof === "function"so this stays compatible with older OpenClaw releases that may not have these methods on the typed surface yet.Why additive (not exclusive)
registerMemoryCapability(the exclusive memory-plugin surface) requires implementing a fullMemorySearchManagerruntime, takes the slot from any other memory plugin, and forces existing users of OpenClaw's built-in memory or another exclusive provider to migrate. The additive supplements give the same agent-visible auto-invocation with zero migration cost. If you want an exclusive variant later, the additive pieces are reusable inside it.Diff
integrations/openclaw-agent-memory/plugin/src/index.ts: +143 / -0 (one source file, no new dependencies, no new tooling).dist/index.jsis intentionally not in the diff — please runnpm run buildto regenerate.Test plan
cd integrations/openclaw-agent-memory/plugin && npm install --ignore-scripts --omit=peer && npm run build(esbuild succeeds, ~13kb bundle)endpoint,workspaceId,accessKey)openclaw --profile <p> agents run helloand inspect the system prompt — should contain the "## OB1 Agent Memory" sectionagent_memoriesfor new rows linked by the agent's task — should land via the corpus supplement during native recallendpointfrom the config and re-run — both hooks should no-op (no errors, no prompt section, no corpus search calls)Behaviour summary
[]/null, host unaffectedRelated
This sits alongside #280, which adds
integrations/hermes-agent-memory/— the Hermes-runtime equivalent. With both merged, OpenClaw agents and Hermes agents share one governed OB1 memory with auto-recall / auto-writeback parity on each side.