Skip to content

Repeated identical local tool calls should be blocked to prevent infinite reasoning loops #3699

@andrew-ellis-engineering

Description

Summary

Nanobot currently guards repeated external lookups (for example web_fetch and web_search) but does not guard repeated identical local tool calls in the same turn.

In practice, this can produce loops where the model reissues the same local call with unchanged arguments until cancellation or max_iterations.

Reproduction Pattern

Examples of repeated identical local calls:

  • read_file(path=...)
  • list_dir(path=...)
  • glob(pattern=...)
  • grep(pattern=...)

The same (tool_name, args) signature can repeat many times with no new signal.

Expected Behavior

Nanobot should short-circuit repeated identical local calls in a single turn after a small retry budget.

Proposed Scope

Initial guarded tools:

  • read_file
  • list_dir
  • glob
  • grep

Behavior:

  1. Normalize a signature from tool_name + normalized args
  2. Count repeats within one turn
  3. Allow a small retry budget (for example 2-3)
  4. After threshold, return synthetic tool error:
    Error: repeated identical tool call blocked. Use the prior result or choose a different tool.
  5. Emit warning log with tool, abbreviated signature, attempt count

Suggested Implementation Area

  • nanobot/agent/runner.py
  • optionally shared helper in nanobot/utils/runtime.py

Test Expectations

  • Repeated identical read_file is blocked after threshold
  • Repeated identical glob is blocked after threshold
  • Repeated identical grep is blocked after threshold
  • Different arguments remain allowed
  • Existing external lookup guard behavior remains unchanged

Notes

This issue is intended as a general core safety fix, not workflow-specific behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions