The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): retain auxiliary compression limit on model switch
KoNit-K8d51d488a41f
diff --git a/agent/agent_runtime_helpers.py b/agent/agent_runtime_helpers.pyindex a38c6edb138..8b85dc32cc4 100644--- a/agent/agent_runtime_helpers.py+++ b/agent/agent_runtime_helpers.py@@ -2058,6 +2058,13 @@ def _update_switch_compressor(agent, custom_providers, effective_context_length,provider=agent.provider,api_mode=agent.api_mode,)+ # A prior compression attempt may have lowered the live trigger to fit+ # its auxiliary summarizer. update_model() rightly recalibrates from+ # the new main model, so immediately reapply that feasibility guard+ # when it has already been resolved for this session.+ if getattr(agent, "_compression_feasibility_checked", False):+ from agent.conversation_compression import check_compression_model_feasibility+ check_compression_model_feasibility(agent)except Exception:_restore_switch_snapshot(agent, snapshot)raisediff --git a/tests/agent/test_switch_model_context.py b/tests/agent/test_switch_model_context.pyindex f7dff8d633b..e23652b93a7 100644--- a/tests/agent/test_switch_model_context.py+++ b/tests/agent/test_switch_model_context.py@@ -133,6 +133,48 @@ def test_switch_model_without_config_context_length():assert call_kwargs.get("config_context_length") is None+def test_switch_model_reapplies_checked_auxiliary_compression_limit():+ """A model switch retains the auxiliary compression model's safe trigger."""+ agent = _make_agent_with_compressor(config_context_length=200_000)+ agent.compression_enabled = True+ agent._compression_feasibility_checked = True+ agent._aux_compression_context_length_config = None+ agent._custom_providers = []+ agent._compression_warning = None+ agent._print_fn = None+ agent.log_prefix = ""+ agent.suppress_status_output = False+ agent._stream_consumers = []+ agent._executing_tools = False+ agent._mute_post_response = False+ agent.status_callback = None+ agent.tool_progress_callback = None+ agent.tools = []+ agent._emit_status = lambda _message: None+ agent._create_openai_client = lambda *_args, **_kwargs: MagicMock()++ aux_client = MagicMock(base_url="https://aux.example/v1", api_key="aux-key")+ with (+ patch(+ "agent.model_metadata.get_model_context_length",+ side_effect=[400_000, 80_000],+ ),+ patch(+ "agent.auxiliary_client.get_text_auxiliary_client",+ return_value=(aux_client, "auxiliary-model"),+ ),+ ):+ agent.switch_model(+ "larger-main-model",+ "openrouter",+ api_key="sk-new",+ base_url="https://openrouter.ai/api/v1",+ )++ assert agent.context_compressor.context_length == 400_000+ assert agent.context_compressor.threshold_tokens == 80_000++def test_switch_model_omitted_base_url_preserves_direct_openai_capability():"""A same-provider switch resolves capabilities from the retained URL."""agent = _make_agent_with_compressor(config_context_length=None)