The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(nous): one is_anonymous_agent seam for the five identity reads
kshitijk4poorf7da523ae6bc
diff --git a/agent/error_classifier.py b/agent/error_classifier.pyindex f54f34f1b6c..c075e618145 100644--- a/agent/error_classifier.py+++ b/agent/error_classifier.py@@ -758,7 +758,7 @@ def classify_api_error(c = _Ctx(error, status_code, body, _build_error_msg(error, body), provider, model,approx_tokens, context_length, num_messages, str(base_url or ""),- is_anonymous_request(provider, api_key),+ anonymous=is_anonymous_request(provider, api_key),)verdict = next((v for v in (stage(c) for stage in _STAGES) if v is not None), _V_UNKNOWN)base = {"status_code": status_code, "provider": provider, "model": model, "message": _extract_message(error, body)}diff --git a/agent/turn_api_call.py b/agent/turn_api_call.pyindex a54d1d7b188..953a6843443 100644--- a/agent/turn_api_call.py+++ b/agent/turn_api_call.py@@ -244,11 +244,11 @@ def nous_rate_limit_guard(nous_rate_limit_remaining, format_remaining as _fmt_nous_remaining)from hermes_cli import anon_auth- _welcome = anon_auth.is_anonymous_request(agent.provider, getattr(agent, "api_key", None))- _nous_remaining = nous_rate_limit_remaining(anonymous=_welcome)+ _anonymous = anon_auth.is_anonymous_agent(agent)+ _nous_remaining = nous_rate_limit_remaining(anonymous=_anonymous)if _nous_remaining is not None and _nous_remaining > 0:reset = _fmt_nous_remaining(_nous_remaining)- if _welcome:+ if _anonymous:_nous_msg = anon_auth.FREE_TIER_RATE_LIMIT_CHAT.format(reset=anon_auth.friendly_wait(_nous_remaining))else:@@ -267,7 +267,7 @@ def nous_rate_limit_guard(# The free tier's sentence already says what to do (wait, or sign in); the# fallback-provider advice is for an install that runs its own providers.return _verdict("return", stamp_failure({- "final_response": (f"⏳ {_nous_msg}" if _welcome+ "final_response": (f"⏳ {_nous_msg}" if _anonymouselse f"⏳ {_nous_msg}\n\n{site_copy('nous_rate_limit')}"),"messages": messages,"api_calls": api_call_count,@@ -276,7 +276,7 @@ def nous_rate_limit_guard("error": _nous_msg,# The free tier's card body and its sign-in door (agent/error_surface.py).**({"free_tier": {"kind": "rate_limited", "message": anon_auth.FREE_TIER_RATE_LIMIT_CARD.format(- reset=anon_auth.friendly_wait(_nous_remaining))}} if _welcome else {}),+ reset=anon_auth.friendly_wait(_nous_remaining))}} if _anonymous else {}),}, FailoverReason.rate_limit.value, True))except Exception:pass # Never let rate guard break the agent loopdiff --git a/agent/turn_recovery.py b/agent/turn_recovery.pyindex e34020b9ec7..aea24690b89 100644--- a/agent/turn_recovery.py+++ b/agent/turn_recovery.py@@ -268,8 +268,8 @@ def _print_nous_401_diagnostics(agent: Any, api_error: Exception) -> None:if _body_text:_plines(agent, f" Response: {_body_text}")try:- from hermes_cli.anon_auth import is_anonymous_request- if is_anonymous_request(getattr(agent, "provider", ""), getattr(agent, "api_key", None)):+ from hermes_cli.anon_auth import is_anonymous_agent+ if is_anonymous_agent(agent):# The free tier has no credits, no agent key and no auth.json to inspect: its session# ended and could not be replaced. The two doors are a sign-in or another provider._plines(agent, " Your session ended and Hermes couldn't start a new one.",@@ -756,6 +756,7 @@ def _welcome_outage_copy(base_url: Any, classified: Any, *, anonymous: bool = Fafor every other route and for rate limits / billing, which have their own copy."""try:from hermes_cli.anon_auth import FREE_TIER_OUTAGE_COPY, route_is_welcome_host+ # Both: an anonymous JWT sent to a user-overridden paid host never reached the free model.if not anonymous or not route_is_welcome_host(base_url):return ""# Not ``unknown``: that is the classifier's catch-all for status-less local failures, which@@ -917,7 +918,7 @@ def max_retries_exhausted_result(guidance (the latter wins), persist, build the result with ``failure_reason`` /``failure_retryable`` / ``billing_block``."""# Result/guidance helpers stay in the loop module (tests import + patch them there).- from hermes_cli.anon_auth import is_anonymous_request+ from hermes_cli.anon_auth import is_anonymous_agentfrom agent.conversation_loop import (_billing_block_dict, _billing_or_entitlement_message, _billing_terminal_label,_print_billing_or_entitlement_guidance,@@ -1002,10 +1003,7 @@ def max_retries_exhausted_result(if _welcome_hint:_final_response = _welcome_tier_guidance(classified, model=model, in_chat=True)_free_tier_kind = _welcome_surface_kind(classified)- elif _outage := _welcome_outage_copy(- base_url, classified,- anonymous=is_anonymous_request(provider, getattr(agent, "api_key", None)),- ):+ elif _outage := _welcome_outage_copy(base_url, classified, anonymous=is_anonymous_agent(agent)):_final_response, _free_tier_kind = _outage, "outage"if _is_thinking_timeout:# Thinking-timeout guidance overrides stream-drop guidance, which would wrongly@@ -1427,8 +1425,8 @@ def _is_genuine_nous_rate_limit(agent: Any, api_error: Exception, error_context:is_genuine_nous_rate_limit, is_long_welcome_rate_limit, record_nous_rate_limit)_err_resp = getattr(api_error, "response", None)_err_hdrs = getattr(_err_resp, "headers", None) if _err_resp else None- from hermes_cli.anon_auth import is_anonymous_request- anonymous = is_anonymous_request(getattr(agent, "provider", ""), getattr(agent, "api_key", None))+ from hermes_cli.anon_auth import is_anonymous_agent+ anonymous = is_anonymous_agent(agent)_classified_ctx = getattr(classified, "error_context", None) or {}# Only an anonymous request's fairshare body is an allowance verdict; named# requests keep the exhausted-bucket rule, whatever their host or body says.diff --git a/agent/turn_response_check.py b/agent/turn_response_check.pyindex 3413024549e..f442155cfcd 100644--- a/agent/turn_response_check.py+++ b/agent/turn_response_check.py@@ -198,8 +198,8 @@ def check_api_response(if agent.provider == "nous":try:from agent.nous_rate_guard import clear_nous_rate_limit- from hermes_cli.anon_auth import is_anonymous_request- clear_nous_rate_limit(anonymous=is_anonymous_request(agent.provider, getattr(agent, "api_key", None)))+ from hermes_cli.anon_auth import is_anonymous_agent+ clear_nous_rate_limit(anonymous=is_anonymous_agent(agent))except Exception:passfrom agent import relay_llmdiff --git a/hermes_cli/anon_auth.py b/hermes_cli/anon_auth.pyindex ae10fb0c320..576bc4e59ed 100644--- a/hermes_cli/anon_auth.py+++ b/hermes_cli/anon_auth.py@@ -172,6 +172,11 @@ def is_anonymous_request(provider: Any, api_key: Any) -> bool:return provider == "nous" and _decode_jwt_claims(api_key).get("account_tier") == ANON_ACCOUNT_TIER+def is_anonymous_agent(agent: Any) -> bool:+ """:func:`is_anonymous_request` for a live agent: read at call time, since the credential rotates."""+ return is_anonymous_request(getattr(agent, "provider", ""), getattr(agent, "api_key", None))++def current_nous_state() -> Optional[Dict[str, Any]]:"""The profile's ``providers.nous`` state without locking or network (status/picker reads)."""from hermes_cli.auth import _load_auth_store, _load_provider_state