Skip to content

fix: Enhanced duplicate response guidance for self-correction#1266

Open
gdeyoung wants to merge 1 commit intoagent0ai:mainfrom
gdeyoung:fix/enhanced-duplicate-guidance-v2
Open

fix: Enhanced duplicate response guidance for self-correction#1266
gdeyoung wants to merge 1 commit intoagent0ai:mainfrom
gdeyoung:fix/enhanced-duplicate-guidance-v2

Conversation

@gdeyoung
Copy link
Copy Markdown

Summary

This PR addresses the ROOT CAUSE of duplicate message loops by providing the LLM with context and specific guidance to self-correct BEFORE the circuit breaker kicks in.

Problem

When the LLM gets stuck in a loop, it:

  1. Doesn't know it's in a loop (no context)
  2. Doesn't have specific guidance on alternatives

Solution

  1. Add retry count context - Pass to warning message so LLM knows its loop status
  2. Provide specific alternatives - 4 concrete approaches to break the loop:
    • If uncertain: Ask user for clarification
    • If stuck: Try different tool/approach
    • If blocked: Explain blocker and needs
    • If waiting: Report status instead of repeating
  3. Track duplicates - Counter for context (resets on success)

Changes

File Changes
+6 lines (counter, increment, reset, pass retry_count)
+14 lines (enhanced guidance with template)

How It Works

Relationship to PR #1265

Both PRs work together for defense-in-depth:

  1. First line of defense: Enhanced guidance (this PR)
  2. Last line of defense: Circuit breaker (PR fix: Add duplicate response loop breaker to prevent infinite loops #1265)

Testing

  • Warning now shows "attempt X/3" for context
  • LLM receives specific alternatives instead of generic "do something else"
  • Counter resets on successful iteration

Related Issues

Addresses root cause of #1056, #1000, #1187, #1011

Notes

This is a minimal, elegant fix that addresses the root cause without modifying core logic. The LLM now has the context and guidance it needs to break loops itself.

- 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant