feat: Add empty response counter logic to ask user for confirmation after 5 retries

This commit is contained in:
pys306
2026-04-27 23:37:46 +09:00
parent 50a7544a55
commit 475c203ea1

9
ga.py
View File

@@ -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:]: