ToolGuardrails Tool Call Circuit Breaker & Infinite Loop Protection
🚨 1. Non-Progressive Dead-Loop Detection for Tool Calls
In complex agent execution, the model often stubbornly calls the same tool with identical parameters after parameter errors. agent/tool_guardrails.py defends against this:
The system maintains a sliding window hash record of tool calls. When it detects the same tool name, same input parameters, producing the same empty error output for 3+ consecutive times, it determines that the system has entered a dead-loop blocking state.
🛡️ 2. Synthetic Intervention Prompt Append
Once the dead-loop circuit breaker trips, the system does not crash. Instead, it calls append_toolguard_guidance() to forcibly inject a safety intervention command prefixed with System: at the head of the current tool message, warning the LLM: "This call is making no progress and is stuck. Please immediately change your strategy or report the stall reason to the user."