Skip to content

fix(openclaw-agent-memory): wire memory-host hooks for auto-recall (#279)#281

Open
MicScalise wants to merge 1 commit into
NateBJones-Projects:mainfrom
MicScalise:fix-279-openclaw-memory-host-hooks
Open

fix(openclaw-agent-memory): wire memory-host hooks for auto-recall (#279)#281
MicScalise wants to merge 1 commit into
NateBJones-Projects:mainfrom
MicScalise:fix-279-openclaw-memory-host-hooks

Conversation

@MicScalise
Copy link
Copy Markdown

Closes #279.

The problem

The nbj-ob1-agent-memory plugin registers seven OB1 tools (openbrain_recall, openbrain_writeback, …) and declares kind: "memory", but the runtime register(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):

  1. registerMemoryPromptSupplement — auto-injects an OB1 discipline block into the system prompt every turn. The block lists currently-loaded openbrain_* tools, the recall-before / writeback-after workflow, and the instruction-vs-evidence reading rule for returned memories.
  2. registerMemoryCorpusSupplement — exposes OB1 as a searchable corpus so OpenClaw's native recall flow queries OB1 alongside whatever else is active. search() maps recall responses onto MemoryCorpusSearchResult; get() maps inspectMemory onto MemoryCorpusGetResult. provenanceLabel reflects OB1's use_policy (instruction when can_use_as_instruction; evidence when can_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 on typeof === "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 full MemorySearchManager runtime, 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.js is intentionally not in the diff — please run npm run build to regenerate.

Test plan

  • cd integrations/openclaw-agent-memory/plugin && npm install --ignore-scripts --omit=peer && npm run build (esbuild succeeds, ~13kb bundle)
  • Install plugin into an OpenClaw profile with valid OB1 config (endpoint, workspaceId, accessKey)
  • openclaw --profile <p> agents run hello and inspect the system prompt — should contain the "## OB1 Agent Memory" section
  • Drive a turn that doesn't explicitly mention OB1, then check agent_memories for new rows linked by the agent's task — should land via the corpus supplement during native recall
  • Remove endpoint from the config and re-run — both hooks should no-op (no errors, no prompt section, no corpus search calls)

Behaviour summary

Case Before After
Configured plugin, agent with no OB1 prompting tools registered but unused prompt section + corpus supplement → auto-recall on every turn
Unconfigured plugin tools registered but throw on call tools still throw on call; supplements no-op silently
Network down or 5xx from API tool calls bubble error to agent tool calls bubble error; supplements return [] / null, host unaffected
Tools not loaded for the agent prompt section absent (no nudge) prompt section gated to only show currently-available tools

Related

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.

…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.
@alanshurafa
Copy link
Copy Markdown
Collaborator

Thanks for the contribution. The implementation is solid — both hooks are gated with typeof ... === "function" so older OpenClaw runtimes stay safe, isConfigured() makes them no-op when OB1 is not set up, and every network call in search() / get() is wrapped so a failing OB1 degrades to empty results instead of throwing into the host.

One housekeeping item: this PR updates src/index.ts but not the compiled dist/index.js, so a npm run build is needed for the change to take effect from the built plugin — worth regenerating dist in the PR, as a couple of the sibling PRs do.

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

alan-reviewed Reviewed by Alan Shurafa in Community Reviewer role area: integrations Review area: integrations/MCP/capture sources integration Contribution: MCP extension or capture source review: ready-for-maintainer Community reviewer recommends maintainer review

Projects

None yet

2 participants