dsh-routing-forensics
bushizhanghan/dsh-routing-forensics
Forensic analysis of past model-routing decisions. Replays each session, classifies every turn's task complexity from its request shape (deterministic, no LLM), and reports two kinds of waste: an expensive model on cheap work (the difference is measurable), and a cheap model on expensive work that failed on its own merits — where every retry re-sends the whole context, so the downgrade cost more than the upgrade. Distinguishes provider-capacity retries (RATE_LIMIT/TIMEOUT/TRANSPORT) from model failures so it does not cry wolf. Derives routing rules from the evidence, priced against a built-in per-million table.
설치
dsh plugin --profile web add github:bushizhanghan/dsh-routing-forensicsREADME
dsh-routing-forensics — 模型路由浪费取证(DSH 插件)
每次模型调用都是一次路由决定。用贵模型改错别字,是浪费;用便宜模型写引擎,失败重试后更贵。 这个插件回放会话日志,把过去的每一次路由决定摊开算账。
安装
dsh plugin --profile desktop add @bushizhanghan/dsh-routing-forensics
重启 DSH 后生效。只读:从不修改会话日志。
Agent 工具
| 工具 | 作用 |
|---|---|
routing_audit | 审计单个会话:回放每轮,按任务复杂度分档,找过配/欠配 |
routing_sweep | 扫描全部会话,按浪费金额排序 |
routing_rules | 从证据产出可执行的路由规则 |
怎么判断复杂度(确定性,不调 LLM)
按请求形状打分,分数决定档位:
| 信号 | 权重 |
|---|---|
| 请求长度 >2000 / >400 / >60 字符 | +3 / +2 / +1 |
| 工具调用 ≥8 / ≥3 / ≥1 | +3 / +2 / +1 |
| 有文件写入 | +2 |
| 重试 ≥3 次 / 有重试 | +6 / +2 |
| 上下文峰值 >100k / >20k | +5 / +1 |
| 分数 | 档位 | 建议模型层 |
|---|---|---|
| 0 | trivial | cheap |
| 1-3 | simple | cheap |
| 4-5 | standard | standard |
| ≥6 | complex | premium |
上下文权重刻意压得很重:一个人只打了「继续」但带着 300k 上下文,那是真在干活,不是琐事。
两类浪费
| 规则 | 级别 | 抓什么 |
|---|---|---|
over-provision | ! warn | 便宜活用了贵模型——差额是可计算的浪费 |
under-provision-retried | ✗ error | 贵活用便宜模型且失败了(非容量类错误)——每次重试重发整个上下文,比直接升级更贵 |
under-provision-capacity-retry | · info | 便宜活干重活但失败原因是限流/超时——不是模型能力问题,换个更好的模型也会撞同一堵墙 |
这个区分很重要:把 RATE_LIMIT 算成"模型不行"会让工具天天喊狼来了。
设计取舍
- 参考价取该档第一个声明的模型,不是全局最便宜。按 input+output 之和挑"最便宜"在混合定价下是错的:glm (0.1/0.3) 之和低于 deepseek (0.14/0.28),但输出密集时 glm 更贵、输入密集时 deepseek 更贵。
- 金额是估算,不是账单。内置价目表按公开标价,明确标注
estimateNotice;不在表里的模型只计数不定价(unpricedSessions),不猜。 SERVER不算容量限制。它太泛,常常就是模型自己的失败;当成容量会让误路由藏在借口后面。只有RATE_LIMIT/TIMEOUT/TRANSPORT算。- 确定性:复杂度分级、浪费计算、规则推导全是纯函数,同一份日志永远同一结论。
开发
node --test test/ # 33 个单测 + 15 项集成测试
测试用真机上的会话日志做 fixture。
License
MIT