feat: Add empty response counter logic to ask user for confirmation after 5 retries
This commit is contained in:
9
ga.py
9
ga.py
@@ -443,8 +443,17 @@ class GenericAgentHandler(BaseHandler):
|
|||||||
content = getattr(response, 'content', '') or ""
|
content = getattr(response, 'content', '') or ""
|
||||||
thinking = getattr(response, 'thinking', '') or ""
|
thinking = getattr(response, 'thinking', '') or ""
|
||||||
if not response or (not content.strip() and not thinking.strip()):
|
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"
|
yield "[Warn] LLM returned an empty response. Retrying...\n"
|
||||||
return StepOutcome({}, next_prompt="[System] Blank response, regenerate and tooluse")
|
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:]):
|
if len(content) > 100 and ('未收到完整响应 !!!]' in content[-100:] or '!!!Error: [SSL:' in content[-100:]):
|
||||||
return StepOutcome({}, next_prompt="[System] Incomplete response. Regenerate and tooluse.")
|
return StepOutcome({}, next_prompt="[System] Incomplete response. Regenerate and tooluse.")
|
||||||
if 'max_tokens !!!]' in content[-100:]:
|
if 'max_tokens !!!]' in content[-100:]:
|
||||||
|
|||||||
Reference in New Issue
Block a user