A token-spend profiler and cost-regression gate for AI agents.
Project description
A Kill-A-Watt meter for your AI agents. Point it at a trace and it tells you exactly where your tokens are being burned and wasted, prices each waste pattern in real dollars, prescribes a fix, and can fail your CI when a change makes your agent measurably more expensive.
A real captured agent trace (see provenance) —
Wattage catches a stable prompt prefix being re-sent instead of cached, prices
the waste, and prescribes the fix. Regenerate this GIF with
vhs docs/assets/demo.tape (see the tape file for the exact command).
Install and run
uvx wattage report trace.json
No config file, no API key, fully offline — point it at an OTLP JSON trace export and it prices every call and runs every detector. Don't have a trace yet? Getting your first trace covers both "I already have OTel traces" and "I have zero instrumentation" (a runnable, 5-minute path from nothing to a real, priced report). Or try it right now against the fixture shipped in this repo:
git clone https://github.com/faizannraza/wattage
cd wattage && uv sync
uv run wattage report examples/sample_trace.json
╭──── ⚡ wattage — examples/sample_trace.json ────╮
│ Token Efficiency: A (100) Total cost: $0.0602 │
│ quality: unmeasured │
╰─────────────────────────────────────────────────╯
Token breakdown
┏━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃ Category ┃ Tokens ┃
┡━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│ input │ 18450 │
│ output │ 320 │
│ cache_read │ 0 │
│ cache_creation │ 0 │
│ reasoning │ 0 │
└────────────────┴────────┘
No findings — this trace looks efficient.
pricing: 2026-07-18-verified
Or get a self-contained, shareable HTML flame graph instead of the terminal view:
uv run wattage report examples/sample_trace.json --html report.html
The evidence, not a marketing claim
Wattage's standout feature is the convergence engine — the
nonconvergence detector, which catches an agent thrashing through a loop
without making real progress, including patterns a naive exact-match
duplicate detector structurally cannot see (a retry with a fresh timestamp
each time, an oscillation between two strategies, a "productive-looking"
stall where every call is technically unique but nothing is actually
learned).
Rather than assert that, we built a hand-reviewed set of 10 labeled synthetic loops and benchmarked Wattage's classifier against a real SHA-256 exact-match baseline implementation:
| Classifier | Precision | Recall | F1 |
|---|---|---|---|
| Wattage | 1.00 | 1.00 | 1.00 |
| SHA-256 exact-match | 1.00 | 0.14 | 0.25 |
Reproduce it yourself — no cherry-picking, no hidden setup:
uv run python -m benchmarks.harness
And on a genuine captured agent trace (not synthetic — see
benchmarks/traces/README.md for provenance),
Wattage's prefix_churn fix simulation shows a 44.7% cost reduction
($0.000199 → $0.000110) from enabling prompt caching on the stable prefix —
small dollar figures because it's a 3-turn demo trace, but the mechanism is
identical at production scale. Run it against your own traces for numbers
that matter:
uv run python -c "from benchmarks.frontier import build_frontier; print(build_frontier())"
Full methodology: The Convergence Engine.
The badge
uv run wattage badge trace.json --out wattage-badge.svg

Wire --badge-out into your CI job (see below) so it regenerates on every
merge to your default branch, and the badge in your README stays live.
How it works
Three surfaces, one normalized data model underneath
(sessions → tasks → loops → iterations → calls), built from
OpenTelemetry GenAI semantic-convention
traces:
-
wattage report— ingests a trace, prices every call against a vendored, dated pricing snapshot, and runs eight detectors:Detector Catches prefix_churnStable context re-sent instead of cached cache_gapCaching attempted but under-redeemed by later reads verbosityOutput far beyond what the step needed redundant_tool_callsThe same tool call repeated (exact or fuzzy) nonconvergenceLoops that thrash, oscillate, or stall without progress retrieval_thrashRepeated retrieval that never yields relevant results model_mismatchA pricier model doing work a cheaper one could handle reasoning_overspendHeavy reasoning-token spend on a simple step Every finding is priced in real dollars, includes a concrete fix, and is tagged with a
quality_risktier (none/low/review) — a fix that could plausibly change output quality (a model downgrade, less reasoning) only counts toward your score once a--qualitymap backs it with real evidence. Full detail: Detectors. -
wattage score/wattage badge— a single 0–100 Token Efficiency grade for a README badge or a CI gate. -
wattage ci— the cost-regression gate (below).
Wattage never fabricates a number: an unpriced model leaves that call's cost
at zero (and fails wattage ci loudly, exit code 4) rather than guessing;
an unmeasured quality signal is reported as unmeasured, not assumed fine.
CI integration
# .github/workflows/wattage.yml
name: Wattage
on:
pull_request:
paths: ["agents/**", "prompts/**", "src/**"]
concurrency:
group: wattage-${{ github.ref }}
cancel-in-progress: true
jobs:
token-efficiency:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Generate trace fixture
run: python scripts/run_agent_fixture.py > trace.json
- name: Wattage cost-regression gate
uses: faizannraza/wattage/action@v0.1.0
with:
source: trace.json
baseline: .wattage/baseline.json
fail-on: "score_below:80,cost_delta_pct_above:5,any_critical:true"
pr-comment: "true"
Fails the build (exit code 1) when your agent regresses past the threshold you set, posts a per-detector delta table as a PR comment, and emits SARIF (shows up in GitHub's Security tab) and JUnit XML for any other CI system. The baseline is a small committed JSON file — noise-floor protection is structural, not statistical: it only ever updates on a run that actually passed the gate.
This is only half the setup. A PR job runs on a throwaway checkout, so
it can't be the thing that updates .wattage/baseline.json on disk — that
update needs a second workflow, triggered on push to your default branch,
that commits the refreshed baseline (and badge) back after each merge.
Skipping it means every PR compares against the same stale baseline
forever. Full reference, with both workflows: CI Integration.
Contributing
Detectors are discovered through a Python entry-point group, so adding one
doesn't require touching this repo's core pipeline — see
CONTRIBUTING.md for the full "write a detector" walkthrough,
using cache_gap as the reference
example.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wattage-0.1.1.tar.gz.
File metadata
- Download URL: wattage-0.1.1.tar.gz
- Upload date:
- Size: 783.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
706fc7c3ae626b945d85d61f801d7a91fd7dc09ef81f6a4b905c13f91643e243
|
|
| MD5 |
27fdcbc086e96969c8b76ee34c79d370
|
|
| BLAKE2b-256 |
7139608ccd94b059044a00b34ebf95aecfbaae125c8bccacb712b0e6dc8b194a
|
File details
Details for the file wattage-0.1.1-py3-none-any.whl.
File metadata
- Download URL: wattage-0.1.1-py3-none-any.whl
- Upload date:
- Size: 82.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45cb7bdd976a85960afa05f72c194f31b57c254650daae5d5e3ccb30607ac247
|
|
| MD5 |
d85c6f503897ff10b0e63054e08fdbe9
|
|
| BLAKE2b-256 |
03ee66cfdf9d7313e763f63db644dbf43a4b77d495bb2265fb8e85a02d1e279d
|