Skip to content

sergioide007/ciu-tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ciu-tracker

Cost per Useful Iteration (CIU) — measure the real cost of running AI agents in production. Companion code for the book Código Sintético / Synthetic Code (Chapter 11).

🇬🇧 English · 🇪🇸 Español


English

What it solves

When a team runs AI agents without governance, Token-Burn appears: token spend that buys no value because no system aggregates it. ciu-tracker makes it visible with one metric:

CIU = total token cost / features validated in production

The denominator is the key word: validated. Iterations that never reach production are not productivity — they are cost.

Install & run

git clone https://github.com/sergioide007/ciu-tracker
cd ciu-tracker
python ciu_tracker.py                       # built-in smoke demo
python examples/demo.py                     # fuller two-feature walkthrough
python examples/gateway_integration.py      # wire it into an AI Gateway (Ch. 3 + 11)
python -m unittest discover -s tests        # run the test suite

No dependencies beyond the Python standard library (3.10+).

Repository layout

ciu_tracker.py                 the metric, the ledger, the alert (≈ 60 lines of logic)
examples/demo.py               two features, one number that tells them apart
examples/gateway_integration.py  the one-line seam between transport and governance
tests/test_ciu_tracker.py      unittest suite — also the executable spec of the rules

Why the alert destination is injected (and not print)

The tracker measures; it does not decide where an alarm goes. The alert sink is a parameter (CIUTracker(alert_sink=...)), so adding Slack or PagerDuty never edits the metric, and tests assert on alerts by injecting a list. That is the Dependency Inversion principle doing real work — the same "SOLID como interrogatorio" the book applies in Chapter 4 (Martin, 2017).

Use it

from ciu_tracker import CIUTracker

tracker = CIUTracker(alert_ciu_usd=5.0)
tracker.record("checkout-refactor", tokens=18_000, cost_usd=0.70, validated=False)
tracker.record("checkout-refactor", tokens=9_000,  cost_usd=0.35, validated=True)

print(tracker.feature_ciu("checkout-refactor"))  # cost per validated feature
print(tracker.monthly_report())                   # team-level rollup + alert flag

Plug record(...) into your AI Gateway so every call is covered automatically. The tracker alerts when a feature's CIU crosses the threshold.

The five causes of excessive Token-Burn

  1. Inflated context · 2. The wrong model · 3. Loops without stopping criteria · 4. No prompt caching ·
  2. Ungoverned verbosity. Plus one lever: batch whatever is not urgent (~50% cheaper).

Español

Qué resuelve

Cuando un equipo opera agentes de IA sin gobernanza aparece el Token-Burn: gasto en tokens que no compra valor porque ningún sistema lo agrega. ciu-tracker lo hace visible con una métrica:

CIU = costo total de tokens / funcionalidades validadas en producción

El denominador es la palabra clave: validadas. Las iteraciones que no llegan a producción no son productividad; son costo.

Instalar y ejecutar

git clone https://github.com/sergioide007/ciu-tracker
cd ciu-tracker
python ciu_tracker.py          # ejecuta la demo de humo incluida

Sin dependencias más allá de la librería estándar de Python (3.10+).

Usarlo

from ciu_tracker import CIUTracker

tracker = CIUTracker(alert_ciu_usd=5.0)
tracker.record("checkout-refactor", tokens=18_000, cost_usd=0.70, validated=False)
tracker.record("checkout-refactor", tokens=9_000,  cost_usd=0.35, validated=True)

print(tracker.feature_ciu("checkout-refactor"))  # costo por feature validada
print(tracker.monthly_report())                   # consolidado del equipo + alerta

Integra record(...) en tu AI Gateway para cobertura automática. El tracker alerta cuando el CIU de una funcionalidad supera el umbral.


Article / Artículo

  • 🇬🇧 The Silent Token-Burn and the CIU Metric — Medium
  • 🇪🇸 El Token-Burn silencioso y la métrica CIU — LinkedIn

License

MIT © Sergio Perez Ruiz. See LICENSE.

About

Cost per Useful Iteration (CIU) — measure the real cost of running AI agents in production.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages