feat(provider): add cost controls and fallback #428

Merged
freemo merged 1 commits from feature/m4-provider-costs into master 2026-02-25 17:40:20 +00:00
Owner

Summary

Add token/cost tracking, budget enforcement (per-plan and per-day), provider fallback selection with capability filtering, and cost metadata for plan models. This implements cost controls so that AI spending can be monitored and capped, and provider fallback ensures service continuity when a provider is unavailable or over budget.

Changes

  • New modules:
    • providers/cost_table.py: CostEntry + ProviderCostTable with default pricing for OpenAI, Anthropic, Google, Groq, Together, Cohere, and Mock providers.
    • providers/cost_tracker.py: BudgetStatus enum, BudgetCheckResult, and CostTracker with warn-at-90%/block-at-100% enforcement.
    • providers/fallback_selector.py: FallbackSelector with capability filtering (tool_calls, streaming, vision, json_mode) and budget awareness.
    • domain/models/core/cost_metadata.py: CostMetadata + BudgetExhaustionEvent for plan-level audit trail.
  • Modified:
    • config/settings.py: Added budget_per_plan, budget_per_day, and fallback_providers config keys.
    • domain/models/core/plan.py: Added cost_metadata field and CLI display dict surfacing.
    • providers/__init__.py: Public exports for all new classes.
  • Documentation: Added docs/reference/cost_controls.md with config keys, thresholds, and fallback order.
  • Testing:
    • 71 Behave scenarios in features/cost_controls.feature (all passing).
    • 6 Robot Framework integration tests in robot/cost_controls.robot.
    • ASV benchmarks in benchmarks/cost_controls_bench.py.
  • Vulture whitelist: Updated vulture_whitelist.py with new public API symbols.

Closes #324

## Summary Add token/cost tracking, budget enforcement (per-plan and per-day), provider fallback selection with capability filtering, and cost metadata for plan models. This implements cost controls so that AI spending can be monitored and capped, and provider fallback ensures service continuity when a provider is unavailable or over budget. ### Changes - **New modules:** - `providers/cost_table.py`: `CostEntry` + `ProviderCostTable` with default pricing for OpenAI, Anthropic, Google, Groq, Together, Cohere, and Mock providers. - `providers/cost_tracker.py`: `BudgetStatus` enum, `BudgetCheckResult`, and `CostTracker` with warn-at-90%/block-at-100% enforcement. - `providers/fallback_selector.py`: `FallbackSelector` with capability filtering (tool_calls, streaming, vision, json_mode) and budget awareness. - `domain/models/core/cost_metadata.py`: `CostMetadata` + `BudgetExhaustionEvent` for plan-level audit trail. - **Modified:** - `config/settings.py`: Added `budget_per_plan`, `budget_per_day`, and `fallback_providers` config keys. - `domain/models/core/plan.py`: Added `cost_metadata` field and CLI display dict surfacing. - `providers/__init__.py`: Public exports for all new classes. - **Documentation:** Added `docs/reference/cost_controls.md` with config keys, thresholds, and fallback order. - **Testing:** - 71 Behave scenarios in `features/cost_controls.feature` (all passing). - 6 Robot Framework integration tests in `robot/cost_controls.robot`. - ASV benchmarks in `benchmarks/cost_controls_bench.py`. - **Vulture whitelist:** Updated `vulture_whitelist.py` with new public API symbols. Closes #324
freemo added this to the v3.0.0 milestone 2026-02-25 03:30:01 +00:00
freemo added the
Type
Feature
label 2026-02-25 03:30:19 +00:00
freemo force-pushed feature/m4-provider-costs from 53e3fa90a1 to 4f8b7c92d4 2026-02-25 16:39:38 +00:00 Compare
freemo scheduled this pull request to auto merge when all checks succeed 2026-02-25 16:42:20 +00:00
freemo canceled auto merging this pull request when all checks succeed 2026-02-25 16:58:46 +00:00
freemo added a new dependency 2026-02-25 17:05:41 +00:00
freemo scheduled this pull request to auto merge when all checks succeed 2026-02-25 17:06:44 +00:00
freemo canceled auto merging this pull request when all checks succeed 2026-02-25 17:07:05 +00:00
freemo force-pushed feature/m4-provider-costs from 803f1a3d2f to 134dce896a 2026-02-25 17:08:17 +00:00 Compare
freemo scheduled this pull request to auto merge when all checks succeed 2026-02-25 17:08:58 +00:00
freemo merged commit 134dce896a into master 2026-02-25 17:40:20 +00:00
freemo deleted branch feature/m4-provider-costs 2026-02-25 17:40:21 +00:00
freemo added the
State
Completed
label 2026-03-04 00:58:33 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Blocks
Reference: cleveragents/cleveragents-core#428