feat: Phase 3 - parallel execution, progress reporting, result caching + AgentChat bug fixes

Phase 3 能力:
- DAG 并行执行 (workflow_engine): asyncio.gather 并行执行就绪节点
- Debate 并行 (orchestrator): for 循环改为 asyncio.gather
- 粒度进度上报 (workflow_engine + tasks + websocket): Redis 推送 + DB 降级
- 工具结果缓存 (tool_manager): 确定性工具默认开启缓存
- LLM 响应缓存 (core): messages[-4:] + model 哈希,5min TTL

AgentChat bug 修复 (Gitea #1-#5):
- #1 SSE 降级重复空消息: fallback POST 前移除占位消息
- #2 streamTimeout 泄漏: while 正常退出后 clearTimeout
- #3 loading 闪烁: final/error 事件中提前设 loading=false
- #4 SSE 事件类型对齐: 确认匹配,未知类型加 console.warn
- #5 retryMessage 流式残留: 重试时清理占位消息

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
renjianbo
2026-05-05 00:00:51 +08:00
parent f3cb35c460
commit 7e00b027d4
8 changed files with 605 additions and 345 deletions

View File

@@ -9,6 +9,7 @@ Agent Orchestrator — 多 Agent 编排引擎。
"""
from __future__ import annotations
import asyncio
import json
import logging
import uuid
@@ -347,9 +348,10 @@ class AgentOrchestrator:
steps: List[OrchestratorStep] = []
agent_outputs: List[Dict[str, Any]] = []
# 第一阶段:所有 Agent 独立回答
# 第一阶段:所有 Agent 并行独立回答
runtimes = []
for agent_cfg in agents:
runtime = AgentRuntime(
runtimes.append(AgentRuntime(
AgentConfig(
name=agent_cfg.name,
system_prompt=agent_cfg.system_prompt,
@@ -364,8 +366,30 @@ class AgentOrchestrator:
),
),
on_llm_call=on_llm_call,
)
result = await runtime.run(question)
))
results = await asyncio.gather(
*[rt.run(question) for rt in runtimes],
return_exceptions=True,
)
for i, agent_cfg in enumerate(agents):
result = results[i]
if isinstance(result, BaseException):
step = OrchestratorStep(
agent_id=agent_cfg.id,
agent_name=agent_cfg.name,
input=question,
output="",
error=str(result),
)
steps.append(step)
agent_outputs.append({
"agent_id": agent_cfg.id,
"agent_name": agent_cfg.name,
"output": f"[错误] {result}",
})
continue
step = OrchestratorStep(
agent_id=agent_cfg.id,