fix: include completed sub agents in overview
This commit is contained in:
parent
20213f30ea
commit
71f24c2d72
@ -566,11 +566,9 @@ class SubAgentManager:
|
|||||||
"""返回子智能体任务概览,用于前端展示。"""
|
"""返回子智能体任务概览,用于前端展示。"""
|
||||||
overview: List[Dict[str, Any]] = []
|
overview: List[Dict[str, Any]] = []
|
||||||
for task_id, task in self.tasks.items():
|
for task_id, task in self.tasks.items():
|
||||||
status = task.get("status")
|
|
||||||
if status not in {"pending", "running"}:
|
|
||||||
continue
|
|
||||||
if conversation_id and task.get("conversation_id") != conversation_id:
|
if conversation_id and task.get("conversation_id") != conversation_id:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
snapshot = {
|
snapshot = {
|
||||||
"task_id": task_id,
|
"task_id": task_id,
|
||||||
"agent_id": task.get("agent_id"),
|
"agent_id": task.get("agent_id"),
|
||||||
@ -585,7 +583,8 @@ class SubAgentManager:
|
|||||||
"conversation_id": task.get("conversation_id"),
|
"conversation_id": task.get("conversation_id"),
|
||||||
"sub_conversation_id": task.get("sub_conversation_id"),
|
"sub_conversation_id": task.get("sub_conversation_id"),
|
||||||
}
|
}
|
||||||
# 对于运行中的任务,尝试获取最新状态
|
|
||||||
|
# 运行中的任务尝试同步远端最新状态
|
||||||
if snapshot["status"] not in TERMINAL_STATUSES:
|
if snapshot["status"] not in TERMINAL_STATUSES:
|
||||||
remote = self._call_service("GET", f"/tasks/{task_id}", timeout=5)
|
remote = self._call_service("GET", f"/tasks/{task_id}", timeout=5)
|
||||||
if remote.get("success"):
|
if remote.get("success"):
|
||||||
@ -593,5 +592,13 @@ class SubAgentManager:
|
|||||||
snapshot["remote_message"] = remote.get("message")
|
snapshot["remote_message"] = remote.get("message")
|
||||||
snapshot["last_tool"] = remote.get("last_tool")
|
snapshot["last_tool"] = remote.get("last_tool")
|
||||||
task["last_tool"] = snapshot["last_tool"]
|
task["last_tool"] = snapshot["last_tool"]
|
||||||
|
else:
|
||||||
|
# 已结束的任务带上最终结果/系统消息,方便前端展示
|
||||||
|
final_result = task.get("final_result") or {}
|
||||||
|
snapshot["final_message"] = final_result.get("system_message") or final_result.get("message")
|
||||||
|
snapshot["success"] = final_result.get("success")
|
||||||
|
|
||||||
overview.append(snapshot)
|
overview.append(snapshot)
|
||||||
|
|
||||||
|
overview.sort(key=lambda item: item.get("created_at") or 0, reverse=True)
|
||||||
return overview
|
return overview
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user