fix: Add duplicate response loop breaker to prevent infinite loops#1265
Open
gdeyoung wants to merge 1 commit intoagent0ai:mainfrom
Open
fix: Add duplicate response loop breaker to prevent infinite loops#1265gdeyoung wants to merge 1 commit intoagent0ai:mainfrom
gdeyoung wants to merge 1 commit intoagent0ai:mainfrom
Conversation
- Add duplicate_retries counter to track consecutive duplicate responses - Break loop after 3 consecutive identical responses with HandledException - Log error message when loop is broken - Reset duplicate_retries on successful iteration Fixes agent0ai#1056, agent0ai#1000 - Prevents agent from getting stuck in infinite loop when receiving 'You have sent the same message again' from external APIs
gdeyoung
pushed a commit
to gdeyoung/agent-zero
that referenced
this pull request
Mar 15, 2026
- Add duplicate_retries counter to track consecutive duplicate responses - Pass retry_count to fw.msg_repeat.md for context - Enhanced warning message with specific guidance on breaking loops - Provides 4 concrete alternatives when stuck in a loop - Reset duplicate_retries on successful iteration This addresses the ROOT CAUSE by giving the LLM: 1. Context (retry count) so it knows it's in a loop 2. Specific alternatives instead of generic 'do something else' 3. Self-correction capability before circuit breaker kicks in Works in conjunction with PR agent0ai#1265 (circuit breaker) for defense-in-depth. Related to agent0ai#1056, agent0ai#1000, agent0ai#1187, agent0ai#1011
Author
🚨 Report: Increased Looping After Today's UpdateAfter today's platform update, I'm experiencing significantly MORE looping issues where patterns get stuck, and it's happening EARLIER in chats. Evidence: Chat Session Restarts Today (March 25)
Key Finding: 3 restarts within 21 minutes (14:28 → 14:49) indicates severe looping/hang issues! Additional Warning on StartupSeeing this in Docker logs on startup: ManifestationThe loops manifest as:
RequestThis reinforces the NEED for the circuit breaker fix in this PR. Please prioritize review - this is actively impacting production use. Related: #1266 (Enhanced duplicate response guidance) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a duplicate response loop breaker to prevent the agent from getting stuck in infinite loops when receiving "You have sent the same message again" errors from external APIs.
Problem
The agent can get stuck in an infinite loop when:
Solution
duplicate_retriescounter to track consecutive duplicate responsesHandledExceptionduplicate_retrieson successful iterationChanges
agent.py: Added duplicate_retries counter and loop breaker logic (13 lines added)Testing
Tested by triggering duplicate response scenarios - agent now breaks out after 3 attempts with clear error message.
Related Issues
Fixes #1056
Fixes #1000
Related to #1187, #1011
Notes
This is a core code fix that cannot be solved through agent behavior changes alone, as the LLM is not in a coherent state during a loop to recognize and break the pattern.