返回目录
模型与 MCP 插件

dsh-difficulty-router

1960697431/dsh-difficulty-router

Difficulty-aware + taste-aware model routing plugin for DeepSeek Harness (DSH): hard/ambiguous tasks → strong model, UI/design → taste model, easy work stays cheap. Provider-agnostic, safe-by-default, calibrated on real bake-offs. MIT.

Stars
0
Forks
0
Issues
0
更新
3 个月前

PROJECT TOPICS

项目标签

INSTALL REFERENCE

安装参考

未验证
dsh plugin --profile web add github:1960697431/dsh-difficulty-router

该命令指向仓库当前默认分支;尚无绑定当前 commit 的完整验证结果。

PROJECT README

README

dsh-difficulty-router

Difficulty-aware + taste-aware model routing for DeepSeek Harness (DSH).

Hooks the agent/request waterfall and, per request step, decides which model should actually serve it:

  • Hard / ambiguous tasks → escalate from your cheap default to a configured strong model.
  • UI / design tasks → route to a configured taste model (design quality matters more than a few cents).
  • Easy tasks → stay on the cheap default.

The goal: spend strong-model money only where it buys quality, and protect your codebase from the places where a weak model guesses wrong and creates cruft.

中文:难度 + 品味双通道的模型路由插件。困难/含糊任务升级到强模型,UI/设计 任务路由到有品味的模型,简单活留在便宜的默认模型上。只在真正需要质量的地方 花强模型的钱。

What it looks like

Same session, three requests — the router reads each step and routes it (logFile JSONL, one line per decision):

{"kind":"keep",        "model":"aliyun/deepseek-v4-flash", "score":1, "reason":"1+1=?"}            // easy → stays cheap
{"kind":"escalate",    "to":"aliyun/qwen3.8-max",  "score":5, "hits":["重构","契约","幂等"]}          // hard → strong
{"kind":"escalate-ui", "to":"aliyun/kimi-k3",       "score":1, "uiHits":["样式","配色","布局","动效"]} // UI → taste
{"kind":"keep",        "model":".../deepseek-v4-flash", "score":4, "hits":[]}                        // "安全加固…只改一个文件" → NOT hard, stays cheap

Every line is a real measured decision from a live session. Install it, run dryRun: true for a day, and watch what would have routed — then flip to false and let it work.


Why

A real bake-off on a production monorepo (backend security task + frontend redesign, hidden acceptance tests, token usage read from session logs) showed:

Task cheap model strong model
single-file security fix passed, ¥0.03 passed, ¥0.50
pricing-page redesign good, ¥0.04 slightly better, ¥0.78

Two lessons:

  1. Scary words ≠ hard tasks. A single-file security fix is easy even though it says "安全 / credential / forge". Real difficulty is scope (multi-file, cross-end, contract changes), concurrency correctness, ambiguity, and no test coverage. So the classifier never escalates on security-ish vocabulary alone.
  2. Naive "always use the strong model" is ~15× more expensive for the same quality. Routing keeps easy work cheap.

Install

From the DSH plugin market, or manually:

dsh plugin add dsh-difficulty-router
# or
dsh plugin add github:YOUR_USER/dsh-difficulty-router

Configure (required to enable routing)

By default every target is empty, so a fresh install is a log-only bystander —it records decisions but never switches any model. Set your targets in the profile cordis.patch.yml insert row:

# dsh-plugin-manager:managed:start
- insert:
    - id: dsh-difficulty-router
      name: 'dsh-difficulty-router'
      config:
        dryRun: false                 # true = observe only (recommended first)
        threshold: 4                  # difficulty score that triggers escalation
        strongProvider: openai        # difficulty-escalation target
        strongModel: gpt-5.2
        uiProvider: anthropic         # taste-lane target
        uiModel: claude-sonnet-5
        exemptRoutes: []              # never escalate from these (prefix/regex)
        weakRoutes: []                # empty = auto (see below)
        classifier:                   # optional v2 second opinion (default off)
          enabled: false
          model: ''
          baseUrl: ''                 # any OpenAI-compatible endpoint
          apiKeyEnv: ''               # env var name holding the API key
          timeoutMs: 1500
# dsh-plugin-manager:managed:end

Nothing here names a specific vendor — point the targets at whatever models your DSH profile has configured.

Config reference

