Design & media

Smart Router Publish

Try it

Use when switching models, saving costs, or routing queries. Automatically picks the cheapest model that can handle the job — "translate hello" routes to $0/...

What it does

Use when switching models, saving costs, or routing queries. Automatically picks the cheapest model that can handle the job — "translate hello" routes to $0/M local, "design a database" routes to $3/M pro. 100% local classification, zero API calls for routing.

The skill document

Smart Router

Overview

"Translate hello to German"       → local   $0/M tok
"Explain how DNS works"           → flash   $0.15/M tok  (GPT-4o-mini)
"Design a distributed database"   → pro     $3/M tok  (Claude Sonnet)

Smart Router classifies every query locally (Ollama embeddings + semantic-router) and picks the cheapest tier that can handle it. Simple queries route to free local models. Complex reasoning routes to frontier models. You pay for what you need — not what your config happens to be set to.

Classification runs entirely on your machine. Zero API calls for routing decisions. Zero keys needed. ~3s on first call, <1ms after.

When to Use

Load this skill when:

  • The user is toggling between models manually (wasting tokens on simple queries)
  • The user asks about cost saving, model switching, or routing
  • The user mentions /model, /tier, or switches models mid-session
  • The agent is about to answer a complex question and should verify the current tier

Do NOT load for: greetings, one-liners, translations, queries under 20 characters.

CRITICAL — Agent Instructions

Call router.resolve() before answering any non-trivial query.

from smart_router.router import get_router

router = get_router()
decision = router.resolve(user_message, current_tier=ACTIVE_TIER)
# → {"tier": "pro", "model": {...}, "needs_switch": true,
#    "reason": "Upgrade from flash to pro — Complex code...",
#    "recommendation": "💡 Switch to pro: `/model anthropic claude-sonnet-4` — ..."}

If decision["recommendation"] is not None, paste it at the top of your response — it's ready to use, no formatting needed.

If decision["recommendation"] is None, just answer normally. If the call errors or times out, skip it and answer — never retry.

ACTIVE_TIER is your current tier (local/flash/pro). Check with /tier or ask.

When to Skip

Skip routing for: greetings ("hello", "thanks"), translations, one-liner facts, queries under 20 characters. Everything else — route.

When to Route

  • Complex: 3+ tool calls, reasoning, architecture, multi-step code, debugging → route
  • Unsure: If it takes more than a sentence to answer → route
  • Default: If in doubt, route. Routing cost (~3s first call, <1ms after) is always less than answering from the wrong tier.

Tier Reference

TierExample ModelInput Price/1M tokUse When
localOllama (llama3, qwen, etc.)$0Simple Q&A, translations, offline
flashGPT-4o-mini, Gemini Flash, Claude Haiku~$0.15–0.80General knowledge, casual coding
proClaude Sonnet, GPT-4o, Gemini Pro~$2.50–3Complex reasoning, architecture

Pricing per official API pages (OpenAI, Anthropic, Google). See individual provider docs for exact rates. Per-token pricing means a single 1K-token question costs $0.003 on flash vs $0.003 on pro — but over thousands of queries per month, the difference compounds.

Prerequisites

  • Hermes Agent v0.17+
  • Ollama installed
  • semantic-router[ollama] and smart_router

Configuration

smart_router:
  enabled: true
  default_tier: flash
  encoder_model: nomic-embed-text
  tiers:
    local:
      provider: custom
      model: llama3.2:3b
      base_url: http://localhost:11434/v1
    flash:
      provider: openai
      model: gpt-4o-mini
    pro:
      provider: anthropic
      model: claude-sonnet-4
  ollama:
    auto_start: true
    idle_timeout: 300

Slash Commands

CommandDescription
/route Show tier selection (dry run)
/route-statsSession routing statistics
/ollama start / stop / statusOllama lifecycle
/tierShow current tier and model

Common Pitfalls

  1. Agent forgets to call router.resolve(). The most common failure mode. If the agent answers without routing, manually trigger with /route .
  2. Ollama not running. If decision["ollama_ready"] is false, start Ollama first (/ollama start) or skip routing for this query.
  3. Slow first call. First router.resolve() pulls nomic-embed-text (~274MB). Subsequent calls are instant. Warm up with python3 -m smart_router route "test" before heavy sessions.
  4. Fast-path false negatives. Queries under 20 chars skip embedding. If a short query needs pro-level reasoning, the router won't catch it — use /model manually.

Testing

bash scripts/install.sh
python3 -m smart_router route "What is the capital of France?"
python3 -m smart_router chat
python3 -m pytest tests/

Related skills

智能模型路由与Token成本优化顾问 / Smart LLM Router & Token Cost Optimizer. 帮助用户为不同复杂度的AI任务选择最合适的模型层级(从极致性价比到旗舰级), 通过任务复杂度评估、模型分级推荐、安全强制升级规则,在保证质量的前提下节省70-90%的Token成本。 同时提...

Smart LLM Router for OpenClaw. Save up to 70% by routing every request to the right model. No coding required.

13 installs

Choose RouterBase model IDs and routing strategies for chat, image, video, audio, and embeddings workloads. Use when comparing providers, selecting GPT, Clau...

1 installs

Universal smart routing skill that chooses the best installed skill or skill chain across mixed environments, and automatically applies OpenClaw-aware routin...

15 installs

Quota-aware LLM router that squeezes maximum usable AI out of free-tier API keys across Gemini, Mistral, OpenRouter, Kilo and Cerebras plus any OpenAI-compatible endpoint (including local Ollama/llama.cpp/vLLM). Probes every model on every key, measures real quality and real published rate limits, then routes each request to the cheapest model that can do the job — spending abundant capacity first and reserving scarce daily quota for when it is actually needed. Persists cooldowns to disk so a 429 discovered in one process is respected by the next. Use when an agent must make many LLM calls on free keys without hitting rate limits, when "all models failed", or when deciding which of several provider keys to use for a task.

2 installs