From cd2d3089fb4aad08a3b5e1e73b6584110fcf5775 Mon Sep 17 00:00:00 2001 From: benbenwyb Date: Tue, 16 Jun 2026 20:47:33 +0800 Subject: [PATCH] fix(agent): guard repeated skill reads Treat skill_view and skills_list as idempotent read-only tools so the existing no-progress guardrail can warn or block repeated identical skill loads. This prevents large skill outputs from being re-added to the context in tool loops. Add regression coverage for repeated skill_view results under hard-stop guardrails. --- agent/tool_guardrails.py | 2 ++ tests/agent/test_tool_guardrails.py | 35 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/agent/tool_guardrails.py b/agent/tool_guardrails.py index 777cb9775d..243a0c64aa 100644 --- a/agent/tool_guardrails.py +++ b/agent/tool_guardrails.py @@ -24,6 +24,8 @@ IDEMPOTENT_TOOL_NAMES = frozenset( "web_search", "web_extract", "session_search", + "skill_view", + "skills_list", "browser_snapshot", "browser_console", "browser_get_images", diff --git a/tests/agent/test_tool_guardrails.py b/tests/agent/test_tool_guardrails.py index 05c2560261..3333101062 100644 --- a/tests/agent/test_tool_guardrails.py +++ b/tests/agent/test_tool_guardrails.py @@ -154,6 +154,41 @@ def test_hard_stop_enabled_blocks_repeated_exact_failure_before_next_execution() +def test_skill_read_tools_are_idempotent_and_block_repeated_identical_success_output(): + cases = [ + ( + "skill_view", + {"name": "gui-agent-ml-operations"}, + '{"success":true,"name":"gui-agent-ml-operations","content":"same"}', + ), + ( + "skills_list", + {"category": "mlops"}, + '{"success":true,"skills":[{"name":"gui-agent-ml-operations"}]}', + ), + ] + + for tool_name, args, result in cases: + controller = ToolCallGuardrailController( + ToolCallGuardrailConfig( + hard_stop_enabled=True, + no_progress_warn_after=2, + no_progress_block_after=2, + ) + ) + + assert controller.before_call(tool_name, args).action == "allow" + assert controller.after_call(tool_name, args, result, failed=False).action == "allow" + assert controller.before_call(tool_name, args).action == "allow" + warn = controller.after_call(tool_name, args, result, failed=False) + assert warn.action == "warn" + assert warn.code == "idempotent_no_progress_warning" + + blocked = controller.before_call(tool_name, args) + assert blocked.action == "block" + assert blocked.code == "idempotent_no_progress_block" + + def test_mutating_or_unknown_tools_are_not_blocked_for_repeated_identical_success_output_by_default(): controller = ToolCallGuardrailController( ToolCallGuardrailConfig(no_progress_warn_after=2, no_progress_block_after=2)