Skip to content

feat(phase35): Token Budget Governor & Adaptive Context Compression - #73

Merged
De-pitcher merged 4 commits into
mainfrom
feat/phase35-token-governor-adaptive-cache
Sep 7, 2026
Merged

De-pitcher merged 4 commits into
mainfrom
feat/phase35-token-governor-adaptive-cache

Conversation

@De-pitcher

Copy link
Copy Markdown
Owner

Phase 35: Token Budget Governor & Adaptive Context Compression

Summary of Changes

  1. TokenBudgetGovernor (\�gentcli/memory/governor.py):
    • Real-time token and USD tracking across models, prompt tokens, completion tokens, cached tokens, and subagent types.
    • Dynamic spend velocity calculations ($/hr, \ okens/min).
    • Soft budget warning (80% threshold) and hard ceiling enforcement with detailed usage breakdowns and formatted summary tables.
  2. AdaptiveContextCompressor (\�gentcli/memory/adaptive_compressor.py):
    • Progressive, multi-tier context compression (ANSI escape code removal, consecutive line deduplication, tool execution payload truncation with hash digests, assistant message trimming).
    • Compression telemetry and metrics reporting.
  3. Session Integration (\�gentcli/session.py):
    • Integrated \TokenBudgetGovernor\ into
      ecord_cost\ and \is_budget_exceeded.
    • Wired \AdaptiveContextCompressor\ into _trim_history.
  4. CLI & TUI Commands:
    • Enhanced /budget\ with [set | max-tokens | tier <low|med|high> | reset | status].
    • Formatted /cost\ and /tokens\ with governor statistics and breakdown.
    • Autocomplete support in \SlashAndFileCompleter\ and command dispatch in \TUIApp.
  5. Comprehensive Test Suite:
    • Added \ ests/test_phase35_token_governor.py\ with 11 focused test cases covering all components.

Quality Verification

  • Ruff: 0 errors
  • Mypy: 0 errors across 127 files
  • Tests: 100% passing across Phase 35, Session, CLI, Worktrees, and TUI test suites.

@De-pitcher
De-pitcher merged commit 22dfdee into main Sep 7, 2026
10 checks passed
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