fix: agent-level retry for intermittent SSL errors during streaming

- llmcore: prefix all error outputs with !!! marker
- ga: detect !!!Error: [SSL: in tail of content as incomplete response and retry
- add len(content)>100 guard to avoid false positives on short responses
This commit is contained in:
Liang Jiaqing
2026-04-23 11:24:54 +08:00
parent 17971f642a
commit 97573e6f46
2 changed files with 4 additions and 4 deletions

2
ga.py
View File

@@ -444,7 +444,7 @@ class GenericAgentHandler(BaseHandler):
if not response or not content.strip(): if not response or not content.strip():
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")
if '未收到完整响应 !!!]' 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:]:
return StepOutcome({}, next_prompt="[System] max_tokens limit reached. Use multi small steps to do it.") return StepOutcome({}, next_prompt="[System] max_tokens limit reached. Use multi small steps to do it.")

View File

@@ -333,7 +333,7 @@ def _openai_stream(api_base, api_key, messages, model, api_mode='chat_completion
body = "" body = ""
try: body = r.text.strip()[:500] try: body = r.text.strip()[:500]
except: pass except: pass
err = f"Error: HTTP {r.status_code}" + (f": {body}" if body else "") err = f"!!!Error: HTTP {r.status_code}" + (f": {body}" if body else "")
yield err; return [{"type": "text", "text": err}] yield err; return [{"type": "text", "text": err}]
gen = _parse_openai_sse(r.iter_lines(), api_mode) if stream else _parse_openai_json(r.json(), api_mode) gen = _parse_openai_sse(r.iter_lines(), api_mode) if stream else _parse_openai_json(r.json(), api_mode)
try: try:
@@ -345,10 +345,10 @@ def _openai_stream(api_base, api_key, messages, model, api_mode='chat_completion
d = _delay(None, attempt) d = _delay(None, attempt)
print(f"[LLM Retry] {type(e).__name__}, retry in {d:.1f}s ({attempt+1}/{max_retries+1})") print(f"[LLM Retry] {type(e).__name__}, retry in {d:.1f}s ({attempt+1}/{max_retries+1})")
time.sleep(d); continue time.sleep(d); continue
err = f"Error: {type(e).__name__}" err = f"!!!Error: {type(e).__name__}"
yield err; return [{"type": "text", "text": err}] yield err; return [{"type": "text", "text": err}]
except Exception as e: except Exception as e:
err = f"Error: {type(e).__name__}: {e}" err = f"!!!Error: {type(e).__name__}: {e}"
yield err; return [{"type": "text", "text": err}] yield err; return [{"type": "text", "text": err}]
def _prepare_oai_tools(tools, api_mode="chat_completions"): def _prepare_oai_tools(tools, api_mode="chat_completions"):