Skip to content

Feature Request: Pre-tool-call routing hook for model delegation #13225

Description

@duckshrug

Summary

Request a hook that fires BEFORE tool execution, with the ability to route the call to a different model/session based on task classification.

Use Case

Cost optimization via automatic delegation. Simple tasks (file reads, greps, status checks) should route to cheaper models (Haiku) while complex reasoning stays in Opus.

Current Limitation

The before_tool_call hook receives toolName and params but:

  1. Cannot see the model's preceding output (to check for CLASSIFY statements)
  2. Cannot redirect the call to a different session/model
  3. Can only block, not route

Requested Enhancement

Add to before_tool_call event:

{
  toolName: string;
  params: Record<string, unknown>;
  precedingModelOutput?: string;  // NEW: what the model said before the tool call
  redirect?: {                     // NEW: route to different session
    model?: string;
    sessionTarget?: 'isolated' | 'existing';
  };
}

Why This Matters

Behavioral approaches to delegation don't work for LLMs — we can't form habits. Each session starts fresh. Rules in files don't create procedural memory. The only reliable solution is architectural enforcement at the gateway level.

Attempted Workarounds

  • CLASSIFY statements before tool calls (behavioral, inconsistent)
  • Tool allowlist restrictions (breaks functionality when too aggressive)
  • Cron-based monitoring (visibility only, not prevention)
  • Manual [DELEGATE] audits (requires human attention)

Environment

OpenClaw 2026.2.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:needs-security-reviewClawSweeper marked this issue as needing security-sensitive review.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.enhancementNew feature or requestimpact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.impact:securitySecurity boundary, credential, authz, sandbox, or sensitive-data risk.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions