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