Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -2,14 +2,14 @@
|
|
| 2 |
license: mit
|
| 3 |
library_name: xgboost
|
| 4 |
tags:
|
| 5 |
-
- agent-cost-optimizer
|
| 6 |
-
- model-router
|
| 7 |
-
- cost-aware-inference
|
| 8 |
-
- cascade-routing
|
| 9 |
-
-
|
| 10 |
---
|
| 11 |
|
| 12 |
-
# Agent Cost Optimizer (
|
| 13 |
|
| 14 |
A universal control layer that reduces the cost of autonomous agent runs while preserving task quality.
|
| 15 |
|
|
@@ -17,36 +17,65 @@ A universal control layer that reduces the cost of autonomous agent runs while p
|
|
| 17 |
|
| 18 |
ACO sits in front of any agent harness and makes cost-aware decisions:
|
| 19 |
- Which model to use (tiny → frontier → specialist)
|
|
|
|
| 20 |
- How much context to include
|
| 21 |
- Whether to call tools
|
| 22 |
- Whether to verify outputs
|
| 23 |
- When to stop failing runs
|
| 24 |
- How to recover from errors
|
| 25 |
|
| 26 |
-
##
|
| 27 |
|
| 28 |
-
|
| 29 |
|
| 30 |
-
1.
|
| 31 |
-
2.
|
| 32 |
-
3.
|
| 33 |
-
4.
|
| 34 |
-
5. **Cache-Aware Prompt Layout** - Prefix-cache optimization
|
| 35 |
-
6. **Tool-Use Cost Gate** - Skip/batch/cache tool calls
|
| 36 |
-
7. **Verifier Budgeter** - Selective verification
|
| 37 |
-
8. **Retry/Recovery Optimizer** - Failure-specific actions
|
| 38 |
-
9. **Meta-Tool Miner** - Repeated workflow compression
|
| 39 |
-
10. **Doom Detector** - Early termination
|
| 40 |
|
| 41 |
-
|
| 42 |
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|--------|---------|---------|---------|
|
| 45 |
-
| always_frontier |
|
| 46 |
-
|
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
## Quick Start
|
| 52 |
|
|
@@ -56,105 +85,30 @@ from aco.config import ACOConfig
|
|
| 56 |
|
| 57 |
opt = ACOOptimizer(ACOConfig(router_model_path="router_models/router_bundle_v8.pkl"))
|
| 58 |
|
| 59 |
-
# Route
|
| 60 |
result = opt.start_run("Debug this critical production bug")
|
| 61 |
print(result["routing"]) # tier, model_id, confidence, cost_estimate
|
| 62 |
|
| 63 |
-
#
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
trace = opt.end_run(success=True)
|
| 68 |
```
|
| 69 |
|
| 70 |
## CLI
|
| 71 |
|
| 72 |
```bash
|
| 73 |
-
aco route "Fix a typo in the README" # → tier 2
|
| 74 |
-
aco route "Debug critical prod bug NOW" # → tier 5
|
| 75 |
-
aco
|
| 76 |
-
aco gate web_search --task-type research
|
| 77 |
-
aco verify --risk high --confidence 0.7
|
| 78 |
-
aco version
|
| 79 |
-
```
|
| 80 |
-
|
| 81 |
-
## Router v8: Dynamic Difficulty + ML
|
| 82 |
-
|
| 83 |
-
The router uses:
|
| 84 |
-
1. Dynamic difficulty estimation from request keywords
|
| 85 |
-
2. Per-tier XGBoost success predictors
|
| 86 |
-
3. Isotonic regression calibration
|
| 87 |
-
4. Safety floors per task type (legal→4, coding→3, etc.)
|
| 88 |
-
5. Safety net escalation (P(success) < 0.30)
|
| 89 |
-
6. Cost saver downgrade (P(success@cheaper) ≥ 0.90)
|
| 90 |
-
|
| 91 |
-
## Trained Models
|
| 92 |
-
|
| 93 |
-
- `router_bundle_v8.pkl` - Production v8 (XGBoost per-tier + calibrators)
|
| 94 |
-
- `router_bundle_v6.pkl` - v6 hybrid baseline
|
| 95 |
-
|
| 96 |
-
## Files
|
| 97 |
-
|
| 98 |
-
```
|
| 99 |
-
aco/ - Python package
|
| 100 |
-
optimizer.py - Main orchestrator
|
| 101 |
-
router.py - Model cascade router
|
| 102 |
-
classifier.py - Task cost classifier
|
| 103 |
-
context_budgeter.py - Context allocation
|
| 104 |
-
cache_layout.py - Prefix-cache optimization
|
| 105 |
-
tool_gate.py - Tool-use cost gate
|
| 106 |
-
verifier_budgeter.py - Selective verification
|
| 107 |
-
retry_optimizer.py - Failure recovery
|
| 108 |
-
meta_tool_miner.py - Workflow compression
|
| 109 |
-
doom_detector.py - Early termination
|
| 110 |
-
config.py - Configuration
|
| 111 |
-
trace_schema.py - Normalized trace schema
|
| 112 |
-
cli.py - CLI interface
|
| 113 |
-
router_models/ - Trained XGBoost models
|
| 114 |
-
training/ - Training scripts (v1-v8)
|
| 115 |
-
eval/ - Benchmark results
|
| 116 |
```
|
| 117 |
|
| 118 |
-
##
|
| 119 |
-
|
| 120 |
-
- Router trained on synthetic data (needs real agent traces)
|
| 121 |
-
- No execution-feedback features yet (highest-impact next step)
|
| 122 |
-
- No real agent benchmarks (SWE-bench, BFCL) yet
|
| 123 |
-
- Quality gap vs always-frontier (79.6% vs 91.0%)
|
| 124 |
-
|
| 125 |
-
## Citation
|
| 126 |
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
@software{aco2025,
|
| 131 |
-
title={Agent Cost Optimizer: Universal Control Layer for Autonomous Agents},
|
| 132 |
-
author={narcolepticchicken},
|
| 133 |
-
year={2025},
|
| 134 |
-
url={https://huggingface.co/narcolepticchicken/agent-cost-optimizer}
|
| 135 |
-
}
|
| 136 |
-
```
|
| 137 |
|
| 138 |
## License
|
| 139 |
|
| 140 |
MIT
|
| 141 |
-
|
| 142 |
-
<!-- ml-intern-provenance -->
|
| 143 |
-
## Generated by ML Intern
|
| 144 |
-
|
| 145 |
-
This model repository was generated by [ML Intern](https://github.com/huggingface/ml-intern), an agent for machine learning research and development on the Hugging Face Hub.
|
| 146 |
-
|
| 147 |
-
- Try ML Intern: https://smolagents-ml-intern.hf.space
|
| 148 |
-
- Source code: https://github.com/huggingface/ml-intern
|
| 149 |
-
|
| 150 |
-
## Usage
|
| 151 |
-
|
| 152 |
-
```python
|
| 153 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 154 |
-
|
| 155 |
-
model_id = 'narcolepticchicken/agent-cost-optimizer'
|
| 156 |
-
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 157 |
-
model = AutoModelForCausalLM.from_pretrained(model_id)
|
| 158 |
-
```
|
| 159 |
-
|
| 160 |
-
For non-causal architectures, replace `AutoModelForCausalLM` with the appropriate `AutoModel` class.
|
|
|
|
| 2 |
license: mit
|
| 3 |
library_name: xgboost
|
| 4 |
tags:
|
| 5 |
+
- agent-cost-optimizer
|
| 6 |
+
- model-router
|
| 7 |
+
- cost-aware-inference
|
| 8 |
+
- cascade-routing
|
| 9 |
+
- execution-feedback
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# ACO: Agent Cost Optimizer (v9)
|
| 13 |
|
| 14 |
A universal control layer that reduces the cost of autonomous agent runs while preserving task quality.
|
| 15 |
|
|
|
|
| 17 |
|
| 18 |
ACO sits in front of any agent harness and makes cost-aware decisions:
|
| 19 |
- Which model to use (tiny → frontier → specialist)
|
| 20 |
+
- Whether to escalate based on output confidence (execution feedback)
|
| 21 |
- How much context to include
|
| 22 |
- Whether to call tools
|
| 23 |
- Whether to verify outputs
|
| 24 |
- When to stop failing runs
|
| 25 |
- How to recover from errors
|
| 26 |
|
| 27 |
+
## v9 Breakthrough: Execution-Feedback Routing
|
| 28 |
|
| 29 |
+
**v9 matches frontier quality at 2.1% cost reduction** by using the cheap model's output confidence to decide whether to escalate:
|
| 30 |
|
| 31 |
+
1. Route request to cheap model (v8 router)
|
| 32 |
+
2. Compute token-level uncertainty from output logprobs
|
| 33 |
+
3. If uncertainty > calibrated threshold → escalate to stronger model
|
| 34 |
+
4. Otherwise, use cheap model's response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
This implements the RouteNLP / CP-Router pattern from recent literature.
|
| 37 |
|
| 38 |
+
## Benchmark Results
|
| 39 |
+
|
| 40 |
+
### Synthetic Benchmark (3K traces)
|
| 41 |
+
|
| 42 |
+
| Method | Success | AvgCost | CostRed |
|
| 43 |
+
|--------|---------|---------|---------|
|
| 44 |
+
| always_frontier | 90.0% | $1.00 | baseline |
|
| 45 |
+
| **v9 (feedback)** | **90.0%** | **$0.98** | **2.1%** |
|
| 46 |
+
| v8 (router only) | 83.7% | $0.92 | 8.5% |
|
| 47 |
+
| heuristic | 83.4% | $0.92 | 11.7% |
|
| 48 |
+
|
| 49 |
+
### Real SWE-bench (500 tasks, 8 models)
|
| 50 |
+
|
| 51 |
+
| Method | Success | AvgCost | CostRed |
|
| 52 |
|--------|---------|---------|---------|
|
| 53 |
+
| always_frontier | 78.2% | $0.32 | baseline |
|
| 54 |
+
| **v9 (feedback)** | **82.6%** | **$0.48** | **-53%** |
|
| 55 |
+
| v8 (router only) | 75.6% | $0.29 | 8.0% |
|
| 56 |
+
| oracle | 87.0% | $0.05 | 82.8% |
|
| 57 |
+
|
| 58 |
+
Key: 64.6% of SWE-bench tasks are solvable by the cheapest model. v9 achieves higher success than always-frontier by escalating when cheap fails.
|
| 59 |
+
|
| 60 |
+
### BFCL v3 Function-Calling (82K traces, 108 models)
|
| 61 |
+
|
| 62 |
+
- **84.1% of tasks solvable by cheaper models** — validates routing thesis
|
| 63 |
+
- **82.5% need only tier 1** — massive savings potential
|
| 64 |
+
- **Top error: state mismatch** — validates tool-use cost gate
|
| 65 |
|
| 66 |
+
## The 11 Modules
|
| 67 |
+
|
| 68 |
+
1. **Cost Telemetry Collector** - Normalized JSON trace schema
|
| 69 |
+
2. **Task Cost Classifier** - 9 task types, dynamic difficulty
|
| 70 |
+
3. **Model Cascade Router (v8)** - Dynamic difficulty + XGBoost + safety floors
|
| 71 |
+
4. **Execution-Feedback Router (v9)** - Token-level uncertainty + cascade
|
| 72 |
+
5. **Context Budgeter** - Adaptive context allocation
|
| 73 |
+
6. **Cache-Aware Prompt Layout** - Prefix-cache optimization
|
| 74 |
+
7. **Tool-Use Cost Gate** - Skip/batch/cache tool calls
|
| 75 |
+
8. **Verifier Budgeter** - Risk-weighted selective verification
|
| 76 |
+
9. **Retry/Recovery Optimizer** - Failure-specific recovery actions
|
| 77 |
+
10. **Meta-Tool Miner** - Repeated workflow compression
|
| 78 |
+
11. **Doom Detector** - Early termination for failing runs
|
| 79 |
|
| 80 |
## Quick Start
|
| 81 |
|
|
|
|
| 85 |
|
| 86 |
opt = ACOOptimizer(ACOConfig(router_model_path="router_models/router_bundle_v8.pkl"))
|
| 87 |
|
| 88 |
+
# Route + cascade with feedback
|
| 89 |
result = opt.start_run("Debug this critical production bug")
|
| 90 |
print(result["routing"]) # tier, model_id, confidence, cost_estimate
|
| 91 |
|
| 92 |
+
# Use execution feedback for cascade decisions
|
| 93 |
+
cascade = opt.cascade_step(request, initial_tier=2, cheap_logprobs=logprobs,
|
| 94 |
+
cheap_response=response)
|
| 95 |
+
print(f"Escalated: {cascade.escalated}, Final tier: {cascade.final_tier}")
|
|
|
|
| 96 |
```
|
| 97 |
|
| 98 |
## CLI
|
| 99 |
|
| 100 |
```bash
|
| 101 |
+
aco route "Fix a typo in the README" # → tier 2
|
| 102 |
+
aco route "Debug critical prod bug NOW" # → tier 5
|
| 103 |
+
aco version # ACO v8.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
```
|
| 105 |
|
| 106 |
+
## Links
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
+
- **Model**: [narcolepticchicken/agent-cost-optimizer](https://huggingface.co/narcolepticchicken/agent-cost-optimizer)
|
| 109 |
+
- **Dataset**: [narcolepticchicken/agent-cost-traces](https://huggingface.co/datasets/narcolepticchicken/agent-cost-traces)
|
| 110 |
+
- **Dashboard**: [narcolepticchicken/aco-dashboard](https://huggingface.co/spaces/narcolepticchicken/aco-dashboard)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
## License
|
| 113 |
|
| 114 |
MIT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|