Skip to main content

resolve_context_window

Function resolve_context_window 

Source
pub fn resolve_context_window(model: &str) -> usize
Expand description

Resolve the real context-window size (in tokens) for a model slug.

Why: #2308 — CompactionConfig::default()’s flat token_threshold: 6_000 is model-blind: ~3% of Bedrock Claude Sonnet’s real 200K-token window, so ordinary coding turns (post-#2261 tool-call-arg counting) blow through it constantly and trigger pathological re-compaction. Compaction must instead scale with the model actually in use, which means a resolver is needed alongside resolve_model to turn a slug into a window size before crate::agent_loop::CompactionConfig::for_context_window can compute a proportional threshold. What: A minimal substring/format table, checked in order: (1) any slug containing claude-sonnet or claude-opus (covers both the bare Anthropic slug and the Bedrock-routed bedrock/us.anthropic.claude-sonnet-4-6 / -opus-* inference-profile format, see crate::llm::bedrock::bedrock_model_id) -> 200,000; (2) any slug beginning with the atlascloud/ routing prefix -> 1,050,000 (#2536 — AtlasCloud’s catalog default openai/gpt-5.6-sol has a 1.05M-token window, keyed off the routing prefix rather than the nested model id so the whole AtlasCloud family gets the large window); (3) any slug containing gpt-4o -> 128,000; else (4) DEFAULT_CONTEXT_WINDOW. Deliberately NOT a config file or per-agent override — the window size is a property of the model itself, not something an operator should need to tune per project. Test: routing::tests::resolve_context_window_maps_bedrock_sonnet_to_200k, routing::tests::resolve_context_window_maps_atlascloud_to_1m, routing::tests::resolve_context_window_falls_back_to_default_for_unknown_model.