代码提交

This commit is contained in:
董宏凯 committed 2026-08-24 20:47:31 +08:00
1 parent 007ed5a7de
commit babc5e95c6
21 files changed
+1170 -145

No files matched your search

@@ -40,6 +40,7 @@ from app.gateway.routers._roundtable_seed import (
SUMMARY_AGENT_ID,
ensure_roundtable_functional_agents,
)
from deerflow.agents.roundtable_orchestrator.delivery import classify_seat_delivery, visible_seat_text
from deerflow.agents.roundtable_orchestrator.report_json import extract_report_json
from deerflow.agents.roundtable_orchestrator.types import (
LeaderTurn,
@@ -163,20 +164,36 @@ def _message_text(message: dict[str, Any] | None) -> str:
return ""
def _is_broadcast_human_text(text: str) -> bool:
"""圆桌后广播进席位 thread 的 human,不算新一轮任务边界。"""
t = (text or "").strip()
return t.startswith("总控智能体收到") or t.startswith("子智能体")
def _latest_ai_text(messages: list[dict[str, Any]]) -> str:
"""取**最后一条有正文**的 AI 消息文本。
"""取本轮**可见正文**(剥掉 ``<think>``)。
席位常以「调一堆工具」的 AIMessage 收尾(正文为空、只有 tool_calls,甚至 dangling),
直接取最后一条 AI 消息会拿到空串 → 报告就拿不到席位产物。这里向前找到真正有文字的那条。
思考-only 不算可见正文:一旦碰到最新一条有原文但剥 think 后为空的 AI,停止继承更早一轮。
后广播 human(``子智能体…`` / ``总控智能体收到``)不是轮次边界。
"""
for m in reversed(messages):
if not isinstance(m, dict):
continue
if (m.get("type") or m.get("role")) not in {"ai", "assistant"}:
role = m.get("type") or m.get("role")
if role in {"human", "user"}:
if _is_broadcast_human_text(_message_text(m)):
continue
return ""
if role not in {"ai", "assistant"}:
continue
text = _message_text(m)
if text.strip():
return text
raw = _message_text(m)
kind = classify_seat_delivery(raw)
if kind == "valid":
return visible_seat_text(raw)
if kind == "thinking_only":
return ""
return ""
@@ -548,8 +565,25 @@ def _exception_reason(exc: BaseException) -> str:
def _seat_empty_reason(messages: list[dict[str, Any]]) -> str | None:
"""席位/取数轮校验:最后一条有正文的 AI 消息为空 → ``empty``(触发换模型)。"""
return "empty" if not _latest_ai_text(messages).strip() else None
"""席位/取数轮校验:本轮无可见正文 → ``empty`` / ``thinking_only``(触发换模型)。"""
saw_thinking = False
for m in reversed(messages):
if not isinstance(m, dict):
continue
role = m.get("type") or m.get("role")
if role in {"human", "user"}:
if _is_broadcast_human_text(_message_text(m)):
continue
break
if role not in {"ai", "assistant"}:
continue
kind = classify_seat_delivery(_message_text(m))
if kind == "valid":
return None
if kind == "thinking_only":
saw_thinking = True
break
return "thinking_only" if saw_thinking else "empty"
def _leader_failed_reason(messages: list[dict[str, Any]]) -> str | None: