feat: improve workflow collaboration trace UX

This commit is contained in:
2026-06-16 07:02:10 +08:00
parent d5f1a4510f
commit 56c1eec051
6 changed files with 529 additions and 35 deletions
@@ -217,6 +217,7 @@ def _make_execution_log_entry(
node_type: str,
**extra: Any,
) -> dict:
extra.setdefault('timestamp', datetime.now().isoformat())
metadata = dict(extra.pop('metadata', {}) or {})
collaboration = _node_collaboration_metadata(node_map, node_id, node_type)
branch_id = extra.get('branch') or extra.get('branch_id')
@@ -238,6 +239,7 @@ def _make_execution_log_entry(
output=extra.get('output'),
error=extra.get('error'),
)
metadata['communication']['timestamp'] = extra.get('timestamp')
return {
'node_id': node_id,
'node_type': node_type,
@@ -982,9 +984,18 @@ class AIWorkflowService:
current_id = next_nodes[0] if next_nodes else None
continue
# 执行节点(异步)
node_inputs = _snapshot_node_inputs(branch_context)
# 执行节点(异步)。并行分支不能共享同一个 AsyncSession,否则模型/Provider 查询会并发抢占连接。
start_time = time.time()
result = await node_instance.execute_async(branch_context)
if context.db_session is not None:
from app.database import AsyncSessionLocal
async with AsyncSessionLocal() as branch_db:
branch_context.db_session = branch_db
result = await node_instance.execute_async(branch_context)
else:
result = await node_instance.execute_async(branch_context)
elapsed = int((time.time() - start_time) * 1000)
target_node_id = _resolve_handoff_target(
current_id,
@@ -1004,6 +1015,7 @@ class AIWorkflowService:
elapsed_time=elapsed,
tokens_used=result.tokens_used,
metadata=_node_result_metadata(result),
inputs=copy.deepcopy(node_inputs),
branch=branch_id,
branch_label=branch_labels.get(branch_id, branch_id),
target_node_id=target_node_id,
@@ -1027,6 +1039,12 @@ class AIWorkflowService:
branch_context.variables.update(result.output_variables)
branch_context.previous_output = result.output
branch_output = result.output
# 支持分支内后续节点使用 {{node_id.output_variable}} 引用当前节点输出。
branch_context.variables[f'_node_{current_id}'] = {
'output': result.output,
**result.output_variables,
}
# 下一个节点
if result.next_node_id: