统一流重试行为: 不管mixin/非mixin中途断连都重试; 更新ga.py错误检测条件

This commit is contained in:
Liang Jiaqing committed 2026-04-28 20:41:14 +08:00
1 parent 02a36a9db3
commit 4e41b15972
2 files changed
+6 -19

No files matched your search

+1 -1
View File
@@ -447,7 +447,7 @@ class GenericAgentHandler(BaseHandler):
if not response or (not content.strip() and not thinking.strip()):
yield "[Warn] LLM returned an empty response. Retrying...\n"
return StepOutcome({}, next_prompt="[System] Blank response, regenerate and tooluse")
if len(content) > 50 and ('未收到完整响应 !!!]' in content[-100:] or '!!!Error: [SSL:' in content[-100:]):
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:]:
return StepOutcome({}, next_prompt="[System] max_tokens limit reached. Use multi small steps to do it.")
+5 -18
View File
@@ -374,14 +374,14 @@ def _stream_with_retry(sess, url, headers, payload, parse_fn):
while True: streamed = True; yield next(gen)
except StopIteration as e: return e.value or []
except (requests.Timeout, requests.ConnectionError) as e:
if attempt < sess.max_retries and not streamed:
err = f"!!!Error: {type(e).__name__}"
if attempt < sess.max_retries:
d = _delay(None, attempt)
print(f"[LLM Retry] {type(e).__name__}, retry in {d:.1f}s ({attempt+1}/{sess.max_retries+1})")
time.sleep(d); continue
err = f"!!!Error: {type(e).__name__}"
yield err; time.sleep(d); continue
yield err; return [{"type": "text", "text": err}]
except Exception as e:
err = f"!!!Error: {type(e).__name__}: {e}"
err = f"\n\n[!!! 流异常中断 {type(e).__name__}: {e} !!!]" if streamed else f"!!!Error: {type(e).__name__}: {e}"
yield err; return [{"type": "text", "text": err}]
def _openai_stream(sess, messages):
@@ -746,19 +746,6 @@ class ToolClient:
_write_llm_log('Response', raw_text)
return self._parse_mixed_response(raw_text)
def _estimate_content_len(self, content):
if isinstance(content, str): return len(content)
if isinstance(content, list):
total = 0
for part in content:
if not isinstance(part, dict): continue
if part.get("type") == "text":
total += len(part.get("text", ""))
elif part.get("type") == "image_url":
total += 1000
return total
return len(str(content))
def _prepare_tool_instruction(self, tools):
tool_instruction = ""
if not tools: return tool_instruction
@@ -799,7 +786,7 @@ Follow these steps to think and act:
user += f"=== {role} ===\n"
for tr in m.get('tool_results', []): user += f'<tool_result>{tr["content"]}</tool_result>\n'
user += str(m['content']) + "\n"
self.total_cd_tokens += self._estimate_content_len(user)
self.total_cd_tokens += len(user) // 3
if self.total_cd_tokens > 9000: self.last_tools = ''
user += "=== ASSISTANT ===\n"
return system + user