dshx-loop-guard: Detecting and Halting Agent Tool Infinite Loops

Preface

When running local small models as Agents in DeepSeek Harness (DSH), a common failure occurs: the model repeatedly initiates calls with exactly the same “tool name + parameters,” receives the same result each time, yet the main loop cannot stop. This type of issue is not necessarily caused by the model’s capabilities, but rather by a lack of counting and circuit breaking for “same call, same result.”

dshx-loop-guard is a DSH workflow plugin published by community maintainer callaumyan-design. It only subscribes to DSH’s public agent/request, tools/pre-execute, and tools/post-execute events. Without altering the Agent’s main loop, it performs fingerprint comparison and threshold control before and after tool execution, thereby warning or rejecting continued calls when the configured upper limit is reached.

What is this

Plugin Repository: callaumyan-design/dshx-loop-guard. Directory Page: SkillHub Plugin Entry.

One-sentence positioning: Detects and stops Agent loops where “identical tool calls repeatedly yield completely identical results,” primarily targeting local small model scenarios. Implemented in pure JavaScript (index.js + cordis.patch.yml) with no build step required.

Determination Rules

Counting is performed per Agent and per “turn.” The rules from the README are as follows:

  1. Call Fingerprint: Tool name + parameters (key order is irrelevant).
  2. Same Result Repetition: When the same fingerprint consecutively yields completely identical results, a warning is appended to the result at the warnAt occurrence, and the call is directly rejected at the stopAt occurrence.
  3. Single Fingerprint Hard Limit: If the same fingerprint is executed hardLimit times within one turn (regardless of whether results are identical), it is rejected.
  4. Total Calls Per Turn: If the total number of tool calls within one turn exceeds maxCallsPerTurn, it is rejected; 0 means no limit.
  5. Rejection Count Limit: If rejections reach maxDenials times within one turn, the current turn is aborted.

Editing a file and then running the same test command is not considered a loop: because the result changes, the relevant counts will be reset to zero.

Configuration

The following fields can be modified in the plugin’s bundled cordis.patch.yml (effective via the plugin bundle after installation; specific merging methods depend on your current DSH / Cordis configuration).

Field Default Description
providers ['local'] Only effective for these providers; an empty array means effective for all models
warnAt 3 Append a warning when identical result repetition reaches this count
stopAt 5 Reject when identical result repetition reaches this count
hardLimit 12 Max execution times for the same fingerprint within one turn
maxCallsPerTurn 0 Max total tool calls per turn, 0 means unlimited
maxDenials 3 Max rejections per turn; aborts the turn upon reaching this limit

By default, it is only effective for the local provider; if you run Agents with other providers in Web or Desktop, you need to adjust providers according to the README.

Installation and Activation

The installation command must follow the original README text (choose one based on profile). DSH must be restarted after installation; requiresRestart in package.json is true.

# Web profile
dsh plugin --profile web add github:callaumyan-design/dshx-loop-guard
# Desktop (use the dsh command bundled with DSH Desktop; completely quit Desktop from the tray first)
dsh plugin --profile desktop add github:callaumyan-design/dshx-loop-guard

Uninstallation:

dsh plugin --profile <profile> remove dshx-loop-guard

package.json declares marketplace support for headless, web, and desktop profiles; the README installation examples only provide web and desktop. For headless, please refer to your environment documentation and select the corresponding profile using the same add github:... format.

Typical Usage

The plugin has no separate CLI examples: after installation and restart, simply run the Agent normally on your configured provider (default local). When the model falls into a loop of “same tool, same parameters, same result,” you will first see warnings after warnAt, followed by rejections or turn aborts triggered by stopAt or hardLimit / maxCallsPerTurn / maxDenials.

If you rely on “executing the same command multiple times until the output changes” (e.g., rerunning tests after code changes), as long as the tool return result differs from the previous turn, the count will be reset, and it will not be misjudged as a dead loop.

Applicable Scenarios and Notes

Who it is for: Primarily for those using local small models for tool-based Agents on DSH who have encountered situations with repeated identical calls (like read_file, grep) returning identical results.

Compatibility: The README specifies development and usage on DeepSeek Harness 0.2.0-rc.2 (desktop / web profile); plugin version 1.0.0, License MIT.

Security and Permissions: The plugin runs with the current DSH process privileges and can intercept or modify behavior on the tool execution path. It is recommended to read the Repository Source Code and License before installation to ensure it aligns with your workflow. The community directory site SkillHub has no official affiliation with DeepSeek / High-Flyer; the plugin source is subject to the GitHub repository.

Conclusion

dshx-loop-guard uses event hooks to perform circuit breaking for “same parameters, same result” and single-turn call limits. It does not alter the Agent’s main loop and is suitable for adding a configurable layer of loop protection for local small models. For installation commands and field default values, refer to the README.

  • Directory Page: https://www.skillhub.cn/plugins/callaumyan-design/dshx-loop-guard
  • GitHub: https://github.com/callaumyan-design/dshx-loop-guard
羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye