From 5f82e8d8959e7e985bf6b5ec912bc14062106245 Mon Sep 17 00:00:00 2001 From: Chris van Hoof Date: Sun, 31 May 2026 22:22:23 -0400 Subject: [PATCH] fix: persist resolved context_length after /model switch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After switch_model() clears _config_context_length to None so the new model can resolve its own context window, the display path in cli.py reads None and falls through to the 256K default for custom providers (LiteLLM, vertex-proxy, etc.) that don't match any probing step. The context compressor already resolves the correct value via get_model_context_length() — write it back to _config_context_length so the /model confirmation message shows the actual context window instead of the fallback. Fixes the display for all custom provider setups where the model's context length resolves via DEFAULT_CONTEXT_LENGTHS or live probes rather than config_context_length. Signed-off-by: Chris van Hoof --- agent/agent_runtime_helpers.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/agent/agent_runtime_helpers.py b/agent/agent_runtime_helpers.py index 73f3cba435df..86edfb0d9813 100644 --- a/agent/agent_runtime_helpers.py +++ b/agent/agent_runtime_helpers.py @@ -1544,6 +1544,13 @@ def switch_model(agent, new_model, new_provider, api_key='', base_url='', api_mo provider=agent.provider, api_mode=agent.api_mode, ) + # Persist the resolved context length so the /model display path + # (cli.py) can read it via getattr(agent, "_config_context_length"). + # Without this, the display always sees None (cleared at the top of + # switch_model) and falls through to the 256K default for custom + # providers that don't match any probe path. + if new_context_length and new_context_length > 0: + agent._config_context_length = new_context_length # ── Invalidate cached system prompt so it rebuilds next turn ── agent._cached_system_prompt = None