The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(guardrails): identical-call streaks hard-stop any tool on unattended platforms
Teknium76648a7faf78
diff --git a/agent/tool_guardrails.py b/agent/tool_guardrails.pyindex 243a0c64aad..1c4951733ec 100644--- a/agent/tool_guardrails.py+++ b/agent/tool_guardrails.py@@ -632,6 +632,31 @@ class ToolCallGuardrailController:"Do not repeat it — change arguments, use a different tool, or ""proceed with what you have.]")+ # Hard-stop widening (#89069 / #100849 bundle): the per-turn+ # no-progress BLOCK above only covers tools in idempotent_tools, so+ # a model replaying the same successful `terminal`/`skill_view`+ # call with a byte-identical result ran until the iteration budget.+ # The consecutive-identical streak is tool-agnostic; when hard+ # stops are enabled, halt at the same idempotent_no_progress+ # threshold. Pollers stay exempt (an unchanged poll is progress).+ if (+ self.config.hard_stop_enabled+ and count >= self.config.no_progress_block_after+ and self._halt_decision is None+ ):+ self._halt_decision = ToolGuardrailDecision(+ action="halt",+ code="identical_call_streak_halt",+ message=(+ f"Stopped {tool_name}: the same call with identical arguments "+ f"returned the same result {count} times in a row. Stop "+ "repeating it unchanged; use the result already provided or "+ "change strategy."+ ),+ tool_name=tool_name,+ count=count,+ signature=signature,+ )stub = Noneif (diff --git a/hermes_cli/config_defaults.py b/hermes_cli/config_defaults.pyindex c6d72c5ac13..72bbadd3394 100644--- a/hermes_cli/config_defaults.py+++ b/hermes_cli/config_defaults.py@@ -821,6 +821,10 @@ DEFAULT_CONFIG = {"tool_loop_guardrails": {"warnings_enabled": True,"hard_stop_enabled": False,+ # Unattended gateway/cron platforms get hard stops by default (nobody+ # is present to /stop a model that ignores loop warnings); interactive+ # cli/tui/desktop/acp stay warning-only unless hard_stop_enabled.+ "non_interactive_hard_stop_enabled": True,"warn_after": {"exact_failure": 2,"same_tool_failure": 3,diff --git a/run_agent.py b/run_agent.pyindex 8d8789657e9..6ec67b2a4e1 100644--- a/run_agent.py+++ b/run_agent.py@@ -9003,6 +9003,13 @@ class AIAgent:function_result = append_toolguard_guidance(function_result, decision)if decision.should_halt:self._set_tool_guardrail_halt(decision)+ else:+ # observe_call may have raised the identical-call streak halt+ # (hard_stop_enabled, tool-agnostic) — surface it the same way.+ streak_halt = self._tool_guardrails.halt_decision+ if streak_halt is not None and streak_halt.code == "identical_call_streak_halt":+ function_result = append_toolguard_guidance(function_result, streak_halt)+ self._set_tool_guardrail_halt(streak_halt)if stall_notice:function_result = (function_result or "") + "\n\n" + stall_noticereturn function_resultdiff --git a/tests/agent/test_tool_guardrails.py b/tests/agent/test_tool_guardrails.pyindex 33331010627..70d07829f4a 100644--- a/tests/agent/test_tool_guardrails.py+++ b/tests/agent/test_tool_guardrails.py@@ -201,6 +201,49 @@ def test_mutating_or_unknown_tools_are_not_blocked_for_repeated_identical_succesassert controller.after_call("custom_tool", {"x": 1}, "ok", failed=False).action == "allow"+def test_identical_call_streak_halts_any_tool_when_hard_stop_enabled():+ # #89069 / #100849 bundle: a model replaying the same SUCCESSFUL+ # terminal/skill_view call with a byte-identical result is not covered by+ # the idempotent_tools no-progress block. The consecutive-identical+ # streak (observe_call) is tool-agnostic; under hard_stop it must halt.+ controller = ToolCallGuardrailController(+ ToolCallGuardrailConfig(hard_stop_enabled=True, no_progress_block_after=5)+ )+ args = {"command": "hermes config get memory.provider"}+ for i in range(1, 5):+ controller.after_call("terminal", args, "local\n", failed=False)+ controller.observe_call("terminal", args, "local\n", failed=False)+ assert controller.halt_decision is None, f"halted early at {i}"++ controller.after_call("terminal", args, "local\n", failed=False)+ controller.observe_call("terminal", args, "local\n", failed=False)+ halt = controller.halt_decision+ assert halt is not None and halt.should_halt+ assert halt.code == "identical_call_streak_halt"+ assert halt.tool_name == "terminal" and halt.count == 5+++def test_identical_call_streak_never_halts_when_hard_stop_disabled_or_for_pollers():+ soft = ToolCallGuardrailController(+ ToolCallGuardrailConfig(hard_stop_enabled=False, no_progress_block_after=2)+ )+ for _ in range(6):+ soft.observe_call("terminal", {"command": "ls"}, "a\nb\n", failed=False)+ assert soft.halt_decision is None # notice-only in interactive sessions++ hard = ToolCallGuardrailController(+ ToolCallGuardrailConfig(hard_stop_enabled=True, no_progress_block_after=2)+ )+ for _ in range(6):+ hard.observe_call("process_manage", {"action": "poll", "session_id": "p1"}, "running", failed=False)+ assert hard.halt_decision is None # an unchanged poll is legitimate progress++ # A changed result resets the streak.+ for i in range(6):+ hard.observe_call("terminal", {"command": "date"}, f"t{i}", failed=False)+ assert hard.halt_decision is None++diff --git a/website/docs/user-guide/configuration.md b/website/docs/user-guide/configuration.mdindex 2a0e1619ece..763297796e7 100644--- a/website/docs/user-guide/configuration.md+++ b/website/docs/user-guide/configuration.md@@ -1799,7 +1799,7 @@ This mirrors Claude Code's per-session WebSearch and subagent caps (v2.1.212), w### Runtime anti-stall guards-Complementing the failure-based guardrails above, `agent.stall_guards` (default `true`) enables two conservative runtime guards against wasted turns. First, an **identical-call loop breaker**: when the same tool is called 3+ consecutive times with identical arguments *and* returns an identical result, a short one-line notice is appended to that tool result telling the model not to repeat the call — it never blocks the call, and legitimately-repeatable pollers (`process`, `*_get_result`, `*_poll`) are exempt. Second, a **continue-intent recovery**: when the model ends a turn with no tool calls but its short reply trails off announcing an action ("Let me now update the file…"), Hermes re-prompts it to act via the same bounded continuation mechanism used for intent-ack recovery (max 2 re-prompts per turn). Both are cache-safe (notices are added at result construction, never retroactively) and can be disabled together:+Complementing the failure-based guardrails above, `agent.stall_guards` (default `true`) enables two conservative runtime guards against wasted turns. First, an **identical-call loop breaker**: when the same tool is called 3+ consecutive times with identical arguments *and* returns an identical result, a short one-line notice is appended to that tool result telling the model not to repeat the call — in warning-only sessions it never blocks the call, and legitimately-repeatable pollers (`process`, `*_get_result`, `*_poll`) are exempt. When hard stops are active (explicit `hard_stop_enabled`, or an unattended gateway/cron platform), the same streak also becomes a hard stop once it reaches `hard_stop_after.idempotent_no_progress` consecutive identical calls — for **any** tool, not just the read-only ones the `idempotent_no_progress` guardrail tracks — so a model replaying the same successful `terminal` or `skill_view` call is halted instead of running out the iteration budget (`identical_call_streak_halt`). Second, a **continue-intent recovery**: when the model ends a turn with no tool calls but its short reply trails off announcing an action ("Let me now update the file…"), Hermes re-prompts it to act via the same bounded continuation mechanism used for intent-ack recovery (max 2 re-prompts per turn). Both are cache-safe (notices are added at result construction, never retroactively) and can be disabled together:```yamlagent: