#Smart Model Router plugin for OpenClaw - automatically picks the best AI model

1 messages Β· Page 1 of 1 (latest)

trim sigil
#

A plugin for OpenClaw that automatically picks the best AI model for each conversation turn. Instead of manually switching between models, the router analyzes your prompt and routes it to the right model based on what you're asking. This doesn't use a cloud LLM for decision making and there is no cost associated with the decision. The plugin uses a local embedding model (you can provide example phrases to extend) and smart hueristics and scoring.

What it does (these are all confiugarable and customizable - can be any LLM local or cloud)
Coding questions go to Claude Sonnet 4.6 (strong at code generation and debugging)
Deep reasoning tasks go to Gemini 2.5 Pro (strong at analysis and multi-step logic)
Simple questions go to Gemini 2.5 Flash (fast, cheap, good enough for quick answers)
Creative writing goes to Claude Sonnet 4.6 (strong at prose, emails, blog posts)
The routing happens automatically on every turn. You can also force a specific route with slash commands like /coding, /reason, /simple, /creative, /action, /best, or /cheap (~ in telegram).

git https://github.com/alexspin/Model-Selection-Optimizer.git
npm: https://www.npmjs.com/package/model-selection-optimizer
maintainer: https://github.com/alexspin

#

Smart Model Router plugin for OpenClaw - automatically picks the best AI model for

#

Smart Model Router plugin for OpenClaw - automatically picks the best AI model

hexed stratus
#

installing.

hexed stratus
#

where can i send fail log?

#

Bug Report: model-selection-optimizer npm install failure

Package
model-selection-optimizer@1.0.2
Date
2026-03-15 (attempted 20:00-00:15 EDT)
Severity
Blocker β€” plugin cannot be installed

Environment
Hardware: Microsoft Surface Laptop 7 for Business
CPU: Intel Core Ultra 5 (Lunar Lake)
GPU: Intel Arc 130V (Xe-LPG), 11.5GB VRAM
RAM: 16 GB
OS: Fedora 43 (kernel 6.18.8-1.surface.fc43.x86_64)
Node.js
v22.22.0
npm
10.9.4
OpenClaw
v2026.3.13 (installed globally via npm)
Network
AT&T 1000/1000 fiber (intermittently slow on some services)

Steps to reproduce

  1. Install via OpenClaw plugin manager:
    openclaw plugins install model-selection-optimizer
    Plugin manifest detects id as "smart-router". Warns about child_process usage (expected). Begins "Installing plugin dependencies" and hangs indefinitely.

  2. Manual extraction + targeted install:
    cd /tmp && npm pack model-selection-optimizer
    tar -xzf model-selection-optimizer-*.tgz
    mv package ~/.openclaw/extensions/smart-router
    cd ~/.openclaw/extensions/smart-router
    npm install --ignore-scripts
    Hangs indefinitely. Verbose output shows npm resolving the full openclaw dependency tree (hundreds of packages) because openclaw is listed as a direct dependency in package.json.

  3. Attempted with stripped dependencies (removed openclaw, @huggingface/transformers, tsx, typescript, @types/node β€” kept only tiktoken and zod):
    npm install --ignore-scripts tiktoken zod
    Also hangs. npm verbose shows it still resolves cached openclaw tree.

  4. Clean node_modules + retry:
    rm -rf node_modules package-lock.json
    npm install --ignore-scripts
    ENOTEMPTY error followed by hang:
    npm error ENOTEMPTY: directory not empty, rename .../tiktoken

  5. Tried with timeout:
    timeout 30 npm install --ignore-scripts --registry https://registry.npmjs.org
    Times out after 30s with partial install of tiktoken and zod only.

#

Root cause analysis
The package.json lists "openclaw": "^2026.3.2" as a direct dependency. This is the full OpenClaw package (~250+ transitive dependencies including native modules like node-llama-cpp, sharp, onnxruntime-node). Even with --ignore-scripts, npm must resolve and download the entire tree, which:
Takes 10+ minutes on slow connections
Frequently hangs during resolution (npm 10.x known issue with large trees)
Is unnecessary β€” openclaw is already installed globally and the plugin runs inside the gateway process
@huggingface/transformers adds another large tree (ONNX runtime) that may also fail on Node 22
Suggested fix
Move openclaw and @huggingface/transformers to peerDependencies (or optionalDependencies):
"peerDependencies": {
"openclaw": ">=2026.3.0"
},
"optionalDependencies": {
"@huggingface/transformers": "^3.8.1"
},
"dependencies": {
"tiktoken": "^1.0.22",
"zod": "^4.3.6"
}
This reduces the install footprint from ~250+ packages to ~10, and lets the plugin find openclaw from the global install at runtime. The semantic classifier should gracefully fall back to heuristic-only mode when @huggingface/transformers is unavailable.
Workaround attempted
Manually editing package.json to strip heavy deps, then npm install. This also hangs because npm caches the original resolved tree and re-resolves it. Deleting node_modules and package-lock.json results in ENOTEMPTY errors from corrupted partial installs.
Additional notes
The same node-llama-cpp / native module issue affects OpenClaw's built-in memory embeddings on Node 22 (we switched to Gemini remote embeddings as a workaround). Any plugin depending on native Node modules should document Node 24 as a requirement or provide a fallback path.

