The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): reword SKILLS_GUIDANCE trigger and stop mislabelling its 400 as billing
Jack Lau6fbbe18be8e3
diff --git a/agent/conversation_loop.py b/agent/conversation_loop.pyindex 53524fc357d..bce2a519749 100644--- a/agent/conversation_loop.py+++ b/agent/conversation_loop.py@@ -542,13 +542,27 @@ def _billing_or_entitlement_message(if (provider or "").strip().lower() == "anthropic":lines = [(- f"{provider_label} reported that your Claude subscription usage is "+ f"{provider_label} reported that your Claude subscription usage may be "f"exhausted for {model_label} (included quota + extra-usage credits)."),"Options: wait for the billing cycle to reset, or add extra usage at ""https://claude.ai/settings/usage","You can also switch to an Anthropic API key or another provider with ""/model <model> --provider <provider>.",+ # This 400 is not proof of a billing problem. Anthropic returns the+ # same "out of extra usage" body when its server-side content filter+ # rejects part of the request on a subscription OAuth token, so the+ # message reliably misdirects diagnosis toward buying quota (#82154).+ # Say so here rather than asserting exhaustion the caller can't check.+ "If https://claude.ai/settings/usage still shows quota remaining, this is "+ "probably NOT a billing problem: on a Claude subscription (OAuth) token "+ "Anthropic returns this same message when its content filter rejects part "+ "of the request — typically a phrase in the system prompt.",+ # The exhaustion latch replays the stored error for ~60 min without+ # issuing a request, so a real fix looks like it didn't work.+ "Retry with a fresh credential state: `hermes auth reset anthropic`. Until "+ "that cooldown clears, this error can be replayed from cache without "+ "contacting the API.",]return "\n".join(lines)diff --git a/agent/prompt_builder.py b/agent/prompt_builder.pyindex a9e11c7abb7..ccfa217f4e4 100644--- a/agent/prompt_builder.py+++ b/agent/prompt_builder.py@@ -197,10 +197,21 @@ SESSION_SEARCH_GUIDANCE = ("asking them to repeat themselves.")+# NOTE (#82154): the opening sentence is worded deliberately. Anthropic's+# server-side content filter rejects the previous phrasing ("After completing a+# complex task (5+ tool calls), fixing a tricky error, or discovering a+# non-trivial workflow, save the approach as a skill with skill_manage so you+# can reuse it next time.") on subscription OAuth credentials, and surfaces that+# rejection as a billing-shaped HTTP 400 ("You're out of extra usage"), which+# sends users to buy quota they do not need. Bisected against the live API: that+# sentence alone reproduces the 400 and removing it alone clears it; size and+# the system[0] identity gate were both ruled out. The reword is empirically+# validated, not understood — if you rewrite this sentence, re-verify against a+# subscription OAuth token, not an sk-ant-api… key, which does not hit the+# filter.SKILLS_GUIDANCE = (- "After completing a complex task (5+ tool calls), fixing a tricky error, "- "or discovering a non-trivial workflow, save the approach as a "- "skill with skill_manage so you can reuse it next time.\n"+ "When you work out a non-trivial workflow, record it with skill_manage "+ "for future reuse.\n""When using a skill and finding it outdated, incomplete, or wrong, ""patch it immediately with skill_manage(action='patch') — don't wait to be asked. ""Skills that aren't maintained become liabilities.\n"diff --git a/hermes_cli/auth.py b/hermes_cli/auth.pyindex 3da395831f4..9f43d1ce3af 100644--- a/hermes_cli/auth.py+++ b/hermes_cli/auth.py@@ -395,6 +395,15 @@ PROVIDER_REGISTRY: Dict[str, ProviderConfig] = {name="Anthropic",auth_type="api_key",inference_base_url="https://api.anthropic.com",+ # CLAUDE_CODE_OAUTH_TOKEN is NOT an API key, despite auth_type="api_key"+ # and its place in this tuple (#82154). `claude setup-token` yields an+ # `sk-ant-oat01…` OAuth token: sent as `x-api-key` it 401s, and sent as a+ # bare Bearer it 429s. It is listed here because this tuple doubles as the+ # credential-DISCOVERY list (agent/credential_pool.py builds its env scan+ # from it), so removing it would stop Hermes finding a setup-token+ # credential at all. The adapter routes such a value down the OAuth path+ # on the strength of its prefix, not on this entry. Only ANTHROPIC_API_KEY+ # and ANTHROPIC_TOKEN are usable as literal API keys.api_key_env_vars=("ANTHROPIC_API_KEY", "ANTHROPIC_TOKEN", "CLAUDE_CODE_OAUTH_TOKEN"),base_url_env_var="ANTHROPIC_BASE_URL",),diff --git a/tests/agent/test_anthropic_billing_guidance.py b/tests/agent/test_anthropic_billing_guidance.pyindex 142b8b04c2f..d76833e3241 100644--- a/tests/agent/test_anthropic_billing_guidance.py+++ b/tests/agent/test_anthropic_billing_guidance.py@@ -44,3 +44,65 @@ def test_non_anthropic_billing_guidance_unaffected():assert "claude.ai/settings/usage" not in msg# Generic path still surfaces the OpenRouter credits link.assert "openrouter.ai/settings/credits" in msg+++# ── #82154: the 400 is not proof of a billing problem ────────────────────────+# Anthropic returns this same "out of extra usage" body when its server-side+# content filter rejects part of the request on a subscription OAuth token.+# Asserting exhaustion outright cost one reporter three debugging sessions and+# sent them at the billing page. The guidance must name the other cause.+++def _anthropic_msg() -> str:+ return _billing_or_entitlement_message(+ capability="model access",+ provider="anthropic",+ base_url="https://api.anthropic.com",+ model="claude-opus-5",+ )+++def test_anthropic_guidance_names_the_content_filter_alternative():+ msg = _anthropic_msg().lower()+ assert "content filter" in msg+ # Must give the operator a way to tell the two apart, not just hedge.+ assert "still shows quota remaining" in msg+ assert "system prompt" in msg+++def test_anthropic_guidance_does_not_assert_exhaustion_as_fact():+ """The opening line must hedge. 'is exhausted' is the claim that misdirected+ diagnosis; 'may be exhausted' keeps the billing lead without asserting it."""+ first_line = _anthropic_msg().splitlines()[0].lower()+ assert "may be exhausted" in first_line+ assert "is exhausted" not in first_line+++def test_anthropic_guidance_warns_about_the_cached_exhaustion_replay():+ """After a failure the credential is latched exhausted for ~60 min and the+ stored error is replayed without issuing a request — so a real fix looks+ like it didn't work. Point at the reset before the user concludes that."""+ msg = _anthropic_msg()+ assert "hermes auth reset anthropic" in msg+ assert "without contacting the API" in msg+++def test_anthropic_guidance_keeps_the_billing_remedies():+ """The new caveats are additive — the original billing path stays intact."""+ msg = _anthropic_msg()+ assert "https://claude.ai/settings/usage" in msg+ assert "reset" in msg.lower()+ assert "/model" in msg+ assert "claude-opus-5" in msg+++def test_content_filter_caveat_is_anthropic_only():+ """A generic provider must not inherit Anthropic-specific classifier lore."""+ msg = _billing_or_entitlement_message(+ capability="model access",+ provider="openrouter",+ base_url="https://openrouter.ai/api/v1",+ model="anthropic/claude-opus-4.7",+ ).lower()+ assert "content filter" not in msg+ assert "hermes auth reset" not in msgdiff --git a/tests/agent/test_skills_guidance_content_filter.py b/tests/agent/test_skills_guidance_content_filter.pynew file mode 100644index 00000000000..ad23b83a47c--- /dev/null+++ b/tests/agent/test_skills_guidance_content_filter.py@@ -0,0 +1,95 @@+"""SKILLS_GUIDANCE must not carry the phrasing Anthropic's content filter rejects.++#82154: on a subscription OAuth credential, Anthropic's server-side content+filter rejected the first sentence of the built-in ``SKILLS_GUIDANCE`` prompt+and surfaced the rejection as ``HTTP 400 "You're out of extra usage."`` —+a billing-shaped message that sent users to buy quota they did not need.++Bisected against the live API against the full 71,721-char assembled prompt:+that sentence alone reproduced the 400, and removing it alone cleared it.+Size (20 KB of filler → 200) and the ``system[0]`` identity gate (a 429, not a+400) were both ruled out.++These tests pin the reword. They deliberately assert on the *trigger substrings*+rather than on an exact replacement string, so a future rewording is free to+change the prose as long as it does not reintroduce the rejected phrasing or+drop the behaviour the sentence exists to produce.+"""++from __future__ import annotations++import re++import pytest++from agent.prompt_builder import SKILLS_GUIDANCE+++# Substrings unique to the rejected sentence. The bisect showed the trigger+# survives removal of the "(5+ tool calls)" clause, so the clause alone is not+# a sufficient guard — the surrounding phrasing is pinned too.+REJECTED_FRAGMENTS = (+ "After completing a complex task",+ "5+ tool calls",+ "fixing a tricky error",+ "save the approach as a",+ "so you can reuse it next time",+)+++class TestRejectedPhrasingIsGone:+ @pytest.mark.parametrize("fragment", REJECTED_FRAGMENTS)+ def test_trigger_fragment_absent(self, fragment):+ assert fragment not in SKILLS_GUIDANCE, (+ f"{fragment!r} is part of the phrasing Anthropic's content filter "+ "rejects on subscription OAuth tokens (#82154)"+ )++ def test_first_sentence_is_the_verified_reword(self):+ # The reporter verified this replacement returns 200 where the original+ # returned 400. Pin the first line so a refactor can't silently revert it.+ first_line = SKILLS_GUIDANCE.split("\n", 1)[0]+ assert first_line == (+ "When you work out a non-trivial workflow, record it with skill_manage "+ "for future reuse."+ )+++class TestBehaviourIsPreserved:+ """The reword must not cost the prompt its meaning — it still has to tell+ the model to record workflows as skills and to patch stale ones."""++ def test_still_instructs_recording_a_workflow_as_a_skill(self):+ first_line = SKILLS_GUIDANCE.split("\n", 1)[0].lower()+ assert "skill_manage" in first_line+ assert "workflow" in first_line+ assert "reuse" in first_line++ def test_patch_stale_skills_sentence_untouched(self):+ assert "skill_manage(action='patch')" in SKILLS_GUIDANCE+ assert "Skills that aren't maintained become liabilities." in SKILLS_GUIDANCE++ def test_skill_safety_rule_block_untouched(self):+ # Guarded independently by tests/agent/test_ghost_skill_pruning.py; asserted+ # here too so a reword of the guidance can't quietly take the block with it.+ assert "## Skill Safety Rule" in SKILLS_GUIDANCE+ for rule in ("UNAVAILABLE", "RELOAD", "WAIT", "DEDUP"):+ assert rule in SKILLS_GUIDANCE++ def test_real_newlines_and_line_count_preserved(self):+ # test_ghost_skill_pruning.py asserts count("\n") >= 6; the reword must+ # not drop a line separator on its way past that bound.+ assert "\\n" not in SKILLS_GUIDANCE+ assert SKILLS_GUIDANCE.count("\n") >= 6+++class TestGuidanceReachesTheSystemPrompt:+ def test_guidance_is_wired_into_tool_guidance(self):+ # A reword is worthless if the constant stopped being appended. Assert the+ # wiring rather than trusting the constant in isolation.+ import inspect++ import agent.system_prompt as system_prompt++ source = inspect.getsource(system_prompt)+ assert re.search(r"tool_guidance\.append\(\s*SKILLS_GUIDANCE\s*\)", source)diff --git a/website/docs/user-guide/features/skills.md b/website/docs/user-guide/features/skills.mdindex 40bf6d33dcd..79c693380df 100644--- a/website/docs/user-guide/features/skills.md+++ b/website/docs/user-guide/features/skills.md@@ -470,10 +470,12 @@ below lets you require human review before those changes land.### When the Agent Creates Skills-- After completing a complex task (5+ tool calls) successfully+The system prompt asks the agent to record a non-trivial workflow with `skill_manage` for+future reuse. In practice that covers:++- When it worked out a multi-step workflow worth repeating- When it hit errors or dead ends and found the working path- When the user corrected its approach-- When it discovered a non-trivial workflow### Actions