Skip to main content

Module cost_budget

Module cost_budget 

Source
Expand description

Per-scope cost budgets + spend aggregation (CH-06, fable §R11 / §7).

Builds on the existing opt-in cost estimation (LlmConfig.cost_tracking, estimate_cost, the uar_llm_cost_usd metric). This module adds the accounting layer the runtime was missing: aggregate spend per run / task / session / agent, declare budget envelopes, and emit threshold-crossing events so the UI and operators can react before a runaway burns the budget.

In-memory and lock-light — a single-process aggregator suitable for the runtime hot path. Durable roll-ups (SurrealDB/Postgres) can layer on top by subscribing to the emitted events; that persistence is intentionally out of scope here.

Structs§

BudgetLimit
A configured budget limit for one (scope, scope_id).
CostBudgetTracker
Thread-safe cost-budget tracker. Cloneable handle over shared state.

Enums§

BudgetScope
The dimension a budget / spend record is keyed on.
BudgetStatus
Result of recording spend against a budget.