fix: tool_calls 流中断自愈——400 配对错误时移除不完整段重试一次;加消息结构诊断日志
This commit is contained in:
@@ -367,6 +367,16 @@ def _agent_thread(run_id, prompt, serial, cfg):
|
||||
_log.warning(f"经验保存异常: {e}")
|
||||
except Exception as e:
|
||||
_log.warning(f"Agent 运行异常: {e}")
|
||||
# 诊断:打印消息结构(tool_calls 与 tool 消息配对检查)
|
||||
try:
|
||||
roles = [m.get("role", "?") for m in agent.messages]
|
||||
tcs = sum(1 for m in agent.messages
|
||||
if m.get("tool_calls") and isinstance(m.get("tool_calls"), list))
|
||||
tools_msg = sum(1 for m in agent.messages if m.get("role") == "tool")
|
||||
_log.warning(f"诊断 messages: {len(agent.messages)} 条 roles={roles[-8:]} "
|
||||
f"tool_calls消息={tcs} tool回应={tools_msg}")
|
||||
except Exception:
|
||||
pass
|
||||
with _lock:
|
||||
_run["state"] = "error"
|
||||
_run["error"] = f"{type(e).__name__}: {str(e)[:200]}"
|
||||
|
||||
Reference in New Issue
Block a user