openclaw - 💡(How to fix) Fix [Feature]: Plugin hook hard routing: forced automatic subagent delegation

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…

before_prompt_build hook can only inject soft rules (system context), cannot force AI to execute sessions_spawn. Plugin detects complex tasks but AI may ignore the routing suggestion and process in main session, wasting tokens.

Root Cause

before_prompt_build hook can only inject soft rules (system context), cannot force AI to execute sessions_spawn. Plugin detects complex tasks but AI may ignore the routing suggestion and process in main session, wasting tokens.

Fix Action

Fix / Workaround

Add a gateway-level routing API or config option that can force specific tasks to be delegated to subagent sessions without relying on AI compliance. Possible approaches:

  1. Hook-level sessions_spawn capability

  2. Config-based task routing rules (e.g., regex patterns → target agent)

  3. REST API endpoint for creating sub-sessions

  4. A dispatch_mode option in agent config ("auto" | "main" | "always_subagent")

  5. Prompt-based routing rules in AGENTS.md/HEARTBEAT.md (current workaround — unreliable, AI ignores soft rules)

  6. External orchestrator script monitoring tasks (complex, fragile)

  7. Separate bot instances for different task types (operational overhead)

Workaround: subsession-router plugin (v1.0.0) using LLM+regex classification to append routing suggestions via appendSystemContext. Works ~70% of the time but AI sometimes ignores the routing directive.

RAW_BUFFERClick to expand / collapse

Summary

before_prompt_build hook can only inject soft rules (system context), cannot force AI to execute sessions_spawn. Plugin detects complex tasks but AI may ignore the routing suggestion and process in main session, wasting tokens.

Problem to solve

OpenClaw plugins can detect task complexity (via LLM classification or regex heuristics), but the only mechanism to act on that detection is appendSystemContext — a soft rule that AI may ignore. There is no gateway-level API to force a task into a subagent session.

Proposed solution

Add a gateway-level routing API or config option that can force specific tasks to be delegated to subagent sessions without relying on AI compliance. Possible approaches:

  1. Hook-level sessions_spawn capability
  2. Config-based task routing rules (e.g., regex patterns → target agent)
  3. REST API endpoint for creating sub-sessions
  4. A dispatch_mode option in agent config ("auto" | "main" | "always_subagent")

Alternatives considered

  1. Prompt-based routing rules in AGENTS.md/HEARTBEAT.md (current workaround — unreliable, AI ignores soft rules)
  2. External orchestrator script monitoring tasks (complex, fragile)
  3. Separate bot instances for different task types (operational overhead)

Impact

All OpenClaw users running multi-agent setups who want automatic task delegation to reduce main session token usage and improve task isolation.

Evidence/examples

Workaround: subsession-router plugin (v1.0.0) using LLM+regex classification to append routing suggestions via appendSystemContext. Works ~70% of the time but AI sometimes ignores the routing directive.

OpenClaw version: 2026.4.21

Additional information

Must be backward-compatible with existing plugin API. Should not break current sessions_spawn behavior. Gateway-level config preferred over code changes.

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

openclaw - 💡(How to fix) Fix [Feature]: Plugin hook hard routing: forced automatic subagent delegation