diff --git a/astrbot/core/provider/sources/openai_source.py b/astrbot/core/provider/sources/openai_source.py index 8aa2778f1b..044aad0203 100644 --- a/astrbot/core/provider/sources/openai_source.py +++ b/astrbot/core/provider/sources/openai_source.py @@ -594,12 +594,20 @@ def _is_empty(content: Any) -> bool: tool_calls = msg.get("tool_calls") reasoning_content = msg.get("reasoning_content") - if _is_empty(content) and not tool_calls and not reasoning_content: - logger.warning(f"过滤第 {idx} 条空 assistant 消息 (无工具调用)") - continue - - if _is_empty(content) and tool_calls: - msg["content"] = None + if _is_empty(content) and not tool_calls: + if not reasoning_content: + # 三者全空,真正的垃圾消息,丢弃 + logger.debug(f"过滤第 {idx} 条空 assistant 消息 (无 content | tool_calls | reasoning_content)") + continue + else: + # ⭐ 有 reasoning_content 但没有 content 和 tool_calls + # 不能丢(推理模型需要 reasoning 历史) + # 但 API 要求 content 或 tool_calls 至少有一个 + # → 设空字符串占位,满足校验 + msg["content"] = "" + + elif _is_empty(content) and tool_calls: + msg["content"] = None # 有 tool_calls,按 OpenAI 规范 cleaned.append(msg)