Skip to content

Feature: before_agent_start hook should support { skip: true } to prevent agent run #32704

@madsharksnow

Description

@madsharksnow

Problem

When building a group message monitoring plugin (e.g., risk signal detection), the plugin needs to:

  1. Receive all group messages (requireMention: false)
  2. Classify messages via external API (fire-and-forget)
  3. 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_sending cancel hook receives ctx.conversationId: undefined (deliver module does not pass it), so cancel never matches

Proposed Solution

Allow before_agent_start to return { skip: true } which would:

  1. Skip the agent run entirely (no LLM call, no session write)
  2. Return immediately with no output
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions