diff --git a/ga.py b/ga.py index 4b8456ad..7a651069 100644 --- a/ga.py +++ b/ga.py @@ -266,6 +266,7 @@ def __init__(self, parent, last_history=None, cwd='./temp'): self.history_info = last_history if last_history else [] self.code_stop_signal = [] self._done_hooks = [] + self._blank_streak = 0 def _get_abs_path(self, path): if not path: return "" @@ -445,8 +446,13 @@ def do_no_tool(self, args, response): content = getattr(response, 'content', '') or "" thinking = getattr(response, 'thinking', '') or "" if not response or (not content.strip() and not thinking.strip()): + self._blank_streak += 1 + if self._blank_streak >= 3: + yield "[Error] LLM returned empty response 3 times consecutively. Aborting.\n" + return StepOutcome({}, next_prompt=None) yield "[Warn] LLM returned an empty response. Retrying...\n" return StepOutcome({}, next_prompt="[System] Blank response, regenerate and tooluse") + self._blank_streak = 0 if len(content) > 50 and ('[!!! 流异常中断' in content[-100:] or '!!!Error:' in content[-100:]): return StepOutcome({}, next_prompt="[System] Incomplete response. Regenerate and tooluse.") if 'max_tokens !!!]' in content[-100:]: