feat(budget): add per-agent token budget enforcement#67
Merged
Conversation
Adds token budget controls to prevent runaway agents from consuming excessive API costs. Checks remaining budget before each LLM call, pauses the agent on limit exceeded, and emits warning/exceeded events. - New SQLite tables: token_budget_configs and token_budget_state - New budget-actions.ts: budget_set, budget_get, budget_resume actions - message-processor.ts: checkAndEnforceBudget() called before runAgent - api/events.ts: BudgetExceededEvent and BudgetWarningEvent types - Budget resets daily at configurable reset_hour (default midnight UTC) - Emits budget.warning at ≥80% usage (non-blocking) - Emits budget.exceeded and pauses agent when limit is hit - Depends on token_usage table from PR #59 (table creation is idempotent) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds token budget controls to prevent runaway agents from consuming excessive API costs.
Changes
token_budget_configsandtoken_budget_statebudget-actions.ts:budget_set,budget_get,budget_resumeactionsmessage-processor.ts:checkAndEnforceBudget()called beforerunAgentapi/events.ts:BudgetExceededEventandBudgetWarningEventtypesreset_hour(default midnight UTC)budget.warningat ≥80% usage (non-blocking)budget.exceededand pauses agent when limit is hitCloses #token-budget-enforcement