openclaw - 💡(How to fix) Fix feat(gateway): add inboundContextHook for per-channel/per-agent context injection or rejection before LLM dispatch

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Fix Action

Fix / Workaround

  • Customer-group inbound message routed to a PM agent without the "customer's contract / owner" context → PM has to ping the architect agent for it
  • Same task ID collides across two agents' workspaces (e.g. our internal D-331); we need to rewrite/redirect before dispatch

Current workaround: each agent's system prompt says "always check X first". But agents forget under context pressure or compact triggers.

  • Embed guard rules in each agent's system prompt → context bloat, easily forgotten
  • Build a separate proxy in front of the Feishu/Slack webhook → reinvents gateway dispatch

Code Example

{
  "inboundContextHook": {
    "command": "/path/to/hook.sh",
    "timeoutMs": 5000,
    "input": {
      "channel": "...",
      "agent": "...",
      "message": "...",
      "senderId": "...",
      "chatId": "..."
    },
    "expectOutput": {
      "action": "pass | inject | reject",
      "injectSystem": "string?",      // prepended to system prompt this turn
      "injectUserPrefix": "string?",  // prepended to inbound message body
      "rejectReason": "string?"       // logged + optional auto-reply
    }
  }
}
RAW_BUFFERClick to expand / collapse

Motivation

We run 11+ agents on OpenClaw (COROS SEA deployment, see DARGO workspace). We repeatedly hit "trigger fires but agent context is incomplete" failures:

  • Customer-group inbound message routed to a PM agent without the "customer's contract / owner" context → PM has to ping the architect agent for it
  • Same task ID collides across two agents' workspaces (e.g. our internal D-331); we need to rewrite/redirect before dispatch

Current workaround: each agent's system prompt says "always check X first". But agents forget under context pressure or compact triggers.

Proposal

Add an optional hook in plugins.entries.gateway:

{
  "inboundContextHook": {
    "command": "/path/to/hook.sh",
    "timeoutMs": 5000,
    "input": {
      "channel": "...",
      "agent": "...",
      "message": "...",
      "senderId": "...",
      "chatId": "..."
    },
    "expectOutput": {
      "action": "pass | inject | reject",
      "injectSystem": "string?",      // prepended to system prompt this turn
      "injectUserPrefix": "string?",  // prepended to inbound message body
      "rejectReason": "string?"       // logged + optional auto-reply
    }
  }
}

Hook returns reject → message does not enter the LLM; gateway logs to inbound-rejected.log.

Use cases

  • Customer-group inbound → hook queries our CRM, returns injectSystem: "Customer owner=ZhangSan, contract=..."
  • Task ID collision → hook returns injectUserPrefix: "[Notice: D-331 already exists in this agent; confirm new vs. existing]"
  • Cheap per-message context enrichment that does not consume the agent's system-prompt budget

Alternatives considered

  • Embed guard rules in each agent's system prompt → context bloat, easily forgotten
  • Build a separate proxy in front of the Feishu/Slack webhook → reinvents gateway dispatch

Risks

  • Adds ≤ 5 s serial latency; needs timeout fallback
  • Hook failure must default to pass (do not block the main path)

Origin

Draft from workspace-dargo/state/openclaw-fr.md. Filed by the DARGO system architect agent on behalf of @90yuwang.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING