Skip to content

@Budget

The @Budget decorator (config/budget.config.ts) defines a FinOps spend ceiling registered in @Application({ budgets }). Budgets are checked before the first step of an execution and reconciled after every model call and SpendRecorder.record() entry across three hierarchical scopes: BudgetScope.Application, BudgetScope.Tenant, and BudgetScope.Execution.

Complete @Budget example across all 3 scopes

Section titled “Complete @Budget example across all 3 scopes”

Every @Budget class implements BudgetHandler (maxSpend(): Usd | Promise<Usd>) and its name ends with -budget:

Option Applies To Type Required Description
name All scopes string Yes Unique kebab-case identifier ending with -budget (e.g., "tenant-daily-budget").
scope All scopes BudgetScope Yes BudgetScope.Application, BudgetScope.Tenant, or BudgetScope.Execution.
period Application & Tenant BudgetPeriod Yes UTC accounting window: BudgetPeriod.Day, BudgetPeriod.Week, or BudgetPeriod.Month. Forbidden on BudgetScope.Execution.
workflow Execution Class No Optional @Workflow class this execution cap applies to; omit to set the default cap for all root executions.
deps All scopes readonly Token[] No Constructor dependencies (AppEnvironment, TenantContext, ExecutionContext, or @Injectable billing services).
Related Entity Import Path Purpose
BudgetHandler "@agboss/core" Interface implemented by every @Budget class (maxSpend(): Usd | Promise<Usd>).
BudgetScope & BudgetPeriod "@agboss/core" Enums specifying what is capped (Application, Tenant, Execution) and over which UTC period (Day, Week, Month).
usd(amount) & Usd "@agboss/core/units" Exact monetary unit factory required for all budget caps and spend reporting.
SpendRecorder "@agboss/core" Injected into @Tool and @Action classes via deps: [SpendRecorder] to count paid external API calls toward @Budget caps.
CostLedgerRepository & SqliteCostLedgerRepository "@agboss/core" Atomic multi-instance ledger storing period and execution spend counters; required in production (agboss check --strict).
BudgetExceededError "@agboss/core" Thrown when a pre-call reservation or post-call spend exceeds any active @Budget ceiling.