One control loop. Five parts.
Every cost tool tells you what an agent operation spent. Only you know what the outcome was worth: a merged PR, a passed test, a resolved ticket. Price it and each operation reports its return; price nothing and it reports cost per outcome, labelled as one.
We turned down a 69.4% saving. 116 real tasks, a cheaper route at 30.6% of the incumbent’s bill, quality 93% to 79%, parity 0.85 against a 0.97 bar. The gate refused it. Published, tagged is_simulated=false.
- The Meter: measures every call, its cost, tokens, substrate, and whether it worked.
- The Estate: the org chart of your AI workforce.
- The Money Map: where the spend goes, decomposed by step.
- The Parity Gate: proves the cheaper route held quality before it ships.
- The Governor: acts with a human ratifying, and a revert armed; if quality slips it reverts and the loop re-runs.

The Meter
Every call, metered: cost, tokens, substrate, and whether it worked, a verdict your own evals supply.
Cost per outcome is the honest default of a value-per-outcome model. No customer has priced an outcome yet, so every figure Margin computes is cost per outcome, and it is labelled as one. Price yours and the meter records it beside the cost, every outcome counted once and unweighted. A value you did not supply is never invented.
The Meter →- cost
- tokens
- substrate
- outcome
- ✓ worked
- Support team
- production
- triage agent classify
- reply agent draft
- staging
- eval agent score
- production

The Parity Gate
A cheaper route is promoted only while quality holds, and reverted when it slips.
The Parity Gate →The measuring half is free and open.
pip install margin-cost reads a local corpus of invoices and outcome counts and prints cost per outcome for every vendor, with the retry tax, cache efficiency, token yield, and the coverage tiers that stop any of it claiming more precision than the evidence supports. It measures; it does not act. No account, no backend, and it never phones home, including to us.
What Margin adds: routing a call to a cheaper model, proving the cheaper model held quality first, promoting that route and reverting it when parity slips, continuously. Measuring spend is becoming table stakes; proving a change did not cost you quality is the commercial product.
Watch the loop run on real spend.
The console shows the loop on open-source agents we metered ourselves: measured spend, recorded face-offs and the gate’s verdicts, every number tagged real or sample. No live route has slipped yet, so the revert has not fired.


