| Module | Problem | Solution | Impact |
|---|---|---|---|
| Model Cascade Router | Overusing frontier models | Routes to cheapest capable model | ~56% cost reduction (simulated, iso-quality) |
| Tool-Use Cost Gate | Unnecessary tool calls | Predicts whether tool call is worth cost | gate F1=0.92 (verified) |
| Verifier Budgeter | Verifying everything | Selectively gating verification | gate F1=0.65 (verified, weak) |
| Context Compressor | Growing context windows | ACON-pattern state-preserving compression | 30-54% token reduction (literature) |
| Cache-Aware Layout | Cache-unfriendly prompts | Static-at-prefix optimization | 50-90% input cost reduction (literature) |
| Intervention Threshold | Verifier-caused regressions | Only verify when safe (d/(d+r) threshold) | Prevents collapse (literature) |
| Token Budget Estimator | Verbose outputs | Per-query optimal length prediction | 15-25% output token reduction (literature) |
| Doom Detector | Continuing doomed runs | Terminate/rescue on failure signals | Prevents wasted cost |
| Meta-Tool Miner | Repeated workflows | Compress successful traces into macros | LLM calls saved on repeats |
Evidence levels: "verified" = independently re-evaluated on held-out data in this repo. "simulated" = derived from trace simulation (aco/benchmark.py, SWE-Router traces), not live test execution. "literature" = reported by cited papers, not independently measured here.
| Claim | Status | Evidence |
|---|---|---|
| Tool-gater F1 = 0.92, acc = 0.98 | ✅ Verified | Independent re-eval, N=1695 held-out |
| Tier-router F1 = 0.67, acc = 0.70 | ✅ Verified | Independent re-eval, N=1260 held-out |
| Verifier-gater F1 = 0.65, acc = 0.65 | ✅ Verified (weak model) | Independent re-eval, N=863 held-out |
| v2 ModernBERT beats v1 | ❌ False | v2 regressed tool-gater −19.6pp F1; flat elsewhere |
| Cascade ≈ 56% cost reduction at iso-quality | ⚠️ Simulated only | Trace simulation; frontier-retry actually solves +4 instances |
| "4/4 Django instances solved by T1" | ⚠️ Misleading | Patches passed git apply --check only — not test-verified |
| Live SWE-bench resolution by cascade agent | ❌ Not demonstrated | No Docker/test-verified results file exists in repo |
Agent Request
│
▼
┌─────────────────────────────────────┐
│ ACO Control Layer │
│ │
│ ┌─────────┐ ┌───────────┐ │
│ │Classifier│─▶│Tier Router│──┐ │
│ └─────────┘ └───────────┘ │ │
│ ▼ │
│ ┌──────────┐ ┌───────────┐ │
│ │Compressor│ │Cache Layout│ │
│ └──────────┘ └───────────┘ │
│ │ │ │
│ └─────┬──────┘ │
│ ▼ │
│ ┌──────────┐ ┌───────────┐ │
│ │Tool Gate │ │Ver. Budget│ │
│ └──────────┘ └───────────┘ │
│ │ │ │
│ ▼ ▼ │
│ ┌──────────────────────────┐ │
│ │ Retry + Recovery + Doom │ │
│ └──────────────────────────┘ │
│ │ │
└─────────────┼────────────────────┘
▼
Agent API Call1from aco import ACOPipeline
2
3# v1 DistilBERT specialists are the production models (v2 regressed — do not use).
4aco = ACOPipeline(use_v2=False)
5
6result = aco.optimize(
7 request="Fix the connection pool timeout in database.py and run the tests",
8 available_tools=["edit_file", "run_tests", "git_diff"],
9 context={"system_prompt": "...", "tool_definitions": "..."}
10)
11
12print(result.routing) # Which model to use
13print(result.tool_decisions) # Which tools to call
14print(result.needs_verify) # Whether to verify output
15print(result.context_budget) # How much context to include
16print(result.cost_estimate) # Expected cost1pip install transformers torch datasets
2git clone https://huggingface.co/narcolepticchicken/agent-cost-optimizer
3cd agent-cost-optimizer
4pip install -e .| Model | Base | Params | Accuracy | F1 Macro | Test N |
|---|---|---|---|---|---|
| Tier Router | DistilBERT | 67M | 0.70 | 0.67 | 1260 |
| Tool Gater | DistilBERT | 67M | 0.98 | 0.92 | 1695 |
| Verifier Gater | DistilBERT | 67M | 0.65 | 0.65 | 863 |
v2_verification_results.json. Use the v1 models above.| Finding | Paper |
|---|---|
| BERT classifier routing → 2x cost reduction | RouteLLM (2406.18665) |
| Guideline compression → 26-54% token reduction | ACON (2510.00615) |
| Critics cause collapse when overused | Intervention Paradox |
| Systematic component optimization → lower cost | Efficient Agents (2508.02694) |
| Cascade + self-consistency → cheaper | In-Context Distillation (2512.02543) |