The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(auth): missing-credential hints name the real env var or the OAuth login (#114405, #78996)
liuhao1024a0562d17d851
diff --git a/agent/agent_init.py b/agent/agent_init.pyindex 800f216782e..ab02e5bffad 100644--- a/agent/agent_init.py+++ b/agent/agent_init.py@@ -857,18 +857,8 @@ def _routed_client_kwargs(agent, fallback_model, _provider_timeout) -> Optional[return _client_kwargs_from_routed(_fb_client, _provider_timeout)if _explicit and _explicit not in {"auto", "openrouter", "custom"}:# Explicit non-OpenRouter provider with no creds and no usable fallback: fail fast.- # Use the provider's real env var name (alibaba → DASHSCOPE_API_KEY).- _env_hint = f"{_explicit.upper()}_API_KEY"- with suppress(Exception):- from hermes_cli.auth import PROVIDER_REGISTRY- _pcfg = PROVIDER_REGISTRY.get(_explicit)- if _pcfg and _pcfg.api_key_env_vars:- _env_hint = _pcfg.api_key_env_vars[0]- raise RuntimeError(- f"Provider '{_explicit}' is set in config.yaml but no API key "- f"was found. Set the {_env_hint} environment "- f"variable, or switch to a different provider with `hermes model`."- )+ from agent.auxiliary_unavailable import missing_provider_credentials_message+ raise RuntimeError(missing_provider_credentials_message(_explicit))from hermes_constants import profile_cli_selector_sel = profile_cli_selector()raise RuntimeError(diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.pyindex aee6e7d9228..d058ca68704 100644--- a/agent/auxiliary_client.py+++ b/agent/auxiliary_client.py@@ -121,8 +121,8 @@ from agent.auxiliary_health import (fallback_candidate_unavailable_reason,)from agent.auxiliary_unavailable import (- AuxiliaryClientUnavailable, clear_nous_credential_failure, nous_credential_failure_detail,- record_nous_credential_failure)+ AuxiliaryClientUnavailable, clear_nous_credential_failure, missing_provider_credentials_message,+ nous_credential_failure_detail, record_nous_credential_failure)from hermes_constants import OPENROUTER_BASE_URL, hermes_home_keyfrom utils import base_url_host_matches, base_url_hostname, base_url_origin, env_float, is_truthy_value, model_forces_max_completion_tokens, normalize_proxy_env_vars@@ -7050,10 +7050,8 @@ def _resolve_call_client(task, _explicit)if fb_client is None:nous_detail = nous_credential_failure_detail() if _explicit == "nous" else None- raise AuxiliaryClientUnavailable(nous_detail or (- f"Provider '{_explicit}' is set in config.yaml but no API key was found. "- f"Set the {_explicit.upper()}_API_KEY environment variable, or switch to "- f"a different provider with `hermes model`."))+ raise AuxiliaryClientUnavailable(+ nous_detail or missing_provider_credentials_message(_explicit))client, final_model = fb_client, fb_modelif async_mode:client, final_model = _to_async_client(diff --git a/agent/auxiliary_unavailable.py b/agent/auxiliary_unavailable.pyindex 6243ea459b7..f7cd93cef89 100644--- a/agent/auxiliary_unavailable.py+++ b/agent/auxiliary_unavailable.py@@ -51,6 +51,33 @@ def _sentence(text: object) -> str:return str(text).strip().rstrip(".") + "."+def missing_provider_credentials_message(provider_id: str) -> str:+ """The "Provider 'X' is set in config.yaml but …" error for an explicit provider with no credentials.++ The remedy comes from the registry, never from the provider id: ``f"{id.upper()}_API_KEY"``+ invents names nothing reads (alibaba → ALIBABA_API_KEY instead of DASHSCOPE_API_KEY, and the+ unsettable MINIMAX-OAUTH_API_KEY for OAuth ids, #114405 / #78996). OAuth providers have no key+ env var at all, so they are pointed at the sign-in command instead.+ """+ pconfig = None+ with contextlib.suppress(Exception):+ from hermes_cli.auth import PROVIDER_REGISTRY+ pconfig = PROVIDER_REGISTRY.get(provider_id)+ env_vars = tuple(getattr(pconfig, "api_key_env_vars", None) or ())+ problem, remedy = "no API key was found", ""+ if env_vars:+ remedy = f"Set the {env_vars[0]} environment variable"+ elif pconfig is None:+ remedy = f"Set the {provider_id.upper().replace('-', '_')}_API_KEY environment variable"+ elif str(pconfig.auth_type).startswith("oauth"):+ problem, remedy = "no credentials were found", f"Run `hermes auth add {provider_id}` to sign in"+ else:+ problem = "no credentials were found"+ switch = "switch to a different provider with `hermes model`."+ return (f"Provider '{provider_id}' is set in config.yaml but {problem}. "+ + (f"{remedy}, or {switch}" if remedy else switch.capitalize()))++def _nous_credential_present(exc: BaseException) -> bool:"""True when a Nous credential exists that failed — a coded error (``invalid_grant``, a quarantinemarker, ``refresh_failed``) or persisted Nous auth state. The uncoded "not logged into Nous Portal"diff --git a/agent/context_compressor.py b/agent/context_compressor.pyindex 5b0d6a2392a..d2cf2a9d802 100644--- a/agent/context_compressor.py+++ b/agent/context_compressor.py@@ -116,7 +116,9 @@ _SUMMARY_PERMANENT_QUOTA_MARKERS: tuple[str, ...] = ("out of credit", "out of extra usage",)-_SUMMARY_MISSING_CREDENTIAL_MARKERS: tuple[str, ...] = ("no api key was found", "no api key found")+_SUMMARY_MISSING_CREDENTIAL_MARKERS: tuple[str, ...] = (+ "no api key was found", "no api key found", "no credentials were found",+)_HYGIENE_PREAGENT_ONLY_COOLDOWN_MARKERS: tuple[str, ...] = ("session hygiene compression timed out", "hygiene compression deferred: turn-hold budget expired",diff --git a/contributors/emails/[email protected] b/contributors/emails/[email protected]new file mode 100644index 00000000000..4ba9141b1aa--- /dev/null+++ b/contributors/emails/[email protected]@@ -0,0 +1,2 @@+TUARAN+# PR #79007 salvagediff --git a/contributors/emails/[email protected] b/contributors/emails/[email protected]new file mode 100644index 00000000000..8e99a451eb1--- /dev/null+++ b/contributors/emails/[email protected]@@ -0,0 +1,2 @@+Chukwuebuka-2003+# PR #114410 salvagediff --git a/tests/agent/test_missing_provider_credentials_hint.py b/tests/agent/test_missing_provider_credentials_hint.pynew file mode 100644index 00000000000..26999d0c891--- /dev/null+++ b/tests/agent/test_missing_provider_credentials_hint.py@@ -0,0 +1,54 @@+"""The "no credentials" error for an explicit provider names a remedy that can actually work.++Deriving the env var from the provider id (``f"{id.upper()}_API_KEY"``) invents names nothing reads:+``MINIMAX-OAUTH_API_KEY`` for OAuth ids (#114405, #78996) and ``ALIBABA_API_KEY`` where the registry+reads ``DASHSCOPE_API_KEY``. Both the auxiliary ladder and main-agent init share one helper.+"""+import pytest+import yaml++from agent.auxiliary_unavailable import missing_provider_credentials_message+from hermes_cli.auth import PROVIDER_REGISTRY++[email protected]("provider, expected, forbidden", [+ ("minimax-oauth", "hermes auth add minimax-oauth", "MINIMAX-OAUTH_API_KEY"),+ ("alibaba", "Set the DASHSCOPE_API_KEY environment variable", "ALIBABA_API_KEY"),+])+def test_aux_ladder_names_registry_remedy_for_explicit_provider(tmp_path, monkeypatch, provider, expected, forbidden):+ """Real call_llm → ladder with the compression provider pinned and no credentials anywhere."""+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))+ for var in ("MINIMAX_API_KEY", "DASHSCOPE_API_KEY"):+ monkeypatch.delenv(var, raising=False)+ (tmp_path / "config.yaml").write_text(yaml.safe_dump({+ "model": {"provider": provider, "default": "test-model"},+ "auxiliary": {"compression": {"provider": provider, "model": "test-model"}},+ }), encoding="utf-8")+ from agent.auxiliary_client import call_llm+ from agent.auxiliary_unavailable import AuxiliaryClientUnavailable++ with pytest.raises(AuxiliaryClientUnavailable) as excinfo:+ call_llm(task="compression", messages=[{"role": "user", "content": "hi"}], max_tokens=5)+ assert expected in str(excinfo.value)+ assert forbidden not in str(excinfo.value)+++def test_main_init_shares_helper_and_no_registry_provider_gets_an_invented_env_var(tmp_path, monkeypatch):+ """agent_init raises the same text as the helper; no registry id yields a made-up ``<ID>_API_KEY``."""+ from types import SimpleNamespace++ from agent.agent_init import _routed_client_kwargs++ monkeypatch.setenv("HERMES_HOME", str(tmp_path))+ agent = SimpleNamespace(provider="minimax-oauth", model="m", base_url=None, api_key=None,+ _fallback_activated=False, _explicit_provider="minimax-oauth")+ with pytest.raises(RuntimeError, match=r"hermes auth add minimax-oauth"):+ _routed_client_kwargs(agent, None, 60)++ for pid, pconfig in PROVIDER_REGISTRY.items():+ invented = f"{pid.upper()}_API_KEY"+ message = missing_provider_credentials_message(pid)+ if invented in message:+ assert invented in pconfig.api_key_env_vars, (pid, message)+ if not pconfig.api_key_env_vars:+ assert "_API_KEY environment variable" not in message, (pid, message)diff --git a/website/docs/guides/minimax-oauth.md b/website/docs/guides/minimax-oauth.mdindex 0c0770252a7..ffc6aa10355 100644--- a/website/docs/guides/minimax-oauth.md+++ b/website/docs/guides/minimax-oauth.md@@ -210,6 +210,12 @@ The auth store has no credentials for `minimax-oauth`. You have not logged in ye**Fix:** run `hermes model` and select MiniMax (OAuth), or run `hermes auth add minimax-oauth`.+### "Provider 'minimax-oauth' is set in config.yaml but no credentials were found"++The main agent or an auxiliary task (compression, vision, …) is pinned to `minimax-oauth` and the auth store has no login. There is no `MINIMAX_API_KEY`-style environment variable for the OAuth provider — `MINIMAX_API_KEY` belongs to the plain API-key `minimax` provider.++**Fix:** run `hermes auth add minimax-oauth` to sign in, or switch that provider to `minimax` with an API key.+## Logging OutTo remove stored MiniMax OAuth credentials: