feat: smart budget fraction for extended context windows#5
Open
sadlilas wants to merge 1 commit intomicrosoft:mainfrom
Open
feat: smart budget fraction for extended context windows#5sadlilas wants to merge 1 commit intomicrosoft:mainfrom
sadlilas wants to merge 1 commit intomicrosoft:mainfrom
Conversation
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>
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
When
context_window > 200k(e.g. Anthropic 1M beta), use fraction-based budgeting instead of the standardcontext_window - reserved_output - safety_marginformula.Default
extended_context_budget_fraction = 0.15keeps 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)EXTENDED_CONTEXT_THRESHOLD = 200_000andDEFAULT_EXTENDED_BUDGET_FRACTION = 0.15extended_context_budget_fraction(float, default 0.15)_calculate_budget()with an extended-context branch in both theget_model_info()and legacyget_info().defaultscode pathsBudget Math
200k - (16k * 0.5) - 1k1M * 0.15 - 1k1M * 0.20 - 1kcontext-persistent Coverage
context-persistentinherits fromSimpleContextManagerand delegatesget_messages_for_request()tosuper(). The_calculate_budget()method lives entirely in context-simple. This fix covers both modules with no changes needed in context-persistent.Test Results
test_tool_result_truncation_phase1) confirmed failing on main before this changeRelated
Closes microsoft-amplifier/amplifier-support#57