warm hemlock
#

A sincere question. Why would i use this instead of openrouter which has a similar capability?

hexed stratus
#

You save on tokens like 95% as claimed by dev and AI which analyzed the code. Faster routing, more control and flexibility. If you'll make it work. I could not, yet.

hexed stratus
#

Installed and working now. Not sure what was wrong as we messed with it heavily with Claude Opus. Had to write my own custom rules best for my use case and hardware. If anyone really interested I can ask Claude to write change log.

warm hemlock
hexed stratus
#

Ok.

trim sigil
#

You’d use this if you want full control within your app at zero cost. This is especially useful if you wanted to host your own models (eg run a local LLM in your app often). Venice and OpenRouter have similar capabilities, then you’re using them all the time. But those are good options. This doesn’t negate them.

trim sigil
trim sigil
hexed stratus
#

Is this true that smart-router only have primary and a single fail-over?

#

I am afraid my Opus made so many modifications already it may be not what you wrote originally or I may be wrong of course, but config file definitely modified heavily. I now have like 10 different classes to route to different models local and cloud. Perhaps overcomplicating it I realize.

trim sigil
#

Yes, it uses a primary and a fallback. If you tell me more about wha you are trying to do maybe I can help.

hexed stratus
#
Class Model1 Model1 Cost (est. $/M input) Failover Model2 Model2 Cost (est. $/M input) Input Ctx
simple openrouter/x-ai/grok-4.1-fast ~$0.30–$0.60* openrouter/google/gemini-3-flash-preview ~$0.075–$0.15* text+image 1953k
coding openrouter/x-ai/grok-4.1-fast ~$0.30–$0.60* openrouter/google/gemini-3-flash-preview ~$0.075–$0.15* text+image 1953k
action openrouter/x-ai/grok-4.1-fast ~$0.30–$0.60* openrouter/google/gemini-3-flash-preview ~$0.075–$0.15* text+image 1953k
reasoning openrouter/x-ai/grok-4.1-fast ~$0.30–$0.60* openrouter/anthropic/claude-sonnet-4.6 ~$3.00* text 977k
creative openrouter/x-ai/grok-4.1-fast ~$0.30–$0.60* openrouter/google/gemini-3-flash-preview ~$0.075–$0.15* text+image 1953k
heavy-review openrouter/x-ai/grok-4.1-fast ~$0.30–$0.60* openrouter/anthropic/claude-sonnet-4.6 ~$3.00* text 977k
planning openrouter/x-ai/grok-4.1-fast ~$0.30–$0.60* openrouter/google/gemini-3-flash-preview ~$0.075–$0.15* text+image 1953k
vision openrouter/x-ai/grok-4.1-fast ~$0.30–$0.60* openrouter/google/gemini-3-flash-preview ~$0.075–$0.15* text+image 1953k
triage openrouter/x-ai/grok-4.1-fast ~$0.30–$0.60* openrouter/google/gemini-3-flash-preview ~$0.075–$0.15* text+image 1953k
#

| private | qwen3.5:9b | $0.0–$0.0 | SPARK rented (via tailscale) $0.0 | text+image | ~977k |

Example only. Claw actually messed it up (apparently) and it does not show what I setup earlier. πŸ™ Model 2 should be a primary to begin with. And... yeah this is just wrong. I'll post final version later.

hexed stratus
#

here is the real, fixed ver:
simple : primary=openai-codex/gpt-5.4 fallback=openrouter/x-ai/grok-4.1-fast
coding : primary=openai-codex/gpt-5.4 fallback=openrouter/x-ai/grok-code-fast-1
action : primary=openai-codex/gpt-5.4 fallback=openrouter/x-ai/grok-4.1-fast
reasoning : primary=openai-codex/gpt-5.4 fallback=openrouter/google/gemini-3.1-pro-preview
creative : primary=openrouter/x-ai/grok-4.20-beta fallback=openrouter/google/gemini-3.1-pro-preview
heavy-review : primary=openai-codex/gpt-5.4 fallback=openrouter/anthropic/claude-sonnet-4.6
planning : primary=openai-codex/gpt-5.4 fallback=openrouter/anthropic/claude-sonnet-4.6
vision : primary=ollama/qwen3.5:9b fallback=openrouter/google/gemini-3.1-flash-light-preview
triage : primary=ollama/deepseek-r1:7b fallback=ollama/qwen3.5:9b
private : primary=ollama/qwen3.5:9b fallback=openrouter/anthropic/claude-sonnet-4.6
premium-final : primary=openai-codex/gpt-5.4 fallback=openrouter/google/gemini-3.1-pro-preview
DEFAULTS: {'fallback': 'openrouter/x-ai/grok-4.1-fast', 'mode': 'balanced', 'model': 'openai-codex/gpt-5.4'}

hexed stratus
#

TBH, I am not 100% happy with how it works. Regardless of how many classes I have or changing weights, when making my gpt5.4 codex primary I end up on failover which is openrouter and some. One month and $78 (112 mill tokens) later I have disabled smart-router to find what is wrong and if this is for me at all.