From 475c203ea103daa77bd85e178c5e9f3cbf4011b8 Mon Sep 17 00:00:00 2001 From: pys306 Date: Mon, 27 Apr 2026 23:37:46 +0900 Subject: [PATCH] feat: Add empty response counter logic to ask user for confirmation after 5 retries --- ga.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ga.py b/ga.py index 428d92f..7be277a 100644 --- a/ga.py +++ b/ga.py @@ -443,8 +443,17 @@ class GenericAgentHandler(BaseHandler): content = getattr(response, 'content', '') or "" thinking = getattr(response, 'thinking', '') or "" if not response or (not content.strip() and not thinking.strip()): + count = self.working.get('empty_response_count', 0) + 1 + self.working['empty_response_count'] = count + if count >= 5: + yield f"[Warn] LLM returned an empty response {count} times. Asking user for confirmation.\n" + return StepOutcome({}, next_prompt="[SYSTEM] LLM has returned empty responses 5 or more times. Please ask the user if they want to continue or stop.") yield "[Warn] LLM returned an empty response. Retrying...\n" return StepOutcome({}, next_prompt="[System] Blank response, regenerate and tooluse") + + # Reset counter on successful non-empty response + if self.working.get('empty_response_count', 0) > 0: + self.working['empty_response_count'] = 0 if len(content) > 100 and ('未收到完整响应 !!!]' in content[-100:] or '!!!Error: [SSL:' in content[-100:]): return StepOutcome({}, next_prompt="[System] Incomplete response. Regenerate and tooluse.") if 'max_tokens !!!]' in content[-100:]: