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.
This commit is contained in:
benbenwyb
2026-06-16 20:47:33 +08:00
committed by Teknium
parent 384fc4bf83
commit cd2d3089fb
2 changed files with 37 additions and 0 deletions
+2
View File
@@ -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",
+35
View File
@@ -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)