Interface ICostBudgetStore

Assembly: redb.Route.Llm.dll

Persists running cost / token usage per conversation so that an
implementation can enforce budgets across multiple agent runs
(not just within one).

is that consumer: AddRedbLlmStorage() registers it in
place of the shipped per-run defaults, and it reads this store before each run and adds to it after
each iteration. Implementations must be safe for concurrent updates.


The optional exchange parameter on every method carries the route
pipeline's current exchange; REDB-backed implementations resolve a
per-exchange through
IRouteContext.GetRedbService(name, exchange) using the named-redb
hint stored in . In-memory implementations
ignore it.
Without an exchange a redb-backed implementation opens a redb scope of its own for the call. That scope joins an
ambient (a , a
route's .Transacted()) as every redb connection does, but not a transaction begun on the context's shared
IRedbService (ExecuteAtomicAsync, BeginTransaction), which it does not see: pass the exchange,
or use a TransactionScope, when the call must commit or roll back with that work. In-memory implementations
take part in no transaction.

public interface ICostBudgetStore

Methods

AddAsync(string, AgentUsage, IExchange?, CancellationToken)

Atomically adds the iteration usage to the running total and returns the updated total.

ValueTask<AgentUsage> AddAsync(string conversationId, AgentUsage delta, IExchange? exchange = null, CancellationToken ct = default)

GetUsageAsync(string, IExchange?, CancellationToken)

Returns the running total for the conversation, or when unknown.

ValueTask<AgentUsage> GetUsageAsync(string conversationId, IExchange? exchange = null, CancellationToken ct = default)

ResetAsync(string, IExchange?, CancellationToken)

Resets the running total — used after a billing period rollover or by tests.

ValueTask ResetAsync(string conversationId, IExchange? exchange = null, CancellationToken ct = default)