The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(nous): heal a signed-in account's stale welcome-host route once before failing the turn
kshitijk4poor4a61b030b0bb
diff --git a/agent/turn_recovery.py b/agent/turn_recovery.pyindex aea24690b89..491201d18c9 100644--- a/agent/turn_recovery.py+++ b/agent/turn_recovery.py@@ -480,13 +480,21 @@ def _recover_format_errors(return False+_WELCOME_ROUTE_HEAL_COPY = {+ "anon_on_paid_host": "Reconnected to the free model's own route.",+ "named_on_welcome_host": "Reconnected to your Nous account's own route.",+}++def _recover_welcome_tier(agent: Any, classified: Any, _retry: TurnRetryState) -> bool:"""Two one-shot repairs for the Nous free tier, both silent on the wire and named once in chat.``model_not_free``: the session asked the welcome host for a model it does not serve; moveto the first alternate the gateway named (its own model) and retry, instead of failing the- turn. ``anon_on_paid_host``: this process is pointed at the paid host with a free-tier- identity (a stale route); re-read the credentials, which heals the URL, and retry.+ turn. ``anon_on_paid_host`` / ``named_on_welcome_host``: this process is pointed at the other+ identity's host (a stale route); re-read the credentials, which heals the URL, and retry. The+ refresh reports False when the store yields the same route, so a user-set+ ``NOUS_INFERENCE_BASE_URL`` falls straight through to the terminal copy.Reads the CLASSIFIER's context (``classified.error_context``): that is where``_nous_welcome_tier`` parks ``welcome_refusal`` / ``welcome_route``. The turn's other context@@ -508,14 +516,14 @@ def _recover_welcome_tier(agent: Any, classified: Any, _retry: TurnRetryState) -logger.info("%sNous free tier: moved %s -> %s after model_not_free", agent.log_prefix, requested, target)return Trueroute = ctx.get("welcome_route") if isinstance(ctx, dict) else None- if route == "anon_on_paid_host" and not _retry.welcome_route_heal_attempted:+ if route in _WELCOME_ROUTE_HEAL_COPY and not _retry.welcome_route_heal_attempted:_retry.welcome_route_heal_attempted = Truetry:healed = bool(agent._try_refresh_nous_client_credentials(force=True))except Exception:healed = Falseif healed:- _vlines(agent, "π Reconnected to the free model's own route. Retrying request...")+ _vlines(agent, f"π {_WELCOME_ROUTE_HEAL_COPY[route]} Retrying request...")return Truereturn Falsediff --git a/tests/agent/test_welcome_tier_recovery.py b/tests/agent/test_welcome_tier_recovery.pyindex 5976a065657..64124139b68 100644--- a/tests/agent/test_welcome_tier_recovery.py+++ b/tests/agent/test_welcome_tier_recovery.py@@ -119,6 +119,19 @@ class TestOneShotRecoveries:assert calls == [{"force": True}]assert _recover_welcome_tier(agent, classified, retry) is False+ def test_a_named_account_on_the_welcome_host_re_reads_the_route_once(self):+ from agent.turn_recovery import _recover_welcome_tier+ calls = []+ agent = _agent(api_key=make_jwt(account_tier="free", client_id="hermes-cli"),+ _try_refresh_nous_client_credentials=lambda **kw: calls.append(kw) or True)+ body = {"status": 400, "message": "This endpoint serves anonymous Hermes Agent accounts only. Use https://inference-api.nousresearch.com with your API key or signed-in account."}+ classified = classify_api_error(_gateway_error(400, body), provider="nous", base_url=WELCOME, api_key=agent.api_key)+ assert classified.error_context["welcome_route"] == "named_on_welcome_host"+ retry = TurnRetryState()+ assert _recover_welcome_tier(agent, classified, retry) is True+ assert calls == [{"force": True}]+ assert _recover_welcome_tier(agent, classified, retry) is False+def test_a_wrong_host_refusal_whose_heal_fails_falls_through(self):from agent.turn_recovery import _recover_welcome_tieragent = _agent(_try_refresh_nous_client_credentials=lambda **kw: False)