openclaw - 💡(How to fix) Fix feat: keyword-based message routing for pre-turn model selection [1 participants]

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…
GitHub stats
openclaw/openclaw#62152Fetched 2026-04-08 03:08:20
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

Add a zero-cost pre-turn model routing mechanism that selects the LLM based on keyword/pattern matching in the incoming message, before any LLM call is made.

Root Cause

Add a zero-cost pre-turn model routing mechanism that selects the LLM based on keyword/pattern matching in the incoming message, before any LLM call is made.

Code Example

{
  agents: {
    defaults: {
      model: {
        primary: "vllm/qwen35",
        tasks: {
          messageRouting: {
            rules: [
              { match: ["code review", "PR", "diff", "refactor"], model: "github-copilot/claude-sonnet-4.6" },
              { match: ["research", "search", "find"], model: "google-gemini-cli/gemini-3-flash-preview" },
              { match: ["patent", "legal", "prior art"], model: "anthropic/claude-opus-4-6" },
            ],
            default: "vllm/qwen35",
          },
        },
      },
    },
  },
}
RAW_BUFFERClick to expand / collapse

Summary

Add a zero-cost pre-turn model routing mechanism that selects the LLM based on keyword/pattern matching in the incoming message, before any LLM call is made.

Motivation

Different tasks benefit from different models:

  • Code review / PRs → high-capability coding model (e.g. claude-sonnet)
  • Research / web search → large context model (e.g. gemini-flash)
  • Quick Q&A / config → fast local model (e.g. qwen35)
  • Legal / patent → high-reasoning model (e.g. opus)

Currently switching models requires a manual /model command. This feature enables automatic routing based on message content with zero additional cost.

Proposed Design

Extend the existing model.tasks infrastructure with a new messageRouting config:

{
  agents: {
    defaults: {
      model: {
        primary: "vllm/qwen35",
        tasks: {
          messageRouting: {
            rules: [
              { match: ["code review", "PR", "diff", "refactor"], model: "github-copilot/claude-sonnet-4.6" },
              { match: ["research", "search", "find"], model: "google-gemini-cli/gemini-3-flash-preview" },
              { match: ["patent", "legal", "prior art"], model: "anthropic/claude-opus-4-6" },
            ],
            default: "vllm/qwen35",
          },
        },
      },
    },
  },
}
  • First-match-wins rule ordering
  • Case-insensitive substring matching
  • Zero LLM cost (pure string matching, no classification call)
  • Falls back to agent primary model if no rule matches
  • Configurable per-agent or at defaults level
  • Supports model aliases and full provider/model strings
  • Can also be specified in AGENTS.md for documentation/awareness

Implementation (prototype in fork)

A working implementation is in PR (see below) with:

  • resolveMessageRoutingModel(cfg, agentId, messageText) in agent-scope.ts
  • MessageRoutingRule, MessageRoutingConfig types in types.agents-shared.ts
  • 5 unit tests (all passing)

extent analysis

TL;DR

Implement a messageRouting config in the model.tasks infrastructure to enable automatic routing of incoming messages to different LLMs based on keyword/pattern matching.

Guidance

  • Review the proposed messageRouting config and adjust the rules to fit your specific use case, considering the types of tasks and corresponding LLMs.
  • Test the implementation using the provided unit tests and verify that the correct LLM is selected for different message scenarios.
  • Consider adding more rules or adjusting the existing ones to handle edge cases or specific requirements.
  • Evaluate the performance of the implementation, ensuring that the zero-cost routing mechanism does not introduce any significant overhead.

Example

{
  agents: {
    defaults: {
      model: {
        primary: "vllm/qwen35",
        tasks: {
          messageRouting: {
            rules: [
              { match: ["code review", "PR", "diff", "refactor"], model: "github-copilot/claude-sonnet-4.6" },
              // Add or modify rules as needed
            ],
            default: "vllm/qwen35",
          },
        },
      },
    },
  },
}

Notes

The implementation is still in a prototype phase, and further testing and refinement may be necessary to ensure its stability and effectiveness.

Recommendation

Apply the proposed messageRouting config and test the implementation to enable automatic routing of incoming messages to different LLMs based on keyword/pattern matching, allowing for more efficient and task-specific model selection.

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