cost-counterfactual
它能做什么
这项技能将你的实际 AI 支出与每项任务都使用同一模型等级时的花费进行比较。适合想知道自动选择模型是否值得的人。
适用场景
- ✓当你想知道自动选择模型是否真的为你省钱时。
- ✓当你怀疑路由器过于频繁地使用昂贵模型时。
- ✓当你想把支出与只用最便宜或能力最强的模型进行比较时。
技能链接
https://github.com/ruvnet/ruflo/blob/main/plugins/ruflo-cost-tracker/skills/cost-counterfactual/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“与始终使用一个模型相比,我自动选择模型的做法是否真的省了钱?”
每周 5 个新技能,1 分钟读完。
工作原理
这项技能按各等级的价格重新计算过去的令牌用量,再减去你的实际成本。结果为正表示路由节省了钱,为负表示花费更多。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Multi-baseline counterfactual cost analysis. Pairs with the existing observability surface:
cost-budget-check— "have we crossed a threshold?" (reactive)cost-projection— "when will we cross a threshold?" (predictive)cost-counterfactual— "is the routing earning its keep?" (comparative) ← this one
Algorithm
- Read all
session-*records from thecost-trackingnamespace. - Apply
--sincewindow filter (default all-time). - Sum tokens across
byModel[*]entries for each session. - For each requested baseline (default: all three):
counterfactualUsd = (input × tier.input + output × tier.output + cache_write × tier.cache_write + cache_read × tier.cache_read) / 1M
- Compute
savings = counterfactualUsd − actualUsd. - Emit per-baseline totals + savings % across the comparison set.
Smoke transcript (2 sessions: 50K haiku tokens + 50K sonnet tokens)
| Sessions considered | 2 |
| Total input tokens | 100,000 |
| Actual spend | $0.162500 |
| Baseline | Hypothetical | Actual | Savings | % |
| `always-haiku` | $0.025000 | $0.162500 | -$0.137500 | -550.00% |
| `always-sonnet` | $0.300000 | $0.162500 | +$0.137500 | 45.83% |
| `always-opus` | $1.500000 | $0.162500 | +$1.337500 | 89.17% |
How to read negative savings
A negative always-haiku result means the router chose more-expensive models than haiku on tasks haiku could have handled. That's an over-escalation signal:
- Maybe qualityBar is set too high
- Maybe the sonnet/opus session was warranted by complexity but the baseline doesn't know that
- Run
cost optimize(or inspect specific sessions viacost conversation) to investigate
Positive savings quantify the router's win against that baseline. The most informative number is usually always-sonnet — it's the standard "safe default" baseline most teams would pick if they didn't have routing.
When to use
- Quarterly cost review: "We saved $X vs always-Sonnet — here's the proof."
- CI gate:
cost counterfactual --format json | jq '.baselines[1].savingsPct > 30'— fail builds if routing isn't saving ≥30% vs sonnet baseline (workload-shift detector). - Routing-config validation: When introducing a new qualityBar or cost-ceiling, re-run counterfactual to confirm savings didn't regress.
Stationarity caveat
Like all counterfactual analyses, this assumes the same tokens at the same complexity would have produced the same outcome from the baseline model. That's an upper bound — the baseline might have failed and required retries, which the math doesn't capture. Treat the numbers as a quality-blind ceiling.
常见问题
负的节省量意味着什么?
这意味着路由花费的钱比基准情况更多。这往往说明有任务被分配给了比实际需要更强的模型。
比较的基准有哪些?
始终使用 haiku、始终使用 sonnet 和始终使用 opus,每种都有各自的价格表。
我能限制分析的时间段吗?
可以。since 设置可以把分析限制在最近的一段时间内,默认使用全部时间。
详情
作者的原始描述
Multi-baseline counterfactual cost analysis. Compares actual session spend to hypothetical always-haiku / always-sonnet / always-opus routing baselines. Answers "is the routing earning its keep?" Negative savings flag over-escalation; positive savings quantify the router's win.
repo: ruvnet/ruflo
热度
- GitHub 星标
- 81k
- 排名
- #1598
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
agent-adaptive-coordinator
81k帮你的智能体在工作量变化时拆分和重新平衡一组 AI 智能体,并选择适合任务的分工方式。
agent-agent
81k教你的智能体把一个大目标拆成有顺序的行动计划,并在情况变化时重新规划。
agent-agentic-payments
81k帮你的智能体管理 AI 购物的消费授权,包括消费上限、时间窗口、商户规则和签名审批。
agent-analyze-code-quality
81k帮你的智能体检查代码质量,找出代码异味、技术债务和重构建议,且不改动文件。