Skip to content

fix: cap consecutive empty LLM response retries to prevent infinite loop#225

Open
Kailigithub wants to merge 1 commit intolsdefine:mainfrom
Kailigithub:fix/empty-response-retry-cap
Open

fix: cap consecutive empty LLM response retries to prevent infinite loop#225
Kailigithub wants to merge 1 commit intolsdefine:mainfrom
Kailigithub:fix/empty-response-retry-cap

Conversation

@Kailigithub
Copy link
Copy Markdown

Summary

Added a consecutive empty response counter to prevent the agent from entering an infinite retry loop when the LLM consistently returns empty content.

Closes #201

Changes

  • ga.py: Added _blank_streak counter to GenericAgentHandler.__init__
  • ga.py: Modified do_no_tool() to track consecutive blank responses and abort after 3 failures

Details

Previously, when the LLM returned an empty response, do_no_tool would yield a warning and retry indefinitely (up to the max_turns=40 outer loop limit). This caused excessive API calls, cost waste, and log flooding with "LLM returned an empty response. Retrying..." messages.

The fix introduces a _blank_streak counter:

  • Increments on each consecutive empty response
  • Resets to 0 on any non-empty response
  • After 3 consecutive empty responses, returns next_prompt=None which signals the agent loop to exit gracefully

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.

一直循环打印:[Warn] LLM returned an empty response. Retrying...

1 participant