feat: add cost budget enforcement with audit/enforce modes#212
Draft
lucioctinoco wants to merge 1 commit into
Draft
feat: add cost budget enforcement with audit/enforce modes#212lucioctinoco wants to merge 1 commit into
lucioctinoco wants to merge 1 commit into
Conversation
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
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.
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
YAML syntax
Changes
Tests
21 new tests covering schema, LimitEnforcer, all 3 graduation steps, and error hierarchy.
Full suite: 1178 passed, 5 skipped, 0 regressions.