Skip to content

fix(agent): detect same-result tool loops even when args vary - #60285

Closed
isheng-eqi wants to merge 4 commits into
NousResearch:mainfrom
isheng-eqi:fix/tool-guardrails-same-result-detection
Closed

fix(agent): detect same-result tool loops even when args vary#60285
isheng-eqi wants to merge 4 commits into
NousResearch:mainfrom
isheng-eqi:fix/tool-guardrails-same-result-detection

Conversation

@isheng-eqi

@isheng-eqi isheng-eqi commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

The tool-loop guardrails only track _no_progress by signature (tool_name, canonical_args) and only for tools in idempotent_tools. This means loops where args vary but the result never changes slip through -- execute_code generating different code that all returns the same output, or vision_load reading the same image with different prompts. The session burns through its iteration budget with no guard activity.

Related Issue

Fixes #60084

Type of Change

  • Bug fix

Changes Made

  • agent/tool_guardrails.py: Add _same_result tracking keyed on (tool_name, result_hash) that applies to ALL tools. Warns when the same result is returned no_progress_warn_after times regardless of varying args. Existing signature-based _no_progress tracking is preserved for idempotent tools (exact-arg-repeat blocking).
  • tests/agent/test_tool_guardrails_same_result.py: 6 tests covering varying-args same-result, different results reset, hard stop integration, reset_for_turn

How to Test

  1. Create a loop where execute_code runs different code that all returns "done"
  2. Verify a guardrail warning fires after N identical results
  3. Verify the idempotent-tool exact-arg-repeat path still works

@alt-glitch alt-glitch added type/feature New feature or request comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint duplicate This issue or pull request already exists P3 Low — cosmetic, nice to have labels Jul 7, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #60087 — both add a content-hash result-repetition guardrail keyed on (tool_name, result_hash) to agent/tool_guardrails.py that fires for all tools on varying-args/fixed-result loops (#60084); they differ only in tracker field names. #60087 is the earliest open canonical version (siblings #60094/#60148/#60219/#60268 were also folded into it). Note: this PR also bundles ~8 unrelated files from a stacked branch — the unique change is only the _same_result axis in tool_guardrails.py.

@isheng-eqi

Copy link
Copy Markdown
Contributor Author

Closed — duplicate of #60087 which already provides the same fix. Keeping #60087 open.

@isheng-eqi isheng-eqi closed this Jul 7, 2026
@isheng-eqi isheng-eqi reopened this Jul 7, 2026
@isheng-eqi

Copy link
Copy Markdown
Contributor Author

Closing as planned — duplicate of #60087 which already provides the same fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint duplicate This issue or pull request already exists P3 Low — cosmetic, nice to have type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Tool-loop guardrails miss loops where args vary but the result never changes (incl. repeated multimodal results)

2 participants