key type default meaning
dryRun bool true log decisions without switching (start here)
threshold int 4 difficulty score (1–5) that escalates
strongProvider / strongModel str '' difficulty target; empty disables the lane
uiProvider / uiModel str '' taste target; empty disables the lane
uiAlwaysStrong bool true UI tasks always go to the taste model
exemptRoutes list [] provider/model prefixes/regex never escalated from
weakRoutes list [] explicit weak list; empty = auto
classifier.* obj on (host llm) v2 second opinion — defaults to asking the current request's own model via DSH's llm service; an external OpenAI-compatible endpoint can override
logFile str /tmp/difficulty-router.log JSONL decision log

How "weak" is decided

A request is eligible for escalation when its route is not one of the configured targets, not in exemptRoutes, and either matches weakRoutes or weakRoutes is empty (auto mode: anything left over is weak). Explicit strong-model requests are never downgraded.

Decision order (per step)

  1. Taste lane — task looks like UI/design (uiKeywords + a design verb, or ≥2 UI nouns) → taste model.
  2. Difficulty lane — score ≥ threshold and real evidence (true-hard signal, or a tool loop ≥6 steps deep) → strong model.
  3. Ambiguous lane — heuristic score 3 + host LLM available → the current request's own provider/model is asked (zero vendor config, no binding) for a second opinion; escalate only if it agrees. This is a real model judgment on top of the free heuristic — smarter than keywords alone, and it costs only the tokens of one tiny call (~¥0.002).

Escalated routes stick for the rest of the turn. Scary words alone and long context alone never escalate.

Classifier vocabulary (bilingual, config-replaceable)

  • TRUE-HARD (+2 each, the only escalation evidence): 重构/迁移/跨端/多文件/ 契约/架构/并发/事务/幂等/无测试/上线 · refactor/migrat/multi-file/contract/ openapi/architect/concurrency/idempoten/deploy/production
  • SCARY (+0.5 each, never escalates alone): 安全/凭据/密钥/权限/审计/加密 · security/credential/secret/permission/oauth/audit/encrypt
  • AMBIGUOUS (+2, escalates at score ≥3): 你来定/你看着办/优化一下/尽量 · you decide/up to you/improve/tune/polish
  • UI (taste lane): 界面/页面/组件/样式/视觉/布局/动效/配色 · landing page/ redesign/visual/layout/typography/palette/motion

All lists are overridable via config (trueHardKeywords, scaryKeywords, ambiguousKeywords, uiKeywords, uiVerbs).

Why model judgment on top of keywords

Keywords are free, instant, and testable — but they miss paraphrases and domain slang. So for the ambiguous middle (heuristic score 3), the router asks whatever model the current request is already using (via DSH's own llm service) for a one-line difficulty verdict. No extra provider, no API key, no vendor binding: users of OpenAI, Alibaba, local models, anything — the router uses what they already have. If the host llm service is unavailable, it falls back to the heuristic alone (safe).

Observe

Decisions are appended as JSONL to logFile:

tail -f /tmp/difficulty-router.log
# kinds: keep | escalate | escalate-ui | escalate-v2 | dry-run-* | keep-v2

Run dryRun: true for a day, watch what would escalate, then flip to false.

Develop

npm test        # node --test classifier.test.js router.test.js  (29 tests)

The decision core (decideStep) is pure and unit-tested; the plugin shell only wires the agent/request waterfall and session-feature reading.

Limitations

  • Heuristic keyword scoring, not semantics. Tune the keyword lists for your domain; the defaults are calibrated on web/backend product work.
  • Source changes require a DSH process restart to load (config changes apply live via HMR).

Contributing · 欢迎提需求

Found a task that routed wrong? Have a routing rule you need? Feature requests and tuning ideas are very welcome — this plugin got good because real mistakes were measured and fixed. Open an issue, or send a PR that tweaks the keyword lists / thresholds / lanes.

Ideas that would land well:

  • Better difficulty signals (e.g., file-scope detection, token-budget-aware escalation)
  • More keyword packs for other domains (data science, infra, mobile)
  • Per-agent / per-workspace routing rules
  • A dashboard to visualize routing decisions over time

欢迎提需求、提路由失误案例、或 PR 调整词表/阈值/通道。这个插件是靠真实 盲测数据校准出来的,你的反馈会让它更好用。

License

MIT

CLASSIFICATION EVIDENCE

分类依据

项目类型插件
功能分类模型与 MCP
规则置信度中

系统优先读取 GitHub Topics,再与站内分类词典和词根规则比对。当前命中: deepseek-harness。