feat: make context length configurable instead of hardcoded#753
Open
Coder-Wangyankun wants to merge 1 commit into
Open
feat: make context length configurable instead of hardcoded#753Coder-Wangyankun wants to merge 1 commit into
Coder-Wangyankun wants to merge 1 commit into
Conversation
Replace hardcoded context trimming parameters with user-configurable overrides, addressable via REST API, TOML profiles, or SDK builder methods. Three new parameters: - context_window: override the model's context window size for budget calc - context_budget_threshold: fraction of window at which trimming triggers - keep_last_n_assistant_messages: how many recent assistant messages to preserve during trimming (default: 5, was hardcoded) All three flow through every code path: - REST API (RunOverrides -> RunConfig -> session_actor) - Gateway/dispatcher (profile resolver -> RunOverrides -> HTTP) - CLI/TUI local path (AgentClientConfig -> TaskBoardContextHook) - TOML profile config (ProfileConfig -> AppConfig -> resolver) Previously hardcoded in session_actor.rs:272 and client/mod.rs:224-225. Closes stakpak#228
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
This PR addresses issue #228 — making context length a configurable parameter instead of keeping it hardcoded.
Problem
Previously, context trimming parameters were hardcoded in two locations:
session_actor.rs:272:BudgetAwareContextReducer::new(5, 0.8)client/mod.rs:224-225:keep_last_n_assistant_messages: Some(5),context_budget_threshold: Some(0.8)Users had no way to override the model's context window size for budget calculations, nor could they tune the trimming threshold or how many messages to preserve.
Solution
Three new user-configurable parameters, exposed through every code path:
context_windowOption<u64>context_budget_thresholdOption<f32>0.8(80%)keep_last_n_assistant_messagesOption<usize>5Usage
REST API:
{ "message": {"role": "user", "content": "hello"}, "overrides": { "context_window": 200000, "context_budget_threshold": 0.95, "keep_last_n_assistant_messages": 20 } }TOML profile:
SDK:
Changes
14 files changed, 248 insertions, 9 deletions.
Backward Compatibility
Fully backward compatible — all new fields are
Optionwith the original hardcoded values as defaults when not set.