feat(plugins): add before_agent_reply hook (claiming pattern)#20067
feat(plugins): add before_agent_reply hook (claiming pattern)#20067jalehman merged 2 commits intoopenclaw:mainfrom
Conversation
|
Note: I opened this PR before noticing that CONTRIBUTING.md asks new features to start as a Discussion first — sorry about the wrong order! Retroactive discussion here: https://github.com/openclaw/openclaw/discussions/20069 |
01f2ad1 to
652027b
Compare
|
This pull request has been automatically marked as stale due to inactivity. |
6c6b075 to
e75a3e8
Compare
|
The Fix submitted in #31868 — once that merges, this PR's CI should go green. |
0a2459c to
a9463af
Compare
a9463af to
99b6039
Compare
|
+1 — this is the most complete solution for local model routing. I have a working |
99b6039 to
f366b64
Compare
21022e8 to
acdc8d9
Compare
|
We run 26 agents on OpenClaw in production. This is the hook we need most. Without it we can not do slash command acknowledgments (instant reply, skip the LLM), multi-agent routing (forward to a different session without burning tokens), or approval gates (hold a message for human sign-off before the LLM touches it). The stale label is misleading. The feature gap is real, the code is clean, CI is green. Would love to see a maintainer take another look. Happy to help test against our fleet. |
27c28ac to
a6d6255
Compare
a6d6255 to
0f43aaa
Compare
c5afa58 to
2ab4581
Compare
c090a5f to
f77eca1
Compare
28a08f9 to
726dc48
Compare
Co-Authored-By: Claude Opus 4.6 <[email protected]>
a275528 to
e40dfbd
Compare
|
Merged via squash.
Thanks @JoshuaLelon! |
…aw#20067) Merged via squash. Prepared head SHA: e40dfbd Co-authored-by: JoshuaLelon <[email protected]> Co-authored-by: jalehman <[email protected]> Reviewed-by: @jalehman
…aw#20067) Merged via squash. Prepared head SHA: e40dfbd Co-authored-by: JoshuaLelon <[email protected]> Co-authored-by: jalehman <[email protected]> Reviewed-by: @jalehman
Summary
before_agent_replyplugin hook that fires after slash commands but before the LLM agent runs{ handled: true, reply }to short-circuit agent processing (forms, wizards, approval gates, etc. as plugins without touching core)runClaimingHookpattern (sequential by priority, first{ handled: true }wins) — same pattern asinbound_claimPluginHookAgentContextincludingtrigger,channelId,messageProviderMotivation
Per VISION.md, core stays lean and optional capability should ship as plugins. Right now there's no way for a plugin to intercept an inbound message and return a synthetic reply before the LLM runs — anything that needs pre-LLM interception has to modify core. This hook fills that gap.
Closes #8807.
Design
Hook name:
before_agent_replyWhen it fires: After
handleInlineActionsreturnskind: "continue", beforestageSandboxMedia/runPreparedReply. This means/helpand other slash commands still work normally, even during a plugin dialog.Event type:
Result type (claiming pattern):
Context: Full
PluginHookAgentContext(agentId,sessionKey,sessionId,workspaceDir,messageProvider,trigger,channelId).Execution:
runClaimingHook— async, sequential by priority (highest first). First handler to return{ handled: true }wins; remaining handlers are not called. Whenhandled: truewithoutreply, the message is swallowed viaSILENT_REPLY_TOKEN.Changes
src/plugins/types.tshandled: boolean), handler map entrysrc/plugins/hooks.tsrunBeforeAgentReplyusingrunClaimingHook, imports, re-exportssrc/auto-reply/reply/get-reply.tssrc/plugins/hooks.before-agent-reply.test.tsTest plan
pnpm test -- src/plugins/hooks.before-agent-reply.test.ts— all 8 tests passpnpm test -- src/plugins/hooks— all 27 existing hook tests unaffectedpnpm test -- src/auto-reply/reply/get-reply— existing get-reply tests passpnpm oxlint/pnpm format— cleanpnpm tsgo— no new type errors (pre-existing upstream errors only)git diff upstream/main --stat— exactly 4 files, no unrelated changes, no deletions ofinbound_claimcode