Skip to content

The agent that grows with you

fix(aux): read the Nous fast-model catalog with credentials, and filter it

Mariano Nicolini35e0d158615f
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py
index e371b0f6769..534b42184af 100644
--- a/agent/auxiliary_client.py
+++ b/agent/auxiliary_client.py
@@ -884,6 +884,18 @@ def _fast_model_from_catalog(provider_id: str) -> str:
# fetch below still works for the catalogs that allow it.
logger.debug("No credentials for %s catalog", provider_id, exc_info=True)
+ if not api_key and provider_id.strip().lower() == "nous":
+ # Nous is OAuth, so the api-key resolver above raises for it. An
+ # anonymous read returns the full catalog rather than the one the
+ # org may reach, and a model picked from it is refused at request
+ # time with model_blocked_by_org_policy.
+ try:
+ from hermes_cli.models import _resolve_nous_pricing_credentials
+
+ api_key, base_url = _resolve_nous_pricing_credentials()
+ except Exception:
+ logger.debug("No Nous credentials for catalog", exc_info=True)
+
if not base_url:
base_url = str(getattr(get_provider_profile(provider_id), "base_url", "") or "")
base_url = base_url.rstrip("/")
@@ -900,6 +912,18 @@ def _fast_model_from_catalog(provider_id: str) -> str:
return ""
ids = sorted((str(m) for m in catalog), key=_model_recency_key, reverse=True)
+ if provider_id.strip().lower() == "nous":
+ # The catalog's keys are a source of ids here, so the policy has to
+ # narrow them the same way it narrows the pickers' lists.
+ try:
+ from hermes_cli.models import (
+ nous_policy_allowed_ids,
+ restrict_to_nous_policy,
+ )
+
+ ids = restrict_to_nous_policy(ids, nous_policy_allowed_ids())
+ except Exception:
+ logger.debug("Nous policy filter unavailable", exc_info=True)
for family in _FAST_MODEL_FAMILIES:
for model_id in ids:
lowered = model_id.lower()
diff --git a/tests/hermes_cli/test_nous_policy_surfaces.py b/tests/hermes_cli/test_nous_policy_surfaces.py
index c8f4cc9d181..d3103c9619b 100644
--- a/tests/hermes_cli/test_nous_policy_surfaces.py
+++ b/tests/hermes_cli/test_nous_policy_surfaces.py
@@ -160,3 +160,44 @@ class TestRecommendedDefaultEndpoint:
def test_unrestricted_org_is_unaffected(self, monkeypatch, no_policy):
assert self._call(monkeypatch)["model"] == "vendor/blocked"
+
+
+class TestAuxiliaryFastModel:
+ """``_fast_model_from_catalog`` treats the catalog's keys as a source of
+ ids, so an anonymous read there can select a model the gateway refuses."""
+
+ def _pick(self, monkeypatch, *, catalog):
+ import agent.auxiliary_client as aux
+
+ seen: dict = {}
+
+ def _fake_fetch(*, api_key=None, base_url="", timeout=8.0, **_k):
+ seen["api_key"] = api_key
+ return {mid: {} for mid in catalog}
+
+ monkeypatch.setattr(
+ models_mod, "_resolve_nous_pricing_credentials",
+ lambda: ("sk-nous", "https://inference.example.com"),
+ )
+ monkeypatch.setattr(models_mod, "fetch_models_with_pricing", _fake_fetch)
+ picked = aux._fast_model_from_catalog("nous")
+ return picked, seen
+
+ def test_reads_the_catalog_with_nous_oauth_credentials(self, monkeypatch, no_policy):
+ """The api-key resolver raises for OAuth providers; without a fallback
+ the read goes out anonymous and returns the unfiltered catalog."""
+ _, seen = self._pick(monkeypatch, catalog=["vendor/haiku-fast"])
+ assert seen["api_key"] == "sk-nous"
+
+ def test_hidden_model_is_not_selected(self, monkeypatch, policy):
+ import agent.auxiliary_client as aux
+
+ monkeypatch.setattr(
+ models_mod, "nous_policy_allowed_ids", lambda **_k: {"vendor/allowed"}
+ )
+ monkeypatch.setattr(aux, "_FAST_MODEL_FAMILIES", ("vendor/",))
+ monkeypatch.setattr(aux, "_FAST_MODEL_EXCLUDE", ())
+ picked, _ = self._pick(
+ monkeypatch, catalog=["vendor/blocked", "vendor/allowed"]
+ )
+ assert picked == "vendor/allowed"