Model Tools & Guardrails

ToolGuardrails Tool Call Circuit Breaker & Infinite Loop Protection

Decrypting agent/tool_guardrails.py non-progressive dead-loop detection & synthetic intervention prompts
Dead-loop State Interception
📊 Figure 3-3-1: Loop Trajectory Detection & Tool Dead-loop Circuit Breaker State Transition

🚨 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.

Tool Call Chain Limitation
📊 Figure 3-3-2: Tool Interception Chain Execution, Prompt Intervention Append & Fallback Control Flow

🛡️ 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."