Skip to content

feat: make context length configurable instead of hardcoded#753

Open
Coder-Wangyankun wants to merge 1 commit into
stakpak:mainfrom
Coder-Wangyankun:feat/configurable-context-length
Open

feat: make context length configurable instead of hardcoded#753
Coder-Wangyankun wants to merge 1 commit into
stakpak:mainfrom
Coder-Wangyankun:feat/configurable-context-length

Conversation

@Coder-Wangyankun

Copy link
Copy Markdown

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:

Parameter Type Default Description
context_window Option<u64> model's built-in Override context window size for budget calculations
context_budget_threshold Option<f32> 0.8 (80%) Fraction of window at which trimming triggers
keep_last_n_assistant_messages Option<usize> 5 Recent assistant messages preserved during trimming

Usage

REST API:

{
  "message": {"role": "user", "content": "hello"},
  "overrides": {
    "context_window": 200000,
    "context_budget_threshold": 0.95,
    "keep_last_n_assistant_messages": 20
  }
}

TOML profile:

[profiles.myprofile]
context_window = 200000
context_budget_threshold = 0.95
keep_last_n_assistant_messages = 20

SDK:

let config = AgentClientConfig::new()
    .with_context_window(200_000)
    .with_context_budget_threshold(0.95)
    .with_keep_last_n_assistant_messages(20);

Changes

14 files changed, 248 insertions, 9 deletions.

Backward Compatibility

Fully backward compatible — all new fields are Option with the original hardcoded values as defaults when not set.

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
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