Documentation
¶
Overview ¶
Package budget provides agent-side enforcement of rolling 24-hour token budgets.
The operator injects AGENT_DAILY_TOKEN_LIMIT into each agent pod. The agent checks this limit before running every task using a Redis sorted set as the shared counter. This is proactive enforcement — the task is rejected before any LLM call is made, not after the operator notices the overage on its next reconcile cycle.
Redis key layout:
ark:budget:{namespace}:{agentName}:usage
score = Unix milliseconds of task completion time
member = "{taskID}:{totalTokens}"
Entries older than 24 hours are pruned on every Check call.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrBudgetExceeded = errors.New("daily token budget exceeded")
ErrBudgetExceeded is returned by Check when the rolling 24h token budget is full.
Functions ¶
This section is empty.
Types ¶
type Store ¶
type Store interface {
// Check returns ErrBudgetExceeded if the daily token limit has been reached.
// It also prunes entries older than 24 hours from the underlying store.
Check(ctx context.Context) error
// Record persists token usage for a completed task so it counts toward the budget.
Record(ctx context.Context, taskID string, totalTokens int64) error
// Close releases any resources held by the store.
Close() error
}
Store checks and records token usage against a rolling 24-hour budget.
Click to show internal directories.
Click to hide internal directories.