Skip to content

feat(budget): add per-agent token budget enforcement#67

Merged
DorianZheng merged 2 commits into
mainfrom
feature/token-budget-enforcement
Apr 25, 2026
Merged

feat(budget): add per-agent token budget enforcement#67
DorianZheng merged 2 commits into
mainfrom
feature/token-budget-enforcement

Conversation

@DorianZheng
Copy link
Copy Markdown
Member

Adds token budget controls to prevent runaway agents from consuming excessive API costs.

Changes

  • 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 feat: durable token usage tracking (SQLite + usage_get_summary action) #59 (table creation is idempotent)

Closes #token-budget-enforcement

DorianZheng and others added 2 commits April 24, 2026 07:06
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>
@DorianZheng DorianZheng merged commit b8b2acb into main Apr 25, 2026
2 checks passed
@DorianZheng DorianZheng deleted the feature/token-budget-enforcement branch April 25, 2026 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant