The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): surface why every init-time fallback entry refused
kokhlof6659596a067
diff --git a/agent/agent_init.py b/agent/agent_init.pyindex 9b18a3d9b76..2222e02e48f 100644--- a/agent/agent_init.py+++ b/agent/agent_init.py@@ -850,6 +850,7 @@ def _routed_client_kwargs(agent, fallback_model, _provider_timeout) -> Optional[# reach the chain instead of dying at init with a misleading "No LLM provider configured" error. See# #17929._explicit = (agent.provider or "").strip().lower()+ _refused_entries = []for _fb in _fallback_entries(fallback_model):try:from hermes_cli.fallback_config import resolve_entry_api_key@@ -860,19 +861,34 @@ def _routed_client_kwargs(agent, fallback_model, _provider_timeout) -> Optional[)except Exception as _fb_exc:logger.debug("Init-time fallback entry %s failed: %s", _fb.get("provider"), _fb_exc)+ _refused_entries.append((str(_fb.get("provider")), str(_fb_exc)))continue- if _fb_client is not None:- agent._fallback_activated = True- if str(_fb["provider"]).strip().lower() == "moa":- # The chokepoint handed back the preset's aggregator client, which only proves the- # preset resolves and its aggregator has credentials. A MoA entry means the preset- # itself (same as ``provider: moa`` in config), so bind the facade, not the aggregator.- from agent.moa_loop import bind_moa_runtime- bind_moa_runtime(agent, _fb["model"])- return None- agent.provider = _fb["provider"]- agent.model = _fb_model or _fb["model"]- return _client_kwargs_from_routed(_fb_client, _provider_timeout)+ if _fb_client is None:+ # The router returns None when no credentials are usable for the entry — a skip+ # that leaves no trace otherwise, hiding key-less fallback entries from the log.+ logger.debug(+ "Init-time fallback entry %s resolved no usable credentials",+ _fb.get("provider"),+ )+ _refused_entries.append((str(_fb.get("provider")), "no usable credentials"))+ continue+ agent._fallback_activated = True+ if str(_fb["provider"]).strip().lower() == "moa":+ # The chokepoint handed back the preset's aggregator client, which only proves the+ # preset resolves and its aggregator has credentials. A MoA entry means the preset+ # itself (same as ``provider: moa`` in config), so bind the facade, not the aggregator.+ from agent.moa_loop import bind_moa_runtime+ bind_moa_runtime(agent, _fb["model"])+ return None+ agent.provider = _fb["provider"]+ agent.model = _fb_model or _fb["model"]+ return _client_kwargs_from_routed(_fb_client, _provider_timeout)+ if _refused_entries:+ logger.warning(+ "No LLM provider configured: primary %r unresolvable and fallback entries refused: %s",+ agent.provider,+ "; ".join(f"{_p} ({_r})" for _p, _r in _refused_entries),+ )if _explicit and _explicit not in {"auto", "openrouter", "custom"}:# Explicit non-OpenRouter provider with no creds and no usable fallback: fail fast.from agent.auxiliary_unavailable import missing_provider_credentials_messagediff --git a/tests/agent/test_init_fallback_refusal_warning.py b/tests/agent/test_init_fallback_refusal_warning.pynew file mode 100644index 00000000000..3cdb8c3184d--- /dev/null+++ b/tests/agent/test_init_fallback_refusal_warning.py@@ -0,0 +1,81 @@+"""A fully-refusing init-time fallback ladder must say why at WARNING before dying.++One burned primary (an exhausted single-entry OpenRouter pool, for example) plus fallback+entries that cannot resolve credentials raises the generic ``No LLM provider configured``+RuntimeError. Without a WARNING naming each refused entry and its reason, the failure is+indistinguishable from actual config loss in gateway.log.+"""++import logging+from types import SimpleNamespace++import pytest+++def _agent():+ return SimpleNamespace(provider="openrouter", model="z-ai/glm-5.3-flash", base_url=None,+ api_key=None, _fallback_activated=False)+++_LADDER = [+ {"provider": "deepseek", "model": "deepseek-v4-pro"},+ {"provider": "kimi", "model": "kimi-k3"},+]+++def _refusing_router(monkeypatch):+ """Primary resolves no client; deepseek resolves none (missing key), kimi raises."""+ def _fake_resolve(provider, model=None, **kwargs):+ if provider == "kimi":+ raise RuntimeError("kimi auth handshake refused")+ return (None, None)++ monkeypatch.setattr("agent.auxiliary_client.resolve_provider_client", _fake_resolve)+ monkeypatch.setattr("hermes_cli.fallback_config.resolve_entry_api_key", lambda entry: None)+++def test_fully_refusing_ladder_warns_with_each_reason(tmp_path, monkeypatch, caplog):+ from agent import agent_init++ monkeypatch.setenv("HERMES_HOME", str(tmp_path))+ _refusing_router(monkeypatch)++ with caplog.at_level(logging.WARNING, logger="run_agent"):+ with pytest.raises(RuntimeError, match="No LLM provider configured"):+ agent_init._routed_client_kwargs(_agent(), _LADDER, 60)++ warnings = [r for r in caplog.records if r.levelno >= logging.WARNING]+ assert len(warnings) == 1+ text = warnings[0].getMessage()+ assert "openrouter" in text+ assert "deepseek" in text and "no usable credentials" in text+ assert "kimi" in text and "kimi auth handshake refused" in text+++def test_recovered_ladder_does_not_warn(tmp_path, monkeypatch, caplog):+ """An entry refusing while a later one serves the init is degraded config, not a failure."""+ from agent import agent_init++ monkeypatch.setenv("HERMES_HOME", str(tmp_path))++ class _Client:+ pass++ def _fake_resolve(provider, model=None, **kwargs):+ if provider == "kimi":+ return (_Client(), model)+ return (None, None)++ monkeypatch.setattr("agent.auxiliary_client.resolve_provider_client", _fake_resolve)+ monkeypatch.setattr("hermes_cli.fallback_config.resolve_entry_api_key", lambda entry: None)+ monkeypatch.setattr(agent_init, "_client_kwargs_from_routed",+ lambda client, timeout: {"api_key": "k"})++ agent = _agent()+ with caplog.at_level(logging.WARNING, logger="run_agent"):+ kwargs = agent_init._routed_client_kwargs(agent, _LADDER, 60)++ assert kwargs == {"api_key": "k"}+ assert agent.provider == "kimi"+ assert agent._fallback_activated+ assert not [r for r in caplog.records if r.levelno >= logging.WARNING]