Unproductive Retry Loop
RULE-UNPRODUCTIVE-RETRY-LOOP: Detects retry storms that consume tokens and execution quotas without making forward progress.
Two or more consecutive retry attempts recorded without a subsequent intervening success event.
Sequential retry events for the same operation where the terminating event is either an error or process termination.
Enforce exponential backoff with jitter, define strict retry budgets (max 2), and abort execution before exhausting context tokens.
Rule Specification
Agents frequently get stuck in unproductive loops where the LLM repeats identical tool calls with identical parameters in a tight loop. Because each loop re-prompts the model, this consumes API tokens rapidly while keeping the agent completely blocked.
Detection Logic & Recovery Invariant
The deterministic rule tracks the active retry sequence. What constitutes recovery? A successful tool_result (status == 'completed') immediately resets the retry counter. If the sequence terminates without recovery, the rule fires.
Remediation Guide
- State Differentiation: Ensure the prompt context injects previous failure reasons so the LLM changes its query parameters instead of repeating identical arguments.
- Retry Budget: Cap total retries per tool invocation to 2.
- Jittered Backoff: Add randomized delay to avoid hammering rate-limited external servers.