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

@@ -20,7 +20,9 @@ from app.models.workflow import Workflow
from app.services.execution_budget import merge_budget_for_execution
from app.services.agent_workspace_chat_log import try_append_agent_dialogue_after_success
from app.services.notification_service import create_notification
from app.websocket.manager import websocket_manager
import asyncio
import json
import time
from typing import Any, Dict, Optional
@@ -42,6 +44,29 @@ def _snapshot_to_jsonable(snapshot: dict) -> dict:
return _json.loads(_json.dumps(snapshot, default=str))
async def _on_workflow_progress(execution_id: str, progress_data: dict):
"""工作流进度回调:写入 Redis + WebSocket 广播。"""
try:
from app.core.redis_client import get_redis_client
redis_client = get_redis_client()
if redis_client:
redis_client.setex(
f"workflow:progress:{execution_id}",
300,
json.dumps(progress_data, ensure_ascii=False),
)
except Exception:
pass
try:
await websocket_manager.broadcast_to_execution(execution_id, {
"type": "progress",
"execution_id": execution_id,
**progress_data,
})
except Exception:
pass
def _trusted_user_for_execution(db, execution: Optional[Execution]) -> Optional[str]:
"""用于校验 LLM 节点引用的 model_configs 归属(与 Workflow / Agent 所有者一致)。"""
if not execution:
@@ -195,7 +220,8 @@ def execute_workflow_task(
for attempt in range(max_retries + 1):
try:
result = asyncio.run(
engine.execute(input_data, resume_snapshot=resume_snapshot)
engine.execute(input_data, resume_snapshot=resume_snapshot,
execution_id=execution_id, on_progress=_on_workflow_progress)
)
break
except WorkflowPaused as paused:
@@ -391,7 +417,8 @@ def resume_workflow_task(
for attempt in range(max_retries + 1):
try:
result = asyncio.run(
engine.execute(base_input, resume_snapshot=snapshot)
engine.execute(base_input, resume_snapshot=snapshot,
execution_id=execution_id, on_progress=_on_workflow_progress)
)
break
except WorkflowPaused as paused: