Skip to content

feat: keyword-based message routing for pre-turn model selection #1682

@scottgl9

Description

@scottgl9

Summary

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

Motivation

Different tasks benefit from different models (coding → claude-sonnet, research → gemini-flash, quick Q&A → qwen35). Currently requires manual model switching.

Proposed Design

messageRouting: {
  rules: [
    { match: ["code review", "PR"], model: "github-copilot/claude-sonnet-4.6" },
    { match: ["research", "search"], model: "gemini-3-flash" },
  ],
  default: "qwen35",
}
  • First-match-wins rule ordering
  • Case-insensitive substring matching
  • Zero LLM cost — pure string matching
  • Falls back to primary model if no rule matches

Implementation

Prototype: scottgl9/nanoclaw feature/message-routing-20260406

  • src/message-routing.ts — types + resolveMessageRoutingModel()
  • src/message-routing.test.ts — 6 tests passing
  • src/types.ts — messageRouting field added
  • src/index.ts — wired into agent dispatch

Also implemented in openclaw/openclaw#62153 and scottgl9/leanclaw#7.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions