Skip to content

feat: add cost budget enforcement with audit/enforce modes#212

Draft
lucioctinoco wants to merge 1 commit into
microsoft:mainfrom
lucioctinoco:feature/budget-enforcement
Draft

feat: add cost budget enforcement with audit/enforce modes#212
lucioctinoco wants to merge 1 commit into
microsoft:mainfrom
lucioctinoco:feature/budget-enforcement

Conversation

@lucioctinoco
Copy link
Copy Markdown
Contributor

@lucioctinoco lucioctinoco commented May 19, 2026

Summary

Implements a Token Budget pattern as a runtime safety mechanism for agentic workflows. Adds budget_usd and budget_mode to workflow limits configuration.

Graduation path for users

  1. No config (default) - no budget tracking, existing behavior unchanged
  2. budget_usd + audit mode - emits budget_exceeded event, logs warning, workflow continues
  3. budget_usd + enforce mode - emits event, saves checkpoint, stops workflow with BudgetExceededError

YAML syntax

limits:
  budget_usd: 5.00
  budget_mode: audit     # or: enforce

Changes

  • config/schema.py: budget_usd and budget_mode on LimitsConfig
  • exceptions.py: BudgetExceededError
  • engine/limits.py: check_budget() with first-time detection; from_dict() resume parity
  • engine/workflow.py: _check_budget() at all 5 enforcement points
  • cli/run.py: pass budget fields on resume
  • docs/configuration.md: document budget fields and graduation path
  • AGENTS.md: test fixture patterns and resume/checkpoint parity notes

Tests

21 new tests covering schema, LimitEnforcer, all 3 graduation steps, and error hierarchy.
Full suite: 1178 passed, 5 skipped, 0 regressions.

Add budget_usd and budget_mode to workflow limits configuration,
implementing LOA Pattern 2.4 (Token Budget Throttle) as a runtime
safety mechanism for agentic workflows.

Graduation path for users:
1. No config (default) - no budget tracking, existing behavior unchanged
2. budget_usd with audit mode - emits budget_exceeded event, logs warning,
   workflow continues. Discover cost profiles before enforcing.
3. budget_usd with enforce mode - emits event, saves checkpoint, stops
   workflow with BudgetExceededError. Resumable via conductor resume.

Changes:
- config/schema.py: budget_usd (float|None) and budget_mode (audit|enforce)
  on LimitsConfig
- exceptions.py: BudgetExceededError with budget_usd, spent_usd, and
  current_agent attributes
- engine/limits.py: check_budget() on LimitEnforcer with first-time
  detection flag; from_dict() accepts budget fields for resume parity
- engine/workflow.py: _check_budget() helper called at all 5 enforcement
  points alongside check_timeout(); budget_exceeded event emission;
  workflow_failed enrichment for BudgetExceededError
- cli/run.py: pass budget fields to LimitEnforcer.from_dict() on resume
- docs/configuration.md: document budget fields and graduation path
- AGENTS.md: add test fixture patterns and resume/checkpoint parity notes
- tests/test_engine/test_budget.py: 21 tests covering schema defaults,
  LimitEnforcer unit tests, all 3 graduation steps, and error attributes
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.

2 participants