Skip to content

The agent that grows with you

fix(cli): use custom provider default_model when --provider is set

Christopherd6688adcc21a
diff --git a/cli.py b/cli.py
index 7534cf7f8bc..39faa07c339 100644
--- a/cli.py
+++ b/cli.py
@@ -4856,6 +4856,21 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin, CLIBillingMixin):
or os.getenv("HERMES_INFERENCE_PROVIDER")
or "auto"
)
+ # `--provider <custom>` without `-m` must use that entry's
+ # default_model. Otherwise the global model.default is sent to the
+ # custom endpoint and the compressor inherits the wrong context
+ # length (#86978). Explicit `-m` still wins.
+ if not model and provider:
+ try:
+ from hermes_cli.runtime_provider import _get_named_custom_provider
+
+ _named_custom = _get_named_custom_provider(provider)
+ except Exception:
+ _named_custom = None
+ _provider_default = str((_named_custom or {}).get("model") or "").strip()
+ if _provider_default:
+ self.model = _provider_default
+ self._model_is_default = False
self._provider_source: Optional[str] = None
self.provider = self.requested_provider
self.api_mode = "chat_completions"
diff --git a/tests/cli/test_cli_provider_resolution.py b/tests/cli/test_cli_provider_resolution.py
index d6613f76c86..3d5b60fc2f8 100644
--- a/tests/cli/test_cli_provider_resolution.py
+++ b/tests/cli/test_cli_provider_resolution.py
@@ -123,6 +123,66 @@ def _import_cli():
return importlib.import_module("cli")
+def test_provider_flag_uses_named_custom_default_model(monkeypatch):
+ """`--provider <custom>` without `-m` uses that entry's default_model (#86978)."""
+ cli = _import_cli()
+ monkeypatch.setitem(
+ cli.CLI_CONFIG,
+ "model",
+ {"default": "tencent/hy3:free", "provider": "nous"},
+ )
+ config = {
+ "model": {"default": "tencent/hy3:free", "provider": "nous"},
+ "providers": {
+ "gmk-lan": {
+ "name": "GMK Local",
+ "base_url": "http://gmk.lan:9931/v1",
+ "api_key": "not-needed",
+ "default_model": "/models/gemma.gguf",
+ }
+ },
+ }
+ monkeypatch.setattr("hermes_cli.config.load_config", lambda: config)
+ monkeypatch.setattr("hermes_cli.runtime_provider.load_config", lambda: config)
+
+ shell = cli.HermesCLI(provider="gmk-lan", compact=True, max_turns=1)
+
+ assert shell.model == "/models/gemma.gguf"
+ assert shell.requested_provider == "gmk-lan"
+
+
+def test_explicit_model_wins_over_provider_default_model(monkeypatch):
+ """`-m` still wins when `--provider` also names a custom default_model."""
+ cli = _import_cli()
+ monkeypatch.setitem(
+ cli.CLI_CONFIG,
+ "model",
+ {"default": "tencent/hy3:free", "provider": "nous"},
+ )
+ config = {
+ "model": {"default": "tencent/hy3:free", "provider": "nous"},
+ "providers": {
+ "gmk-lan": {
+ "name": "GMK Local",
+ "base_url": "http://gmk.lan:9931/v1",
+ "api_key": "not-needed",
+ "default_model": "/models/gemma.gguf",
+ }
+ },
+ }
+ monkeypatch.setattr("hermes_cli.config.load_config", lambda: config)
+ monkeypatch.setattr("hermes_cli.runtime_provider.load_config", lambda: config)
+
+ shell = cli.HermesCLI(
+ provider="gmk-lan",
+ model="explicit-id",
+ compact=True,
+ max_turns=1,
+ )
+
+ assert shell.model == "explicit-id"
+
+
def test_hermes_cli_init_does_not_eagerly_resolve_runtime_provider(monkeypatch):
cli = _import_cli()
calls = {"count": 0}