Skip to content

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

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

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

Conversation

@Kailigithub
Copy link
Copy Markdown
Contributor

Closes #201

Summary

Issue #201 reports that the agent enters an infinite retry loop when the LLM returns empty responses, continuously printing [Warn] LLM returned an empty response. Retrying... without any upper bound.

Root Cause

do_no_tool() in ga.py returns a StepOutcome with a retry prompt whenever the LLM response is empty. The agent loop (agent_runner_loop) then re-invokes the LLM, which can produce another empty response, creating an unbounded cycle until max_turns (40) is exhausted.

Fix

  • Added a consecutive empty response counter (_consecutive_empty_retries) to GenericAgentHandler
  • After 3 consecutive empty responses, the loop breaks by returning StepOutcome({}, next_prompt=None) instead of a retry prompt
  • The counter resets on any non-empty response
  • Retry messages now show progress: Retrying (1/3)..., Retrying (2/3)..., etc.

Changes

  • ga.py__init__: added _consecutive_empty_retries = 0
  • ga.pydo_no_tool(): capped retries at 3, added counter reset on valid response

Verification

✓ python3 -m py_compile ga.py — no syntax errors
✓ ruff check ga.py — no new lint issues (existing project-level warnings unchanged)
✓ 8 lines added, 1 removed — surgical change, no collateral modification

@lsdefine
Copy link
Copy Markdown
Owner

lsdefine commented May 2, 2026

Thanks for identifying this issue. We've implemented a simpler fix on our end. Closing this PR.

@lsdefine lsdefine closed this May 2, 2026
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...

2 participants