Skip to content

feat: smart budget fraction for extended context windows#5

Open
sadlilas wants to merge 1 commit intomicrosoft:mainfrom
sadlilas:feat/extended-context-budget-fraction
Open

feat: smart budget fraction for extended context windows#5
sadlilas wants to merge 1 commit intomicrosoft:mainfrom
sadlilas:feat/extended-context-budget-fraction

Conversation

@sadlilas
Copy link

Summary

When context_window > 200k (e.g. Anthropic 1M beta), use fraction-based budgeting instead of the standard context_window - reserved_output - safety_margin formula.

Default extended_context_budget_fraction = 0.15 keeps sessions in the standard pricing zone (~149k budget for 1M context) while using the extended window as a safety net against overflow errors.

What Changed

Single file: amplifier_module_context_simple/__init__.py (+45 lines)

  • Two module-level constants: EXTENDED_CONTEXT_THRESHOLD = 200_000 and DEFAULT_EXTENDED_BUDGET_FRACTION = 0.15
  • New config parameter extended_context_budget_fraction (float, default 0.15)
  • Modified _calculate_budget() with an extended-context branch in both the get_model_info() and legacy get_info().defaults code paths
  • Standard context windows (<= 200k) are completely unaffected

Budget Math

Context Window Formula Budget
200k (standard) 200k - (16k * 0.5) - 1k 191,000
1M (extended, 0.15) 1M * 0.15 - 1k 149,000
1M (extended, 0.20) 1M * 0.20 - 1k 199,000

context-persistent Coverage

context-persistent inherits from SimpleContextManager and delegates get_messages_for_request() to super(). The _calculate_budget() method lives entirely in context-simple. This fix covers both modules with no changes needed in context-persistent.

Test Results

  • 32/33 passed (local macOS + shadow environment Linux)
  • 1 pre-existing failure (test_tool_result_truncation_phase1) confirmed failing on main before this change
  • Direct budget calculation verification passed for all code paths (standard, extended, custom fraction, boundary, fallback)

Related

Closes microsoft-amplifier/amplifier-support#57

When context_window > 200k (e.g. Anthropic 1M beta), use fraction-based
budgeting instead of standard formula. Default 0.15 keeps sessions in
standard pricing zone while using extended window as safety net.

Closes microsoft-amplifier/amplifier-support#57

🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier)

Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
sadlilas added a commit to sadlilas/amplifier-module-context-simple that referenced this pull request Feb 21, 2026
Read context_budget_cap from provider defaults and cap the computed
budget. Providers with pricing cliffs (Anthropic, Gemini) set this to
keep sessions in the standard pricing zone while preserving the full
context window as a safety net. Providers without pricing cliffs
(OpenAI) don't set the key and are unaffected.

Applied in both the get_model_info() and get_info().defaults code paths.

Replaces the fraction-based approach (PR microsoft#5) which applied uniformly to
all providers regardless of their pricing model.

Related: microsoft-amplifier/amplifier-support#57

🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier)

Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
sadlilas added a commit to sadlilas/amplifier-module-context-simple that referenced this pull request Feb 22, 2026
Read context_budget_cap from provider defaults and cap the computed
budget. Providers with pricing cliffs (Anthropic, Gemini) set this to
keep sessions in the standard pricing zone while preserving the full
context window as a safety net. Providers without pricing cliffs
(OpenAI) don't set the key and are unaffected.

Applied in both the get_model_info() and get_info().defaults code paths.

Replaces the fraction-based approach (PR microsoft#5) which applied uniformly to
all providers regardless of their pricing model.

Related: microsoft-amplifier/amplifier-support#57

🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier)

Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
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