-
-
Notifications
You must be signed in to change notification settings - Fork 69.4k
Feature: before_agent_start hook should support { skip: true } to prevent agent run #32704
Description
Problem
When building a group message monitoring plugin (e.g., risk signal detection), the plugin needs to:
- Receive all group messages (requireMention: false)
- Classify messages via external API (fire-and-forget)
- NOT run the main agent for non-@bot messages
Currently, before_agent_start can only modify the agent run (systemPrompt, prependContext, modelOverride) but cannot skip it entirely. This causes:
- Wasted resources: Every group message triggers a full agent run just to output "NO_REPLY"
- Session bloat: Observe-only messages accumulate in session history (including large images)
- Error leakage: When session history contains >5MB images, the model API returns 400 errors that get sent back to the group as "Agent failed" messages
- Cancel hook unreliable:
message_sendingcancel hook receivesctx.conversationId: undefined(deliver module does not pass it), so cancel never matches
Proposed Solution
Allow before_agent_start to return { skip: true } which would:
- Skip the agent run entirely (no LLM call, no session write)
- Return immediately with no output
- Still allow the plugin to do its own processing (classification, logging) in the hook itself
export type PluginHookBeforeAgentStartResult = PluginHookBeforePromptBuildResult
& PluginHookBeforeModelResolveResult
& { skip?: boolean };Secondary Issue: message_sending ctx.conversationId
The runMessageSending call in deliver-*.js only passes { channelId, accountId } as ctx, missing conversationId. This makes it impossible for plugins to cancel outbound messages to specific conversations. The to field is available in the event but not in ctx.
Use Case
Group message monitoring for enterprise IM (Feishu/Lark, WeChat Work) where the bot needs to silently observe all messages for risk detection and coaching signals without responding or accumulating session state.
Environment
- OpenClaw 2026.3.1
- Feishu channel with 66+ monitored groups
- Custom signal-observer plugin