feat(guards): implement budget cap enforcement for token and cost limits #8538

Open
opened 2026-04-13 20:37:11 +00:00 by HAL9000 · 0 comments
Owner

Metadata

  • Commit message type: feat
  • Scope: guards
  • Branch name prefix: feat/v3.5.0-budget-cap-enforcement

Background and Context

As part of Epic #8424 (Guard & Safety System), budget cap enforcement prevents plans from exceeding configured token or cost limits. This is essential for autonomous execution where runaway plans could incur significant costs.

This issue blocks Epic #8424.

Expected Behavior

  • Budget caps (max token spend, max cost) are configurable per-plan and per-action
  • Plan execution halts when a budget cap is reached, with a clear BudgetExceededError
  • Budget tracking is updated after each LLM call
  • Budget caps are enforced before each LLM call (pre-check)

Acceptance Criteria

  • BudgetCapGuard class is implemented with configurable token and cost limits
  • Guard raises BudgetExceededError when a budget cap is exceeded
  • Budget tracking is updated after each LLM call
  • Pre-check prevents LLM calls that would exceed the budget
  • Error message includes: current spend, budget limit, plan ID
  • BDD tests cover budget cap enforcement scenarios
  • Unit tests achieve >= 97% coverage

Subtasks

  • Define BudgetExceededError exception class
  • Implement BudgetCapGuard class with token and cost tracking
  • Add pre-check before each LLM call
  • Integrate BudgetCapGuard into plan execution pipeline
  • Emit structured log event on budget exceeded
  • Write BDD tests for budget cap enforcement
  • Write unit tests for budget tracking logic

Definition of Done

  1. BudgetCapGuard is implemented and integrated
  2. BDD tests cover budget cap enforcement scenarios
  3. Unit tests pass with >= 97% coverage
  4. Code reviewed and merged to main branch

Automated by CleverAgents Bot
Supervisor: Epic Planning | Agent: epic-planning-pool-supervisor

## Metadata - **Commit message type**: `feat` - **Scope**: `guards` - **Branch name prefix**: `feat/v3.5.0-budget-cap-enforcement` ## Background and Context As part of Epic #8424 (Guard & Safety System), budget cap enforcement prevents plans from exceeding configured token or cost limits. This is essential for autonomous execution where runaway plans could incur significant costs. This issue blocks Epic #8424. ## Expected Behavior - Budget caps (max token spend, max cost) are configurable per-plan and per-action - Plan execution halts when a budget cap is reached, with a clear `BudgetExceededError` - Budget tracking is updated after each LLM call - Budget caps are enforced before each LLM call (pre-check) ## Acceptance Criteria - [ ] `BudgetCapGuard` class is implemented with configurable token and cost limits - [ ] Guard raises `BudgetExceededError` when a budget cap is exceeded - [ ] Budget tracking is updated after each LLM call - [ ] Pre-check prevents LLM calls that would exceed the budget - [ ] Error message includes: current spend, budget limit, plan ID - [ ] BDD tests cover budget cap enforcement scenarios - [ ] Unit tests achieve >= 97% coverage ## Subtasks - [ ] Define `BudgetExceededError` exception class - [ ] Implement `BudgetCapGuard` class with token and cost tracking - [ ] Add pre-check before each LLM call - [ ] Integrate `BudgetCapGuard` into plan execution pipeline - [ ] Emit structured log event on budget exceeded - [ ] Write BDD tests for budget cap enforcement - [ ] Write unit tests for budget tracking logic ## Definition of Done 1. `BudgetCapGuard` is implemented and integrated 2. BDD tests cover budget cap enforcement scenarios 3. Unit tests pass with >= 97% coverage 4. Code reviewed and merged to main branch --- **Automated by CleverAgents Bot** Supervisor: Epic Planning | Agent: epic-planning-pool-supervisor
HAL9000 added this to the v3.5.0 milestone 2026-04-13 20:53:18 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#8538
No description provided.