feat(backend): 完善 Workflow 与 DeepResearch 的运行链路与持久化能力
功能说明:\n- 重构并增强工作流网关执行链路,支持更完整的 proposal 与 run 调度参数透传\n- 增加 DeepResearch/workflow 运行事件持久化能力并补齐建表 SQL 与查询/保存接口适配\n- 优化 lead agent 与 deep research runner 的中间态处理,增强线程收集与执行链并发控制\n- 调整工作流执行器与任务路由,提升兼容性并完善错误与回放行为\n- 补充回归测试:deep_research 持久化、workflow 并发、定义加载、引擎执行、run 流程等覆盖
This commit is contained in:
1 parent
f5bf7897b9
commit
6d326a21cd
28 files changed
+836
-135
No files matched your search
@@ -9,6 +9,7 @@ Canonical ``data`` payloads (frozen contract — REST replay and SSE must agree)
|
||||
"title": "联网检索", "args": {"path": "..."}}
|
||||
node.tool.finished {"name": "web_search", "toolCallId": "call_001",
|
||||
"status": "succeeded" | "failed", "summary": "获得 12 条结果"}
|
||||
node.message {"messages": [<native LangGraph message>, <metadata>]}
|
||||
run.awaiting_input {"resumeToken": "one-time-token", "prompt": "请确认是否发布",
|
||||
"formSchema": {...}, "actions": ["approve", "reject"]}
|
||||
artifact.created {"artifactId": "artifact_001", "name": "weekly-report.docx",
|
||||
@@ -40,6 +41,7 @@ WorkflowEventType = Literal[
|
||||
"node.started",
|
||||
"node.progress",
|
||||
"node.output.delta",
|
||||
"node.message",
|
||||
"node.tool.started",
|
||||
"node.tool.finished",
|
||||
"artifact.created",
|
||||
@@ -61,6 +63,7 @@ ALL_WORKFLOW_EVENT_TYPES: tuple[WorkflowEventType, ...] = (
|
||||
"node.started",
|
||||
"node.progress",
|
||||
"node.output.delta",
|
||||
"node.message",
|
||||
"node.tool.started",
|
||||
"node.tool.finished",
|
||||
"artifact.created",
|
||||
|
||||
+39
-25
@@ -17,7 +17,7 @@ from typing import Any
|
||||
from deerflow.workflows.errors import WorkflowError
|
||||
from deerflow.workflows.expressions import render_template, render_value
|
||||
from deerflow.workflows.nodes.base import require_dep
|
||||
from deerflow.workflows.runtime.context import RunContext
|
||||
from deerflow.workflows.runtime.context import RunContext, WorkflowPaused
|
||||
from deerflow.workflows.schemas import ArtifactRef, NodeResult, WorkflowNode
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -96,28 +96,6 @@ def _extract_json(text: str) -> Any:
|
||||
return None
|
||||
|
||||
|
||||
_SAFE_ARG_STRING_CHARS = 160
|
||||
_SAFE_ARG_MAX_KEYS = 12
|
||||
|
||||
|
||||
def _safe_tool_args(args: Any) -> dict[str, Any]:
|
||||
"""Minimal safe projection of tool-call args for the event log.
|
||||
|
||||
Scalars only (strings truncated), no nested containers, bounded key count —
|
||||
enough for the canvas to label the step without leaking full payloads such
|
||||
as entire documents, prompts or credentials that a tool may carry."""
|
||||
if not isinstance(args, dict):
|
||||
return {}
|
||||
out: dict[str, Any] = {}
|
||||
for key, value in list(args.items())[:_SAFE_ARG_MAX_KEYS]:
|
||||
if isinstance(value, bool) or not isinstance(value, (str, int, float)):
|
||||
continue
|
||||
if isinstance(value, str):
|
||||
value = value[:_SAFE_ARG_STRING_CHARS]
|
||||
out[str(key)[:64]] = value
|
||||
return out
|
||||
|
||||
|
||||
def _append_input_bindings(prompt: str, raw_bindings: Any, state: dict[str, Any]) -> str:
|
||||
"""Attach explicit workflow inputs to an agent prompt.
|
||||
|
||||
@@ -206,7 +184,10 @@ class _AgentInvocation:
|
||||
"name": name,
|
||||
"toolCallId": call_id,
|
||||
"title": str(event.get("title") or name),
|
||||
"args": _safe_tool_args(event.get("args")),
|
||||
# The native messages frame is authoritative for the
|
||||
# conversation UI. Preserve this compatibility event
|
||||
# too, so history/replay never differs from live data.
|
||||
"args": event.get("args"),
|
||||
},
|
||||
node_id=node.id,
|
||||
)
|
||||
@@ -218,13 +199,30 @@ class _AgentInvocation:
|
||||
"name": name,
|
||||
"toolCallId": call_id,
|
||||
"status": "succeeded" if ok in (True, None) else "failed",
|
||||
"summary": event.get("summary"),
|
||||
"result": event.get("result"),
|
||||
},
|
||||
node_id=node.id,
|
||||
)
|
||||
|
||||
async def on_message(messages: list[Any]) -> None:
|
||||
# Do not adapt the nested LangGraph frame. The browser consumes
|
||||
# exactly the same native AIMessage/ToolMessage structure as
|
||||
# DeerFlow's chat client; the outer workflow event only supplies
|
||||
# durable seq and canvas-node attribution.
|
||||
await ctx.emit_event(
|
||||
"node.message",
|
||||
data={"messages": messages},
|
||||
node_id=node.id,
|
||||
)
|
||||
|
||||
try:
|
||||
try:
|
||||
resume_payload = (
|
||||
ctx.resume_payload
|
||||
if isinstance(ctx.resume_payload, dict)
|
||||
and str(ctx.resume_payload.get("nodeId") or "") == node.id
|
||||
else None
|
||||
)
|
||||
outcome = await run_agent(
|
||||
run_id=ctx.run_id,
|
||||
node_id=node.id,
|
||||
@@ -237,6 +235,8 @@ class _AgentInvocation:
|
||||
cancel=ctx.cancel,
|
||||
on_delta=on_delta,
|
||||
on_tool=on_tool,
|
||||
on_message=on_message,
|
||||
resume_payload=resume_payload,
|
||||
)
|
||||
except WorkflowError as exc:
|
||||
exc.node_id = exc.node_id or node.id
|
||||
@@ -253,6 +253,20 @@ class _AgentInvocation:
|
||||
finally:
|
||||
await coalescer.flush()
|
||||
|
||||
pending_input = outcome.get("awaiting_input")
|
||||
if isinstance(pending_input, dict):
|
||||
raise WorkflowPaused(
|
||||
node.id,
|
||||
{
|
||||
"nodeId": node.id,
|
||||
**pending_input,
|
||||
},
|
||||
)
|
||||
if resume_payload is not None:
|
||||
# The reply belongs to this agent thread only. A later human/agent
|
||||
# node must not accidentally consume it as its own resume data.
|
||||
ctx.resume_payload = None
|
||||
|
||||
text = str(outcome.get("text") or "")
|
||||
data: dict[str, Any] = {"text": text}
|
||||
if response_mode == "json":
|
||||
|
||||
Reference in new issue
Block a user