Skip to content

The agent that grows with you

fix(profiles): align model seed with provider resolution

Gille5fee8d77bf91
diff --git a/hermes_cli/profile_model_seed.py b/hermes_cli/profile_model_seed.py
index c026af9bef9..222f5a02185 100644
--- a/hermes_cli/profile_model_seed.py
+++ b/hermes_cli/profile_model_seed.py
@@ -1,7 +1,22 @@
"""Copy the model and its selected custom endpoint when creating an independent profile."""
+from hermes_cli.config import (
+ get_compatible_custom_providers,
+ is_provider_enabled,
+ providers_dict_to_custom_providers,
+)
from hermes_cli.providers import custom_provider_aliases
-from hermes_cli.config import is_provider_enabled
+from hermes_cli.runtime_provider_custom import _shadowed_by_builtin
+
+
+def _matches_custom_provider(requested: str, entries: list[dict]) -> bool:
+ return bool(
+ entries
+ and requested
+ in custom_provider_aliases(
+ entries[0]["name"], entries[0].get("provider_key", "")
+ )
+ )
def launch_model_seed(source_cfg: dict) -> dict:
@@ -15,19 +30,24 @@ def launch_model_seed(source_cfg: dict) -> dict:
return seed
requested = provider.strip().lower().replace(" ", "-")
providers = source_cfg.get("providers")
- for key, entry in providers.items() if isinstance(providers, dict) else ():
- if (
- isinstance(entry, dict)
- and is_provider_enabled(entry)
- and (entry.get("api") or entry.get("url") or entry.get("base_url"))
- and requested in custom_provider_aliases(entry.get("name") or key, key)
+ providers = providers if isinstance(providers, dict) else {}
+ exact = providers.get(provider)
+ # Exact config keys also carry built-in provider tuning, without an endpoint URL.
+ if isinstance(exact, dict) and is_provider_enabled(exact):
+ seed["providers"] = {provider: exact}
+ return seed
+ if not requested or requested == "auto" or _shadowed_by_builtin(requested):
+ return seed
+ for key, entry in providers.items():
+ if _matches_custom_provider(
+ requested, providers_dict_to_custom_providers({key: entry})
):
seed["providers"] = {key: entry}
return seed
custom_providers = source_cfg.get("custom_providers")
for entry in custom_providers if isinstance(custom_providers, list) else ():
- if isinstance(entry, dict) and requested in custom_provider_aliases(
- entry.get("name", ""), entry.get("provider_key", "")
+ if _matches_custom_provider(
+ requested, get_compatible_custom_providers({"custom_providers": [entry]})
):
seed["custom_providers"] = [entry]
return seed
diff --git a/tests/hermes_cli/test_profile_model_seed.py b/tests/hermes_cli/test_profile_model_seed.py
index 3d4d4182b59..5a96d49a9ab 100644
--- a/tests/hermes_cli/test_profile_model_seed.py
+++ b/tests/hermes_cli/test_profile_model_seed.py
@@ -15,16 +15,17 @@ from hermes_cli import runtime_provider
@pytest.mark.parametrize(
- "schema,provider",
+ "schema,provider,url_key",
[
- ("providers", "lab"),
- ("providers", "custom:lab"),
- ("providers", "custom:display-name"),
- ("custom_providers", "custom:display-name"),
+ ("providers", "lab", "base_url"),
+ ("providers", "custom:lab", "base_url"),
+ ("providers", "custom:display-name", "base_url"),
+ ("custom_providers", "custom:display-name", "base_url"),
+ ("providers", "custom:lab", "baseUrl"),
],
)
def test_fresh_profile_retains_resolvable_custom_endpoint(
- tmp_path, monkeypatch, schema, provider
+ tmp_path, monkeypatch, schema, provider, url_key
):
home = tmp_path / ".hermes"
home.mkdir()
@@ -33,7 +34,7 @@ def test_fresh_profile_retains_resolvable_custom_endpoint(
monkeypatch.setenv("LAB_TOKEN", "synthetic-secret")
endpoint = {
"name": "Display Name",
- "base_url": "http://127.0.0.1:11434/v1",
+ url_key: "http://127.0.0.1:11434/v1",
"api_key": "${LAB_TOKEN}",
"api_mode": "chat_completions",
}
@@ -57,12 +58,74 @@ def test_fresh_profile_retains_resolvable_custom_endpoint(
assert created["model"] == source["model"]
copied = get_compatible_custom_providers(created)
- assert [entry["base_url"] for entry in copied] == [endpoint["base_url"]]
+ assert [entry["base_url"] for entry in copied] == [endpoint[url_key]]
assert copied[0]["api_key"] == endpoint["api_key"]
monkeypatch.setattr(runtime_provider, "load_config", lambda: created)
resolved = runtime_provider._get_named_custom_provider(provider)
assert resolved is not None
- assert resolved["base_url"] == endpoint["base_url"]
+ assert resolved["base_url"] == endpoint[url_key]
source["model"] = {"provider": "nous", "default": "other-model"}
atomic_config_write(home / "config.yaml", source)
assert read_user_config_raw(profile / "config.yaml") == created
+
+
[email protected]("schema", ["providers", "custom_providers"])
[email protected]("provider", ["openrouter", "custom:openrouter"])
+def test_builtin_name_collision_only_copies_explicit_custom_selection(
+ tmp_path, monkeypatch, schema, provider
+):
+ home = tmp_path / ".hermes"
+ home.mkdir()
+ monkeypatch.setattr(Path, "home", lambda: tmp_path)
+ monkeypatch.setenv("HERMES_HOME", str(home))
+ endpoint = {
+ "name": "OpenRouter",
+ "base_url": "http://127.0.0.1:11434/v1",
+ "api_key": "synthetic-other-secret",
+ }
+ catalog = {"other-endpoint": endpoint} if schema == "providers" else [endpoint]
+ source = {
+ "model": {"provider": provider, "default": "synthetic-model"},
+ schema: catalog,
+ "_config_version": DEFAULT_CONFIG["_config_version"],
+ }
+ atomic_config_write(home / "config.yaml", source)
+ monkeypatch.setattr(runtime_provider, "load_config", lambda: source)
+ is_custom = provider.startswith("custom:")
+ assert (
+ runtime_provider._get_named_custom_provider(provider) is not None
+ ) is is_custom
+
+ profile = create_profile("sample-bot", no_alias=True, no_skills=True)
+ created = read_user_config_raw(profile / "config.yaml")
+
+ assert created["model"] == source["model"]
+ if is_custom:
+ copied = get_compatible_custom_providers(created)
+ assert [entry["base_url"] for entry in copied] == [endpoint["base_url"]]
+ assert copied[0]["api_key"] == endpoint["api_key"]
+ monkeypatch.setattr(runtime_provider, "load_config", lambda: created)
+ assert runtime_provider._get_named_custom_provider(provider) is not None
+ else:
+ assert "providers" not in created
+ assert "custom_providers" not in created
+
+
+def test_fresh_profile_keeps_explicit_builtin_provider_settings(tmp_path, monkeypatch):
+ home = tmp_path / ".hermes"
+ home.mkdir()
+ monkeypatch.setattr(Path, "home", lambda: tmp_path)
+ monkeypatch.setenv("HERMES_HOME", str(home))
+ source = {
+ "model": {"provider": "openrouter", "default": "synthetic-model"},
+ "providers": {"openrouter": {"request_timeout_seconds": 150}},
+ "_config_version": DEFAULT_CONFIG["_config_version"],
+ }
+ atomic_config_write(home / "config.yaml", source)
+
+ profile = create_profile("sample-bot", no_alias=True, no_skills=True)
+
+ assert (
+ read_user_config_raw(profile / "config.yaml")["providers"]
+ == source["providers"]
+ )