cost-counterfactual
できること
このスキルは、実際のAI支出を、すべてのタスクに1つのモデル階層を使った場合の費用と比べます。自動のモデル選択に価値があるかを知りたい人向けです。
使う場面
- ✓モデルを自動で選ぶことで費用が節約できているかを知りたいとき。
- ✓ルーターが高価なモデルを使いすぎていると疑うとき。
- ✓最も安いモデルか、最も高性能なモデルだけを使った場合と、支出を比べたいとき。
スキルのリンク
https://github.com/ruvnet/ruflo/blob/main/plugins/ruflo-cost-tracker/skills/cost-counterfactual/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“自動でモデルを選ぶ仕組みは、1つのモデルを常に使う場合と比べて、実際に費用を節約していますか?”
毎週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 の3つで、それぞれ独自の価格表を使います。
期間を限定できますか?
はい。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作業量の変化に合わせて、エージェントのグループを分割し、再配分する手助けをします。作業に合った配置を選びます。
agent-agent
81k大きな目標を順番に並んだ行動計画にし、状況が変わったときに計画を立て直す方法をエージェントに教えます。
agent-agentic-payments
81kAIの買い物のために、支出の上限、期間、販売店のルール、署名付きの承認を含む支出の委任を管理する手助けをします。
agent-analyze-code-quality
81kコードの品質を確認し、コードの臭い、技術的負債、リファクタリングの案を見つける手助けをします。ファイルは変更しません。