Skip to content

The agent that grows with you

fix(gateway): preserve capabilities on model switches

Stephen Chinf245765a6d0d
diff --git a/gateway/slash_commands.py b/gateway/slash_commands.py
index 627ff37f0ea..bd86f0d96d5 100644
--- a/gateway/slash_commands.py
+++ b/gateway/slash_commands.py
@@ -2013,6 +2013,7 @@ class GatewaySlashCommandsMixin:
"base_url": result.base_url,
"api_mode": result.api_mode,
"request_overrides": dict(result.request_overrides or {}),
+ "capabilities": dict(result.runtime_capabilities or {}),
}
# Write-through the non-secret parts to the session
@@ -2327,6 +2328,7 @@ class GatewaySlashCommandsMixin:
"base_url": result.base_url,
"api_mode": result.api_mode,
"request_overrides": dict(result.request_overrides or {}),
+ "capabilities": dict(result.runtime_capabilities or {}),
}
if one_turn:
if not hasattr(self, "_pending_one_turn_model_restores"):
diff --git a/hermes_cli/model_switch.py b/hermes_cli/model_switch.py
index f2e72cbf0e1..2760965ba37 100644
--- a/hermes_cli/model_switch.py
+++ b/hermes_cli/model_switch.py
@@ -1850,6 +1850,7 @@ def switch_model(
api_key = current_api_key
base_url = current_base_url
api_mode = ""
+ runtime_capabilities: dict[str, bool] = {}
ollama_headers: dict[str, str] = {}
validation_headers: dict[str, str] = {}
suppress_ollama_headers = False
@@ -1894,6 +1895,7 @@ def switch_model(
api_key = runtime.get("api_key", "") or _ukey
base_url = runtime.get("base_url", "") or _user_pdef.base_url
api_mode = runtime.get("api_mode", "")
+ runtime_capabilities = runtime.get("capabilities") or {}
validation_headers = runtime.get("extra_headers") or validation_headers
except Exception:
api_key = _ukey
@@ -1912,6 +1914,7 @@ def switch_model(
api_key = runtime.get("api_key", "")
base_url = runtime.get("base_url", "")
api_mode = runtime.get("api_mode", "")
+ runtime_capabilities = runtime.get("capabilities") or {}
validation_headers = runtime.get("extra_headers") or validation_headers
except Exception as e:
return ModelSwitchResult(
@@ -1972,6 +1975,7 @@ def switch_model(
api_key = runtime.get("api_key", "")
base_url = runtime.get("base_url", "")
api_mode = runtime.get("api_mode", "")
+ runtime_capabilities = runtime.get("capabilities") or {}
validation_headers = runtime.get("extra_headers") or validation_headers
except Exception:
pass
@@ -2223,7 +2227,11 @@ def switch_model(
provider_label=provider_label,
resolved_via_alias=resolved_alias,
capabilities=capabilities,
- runtime_capabilities=runtime_capabilities,
+ runtime_capabilities={
+ key: value
+ for key, value in runtime_capabilities.items()
+ if isinstance(key, str) and isinstance(value, bool)
+ },
model_info=model_info,
is_global=is_global,
)
diff --git a/tests/gateway/test_model_switch_persistence.py b/tests/gateway/test_model_switch_persistence.py
index 151d98b1d0f..03926cb06f2 100644
--- a/tests/gateway/test_model_switch_persistence.py
+++ b/tests/gateway/test_model_switch_persistence.py
@@ -208,6 +208,7 @@ class TestOneTurnNeverPersisted:
api_key="sk-test",
base_url="https://openrouter.ai/api/v1",
api_mode="chat_completions",
+ runtime_capabilities={"openai_native_compaction": True},
provider_label="OpenRouter",
),
)
@@ -253,6 +254,9 @@ class TestOneTurnNeverPersisted:
assert result is not None and "gpt-5.5" in result
# In-memory override installed for the next turn + restore queued...
assert runner._session_model_overrides[sk]["model"] == "gpt-5.5"
+ assert runner._session_model_overrides[sk]["capabilities"] == {
+ "openai_native_compaction": True
+ }
assert sk in runner._pending_one_turn_model_restores
# ...but NEVER written through to the persistent session store.
runner.async_session_store.set_model_override.assert_not_awaited()