The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): a provider-qualified -m selects that provider on both CLI entry paths
kshitijk4poor81cd8755b5e3
diff --git a/hermes_cli/model_switch.py b/hermes_cli/model_switch.pyindex 4f73230bc95..c91daac9a78 100644--- a/hermes_cli/model_switch.py+++ b/hermes_cli/model_switch.py@@ -385,7 +385,16 @@ def resolve_startup_model_route(return StartupModelRoute(model=direct.model, provider=alias_provider, base_url=direct.base_url, api_key=alias_key or "")- if explicit_provider or "/" not in raw:+ if explicit_provider:+ return None+ # ``custom:<name>:<model>`` / ``<provider>:<model>`` — the same qualified form ``/model``+ # accepts. Left undecoded, the configured default provider receives the unsplit string as+ # the model name and the whole prompt goes to its endpoint before it 404s (#73943).+ from hermes_cli.models import parse_model_input+ qualified_provider, qualified_model = parse_model_input(raw, "")+ if qualified_provider and qualified_model != raw:+ return StartupModelRoute(model=qualified_model, provider=qualified_provider)+ if "/" not in raw:return Noneprefix, model = (part.strip() for part in raw.split("/", 1))if not prefix or not model:diff --git a/hermes_cli/oneshot.py b/hermes_cli/oneshot.pyindex 524a6c2530e..c024926e371 100644--- a/hermes_cli/oneshot.py+++ b/hermes_cli/oneshot.py@@ -395,8 +395,8 @@ def _resolve_model_and_provider(cfg: dict, model: Optional[str], provider: Optio# DIRECT_ALIASES (config.yaml ``model_aliases:``) map a user alias to (model, provider,# base_url) for endpoints outside any catalog (local servers, custom proxies, ...).+ from hermes_cli import model_switch as _mstry:- from hermes_cli import model_switch as _ms_ms._ensure_direct_aliases()direct = _ms.DIRECT_ALIASES.get(explicit_model.strip().lower())except Exception:@@ -406,6 +406,15 @@ def _resolve_model_and_provider(cfg: dict, model: Optional[str], provider: Optioif isinstance(model_cfg, dict):cfg_provider = str(model_cfg.get("provider") or "").strip().lower()current_provider = cfg_provider or os.getenv("HERMES_INFERENCE_PROVIDER", "").strip().lower() or "auto"+ # Same owner as HermesCLI startup: a provider-qualified string (``custom:<name>:<model>``,+ # ``<provider>/<model>``) selects that provider before auto-detection can hand the unsplit+ # string to the configured default (#73943).+ route = _ms.resolve_startup_model_route(+ explicit_model, current_provider=current_provider,+ user_providers=cfg.get("providers"), custom_providers=cfg.get("custom_providers"))+ if route is not None:+ choice.provider, choice.model = route.provider, route.model+ return choicedetected = detect_provider_for_model(explicit_model, current_provider)if detected:choice.provider, choice.model = detecteddiff --git a/tests/hermes_cli/test_startup_model_routing.py b/tests/hermes_cli/test_startup_model_routing.pyindex ffa3b902a92..fcec1d29ff4 100644--- a/tests/hermes_cli/test_startup_model_routing.py+++ b/tests/hermes_cli/test_startup_model_routing.py@@ -1,5 +1,7 @@"""Regression tests for startup model/provider routing (#87189)."""+import pytest+from hermes_cli import model_switch@@ -149,3 +151,46 @@ def test_model_aliases_dict_entries_are_loaded(monkeypatch):assert aliases["localqwen"] == model_switch.DirectAlias("qwen3.5:4b", "custom", "http://localhost:11434/v1")+++def _write_named_provider(tmp_path, monkeypatch):+ """A ``providers:`` entry the user selects by the documented ``custom:<name>:<model>`` form."""+ home = tmp_path / "hermes-home"+ home.mkdir()+ (home / "config.yaml").write_text(+ "model:\n default: claude-sonnet-4-5\n provider: anthropic\n"+ "providers:\n jetson-vllm:\n base_url: http://127.0.0.1:8000/v1\n"+ " api_key: EMPTY\n api_mode: chat_completions\n models: [nemotron-nano-30b]\n"+ )+ monkeypatch.setenv("HERMES_HOME", str(home))+ monkeypatch.setattr(model_switch, "DIRECT_ALIASES", {})+ from hermes_cli.config import load_config+ return load_config()+++def test_startup_route_decodes_custom_colon_qualified_model(tmp_path, monkeypatch):+ """``custom:<name>:<model>`` selects the named provider instead of leaving the unsplit string+ to the configured default (#73943: the prompt went to api.anthropic.com before a 404)."""+ cfg = _write_named_provider(tmp_path, monkeypatch)+ route = model_switch.resolve_startup_model_route(+ "custom:jetson-vllm:nemotron-nano-30b", current_provider="anthropic",+ user_providers=cfg.get("providers"))+ assert route == model_switch.StartupModelRoute("nemotron-nano-30b", "custom:jetson-vllm", "")+ # A colon inside a plain model id is not a provider delimiter.+ assert model_switch.resolve_startup_model_route(+ "anthropic/claude-3.5-sonnet:beta", current_provider="anthropic",+ user_providers=cfg.get("providers")) is None+++def test_oneshot_qualified_model_never_reaches_default_provider(tmp_path, monkeypatch):+ """``hermes -z -m custom:<name>:<model>`` routes through the same startup owner, so provider+ auto-detection never hands the qualified string to the configured default (#73943)."""+ from hermes_cli.oneshot import _resolve_model_and_provider++ cfg = _write_named_provider(tmp_path, monkeypatch)+ monkeypatch.delenv("HERMES_INFERENCE_MODEL", raising=False)+ monkeypatch.setattr(+ "hermes_cli.models.detect_provider_for_model",+ lambda *_a, **_k: pytest.fail("auto-detection ran on a provider-qualified model"))+ choice = _resolve_model_and_provider(cfg, "custom:jetson-vllm:nemotron-nano-30b", None)+ assert (choice.provider, choice.model) == ("custom:jetson-vllm", "nemotron-nano-30b")