Class StoreBudgetEnforcer
Budget enforcement that survives the run: usage is accumulated per conversation in an
, and the per-run ceiling from is checked
against that running total. A conversation that already spent its budget therefore stops the next
run as well — that is the point of storing it, and it is a behaviour change worth knowing about:
a run that passes today can stop once the conversation's total crosses the ceiling.
Registered by AddRedbLlmStorage() in place of the shipped per-run defaults. The engine calls the
members that carry the run's exchange, and the store gets it: the rows go to the redb instance the endpoint
chose (?redb=), else the store's own default. The members without an exchange use the store's default.
Without a conversation id there is nowhere to accumulate, so the check degrades to the per-run one.
public sealed class StoreBudgetEnforcer : IBudgetEnforcer
Inheritance
Implements
Methods
PreCheckAsync(string?, AgentBudget, AgentUsage, CancellationToken)
Checks whether the agent run is allowed to continue at the start of an
public ValueTask<BudgetDecision> PreCheckAsync(string? conversationId, AgentBudget budget, AgentUsage usageSoFar, CancellationToken ct = default)
PreCheckAsync(string?, AgentBudget, AgentUsage, IExchange?, CancellationToken)
with the run's exchange, which
public ValueTask<BudgetDecision> PreCheckAsync(string? conversationId, AgentBudget budget, AgentUsage usageSoFar, IExchange? exchange, CancellationToken ct = default)
RecordAndCheckAsync(string?, AgentBudget, AgentUsage, AgentUsage, CancellationToken)
Records usage produced by the iteration and returns a decision whether the agent may
public ValueTask<BudgetDecision> RecordAndCheckAsync(string? conversationId, AgentBudget budget, AgentUsage iterationUsage, AgentUsage totalUsage, CancellationToken ct = default)
RecordAndCheckAsync(string?, AgentBudget, AgentUsage, AgentUsage, IExchange?, CancellationToken)
with the
public ValueTask<BudgetDecision> RecordAndCheckAsync(string? conversationId, AgentBudget budget, AgentUsage iterationUsage, AgentUsage totalUsage, IExchange? exchange, CancellationToken ct = default)
Constructors
StoreBudgetEnforcer(ICostBudgetStore)
Creates the enforcer over store.