feat(workflow): 增加会话级多智能体任务规划运行能力
提交范围聚焦于工作流编排新增:新增 workflow_planning 路由与前后端运行入口(workflow_planning.py、workflow_proposal_planner.py、workflow_deep_research_adapter.py),支持基于会话的提案-规划-执行流程,满足任务驱动式多智能体协作。 完成网关层运行时适配:扩展 workflow_resource_checks、workflow_executor、workflow_runs、workflow_agent_runner 与依赖注入,新增/更新配置(config.yaml、workflow_config),并补充 lead_agent 路径与节点实现,确保 Planner 与普通工作流运行态衔接一致。 补齐持久化与建模:新增 workflow_planning 持久化模块与 MySQL migration(20260831_01_workflow_planning_sessions),注册 SQL 与模型、内存 store,并扩展错误/表达式/validator/节点语义以承载新会话态输入输出。 增强文档与测试:新增会话式多智能体编排中文说明、更新开发文档与 AGENTS 指南、补充 workflow_engine/workflow_runs 回归测试,提高新路径的行为可验证性;同时留存 seed 资产(workflow-planner)便于一体化部署。
This commit is contained in:
1 parent
ac92f29db1
commit
1706a24182
39 files changed
+4896
-81
No files matched your search
@@ -122,7 +122,10 @@ class WorkflowRunExecutor:
|
||||
return
|
||||
|
||||
cancel = CancelToken()
|
||||
resume_payload = (run.get("context") or {}).get("resume_payload")
|
||||
run_context = run.get("context") or {}
|
||||
resume_payload = run_context.get("resume_payload")
|
||||
raw_env = run_context.get("env")
|
||||
env = dict(raw_env) if isinstance(raw_env, dict) else {}
|
||||
preloaded, loop_state = await self._replay_state(params.run_id)
|
||||
|
||||
ctx = RunContext(
|
||||
@@ -136,6 +139,7 @@ class WorkflowRunExecutor:
|
||||
cancel=cancel,
|
||||
emit=sink.emit,
|
||||
resume_payload=resume_payload if isinstance(resume_payload, dict) else None,
|
||||
env=env,
|
||||
)
|
||||
|
||||
await sink.emit(
|
||||
@@ -191,12 +195,17 @@ class WorkflowRunExecutor:
|
||||
|
||||
# ── terminal transitions ────────────────────────────────────────────
|
||||
async def _complete(self, params: LeaseParams, result: Any, sink: Any) -> None:
|
||||
context = await self._context_with(
|
||||
params.run_id,
|
||||
loop_state=result.loop_state,
|
||||
steps=result.steps,
|
||||
)
|
||||
await self._runs.update_run(
|
||||
params.run_id,
|
||||
lease_owner=params.lease_owner,
|
||||
status="completed",
|
||||
output_json=result.output,
|
||||
context_json={"loop_state": result.loop_state, "steps": result.steps},
|
||||
context_json=context,
|
||||
finished_at=datetime.now(UTC),
|
||||
)
|
||||
await sink.emit("run.completed", data={"output": result.output, "steps": result.steps})
|
||||
@@ -238,12 +247,17 @@ class WorkflowRunExecutor:
|
||||
# One conditional update writes status + token + pending descriptor +
|
||||
# run context together; a separate follow-up context write could clobber
|
||||
# a resume that lands in between.
|
||||
context = await self._context_with(
|
||||
params.run_id,
|
||||
loop_state=dict(ctx.loop_state),
|
||||
resume_payload=None,
|
||||
)
|
||||
updated = await self._runs.set_awaiting_input(
|
||||
params.run_id,
|
||||
lease_owner=params.lease_owner,
|
||||
pending_input=paused.pending_input,
|
||||
resume_token=token,
|
||||
context={"loop_state": dict(ctx.loop_state), "resume_payload": None},
|
||||
context=context,
|
||||
)
|
||||
if updated is None:
|
||||
# Lost the lease (cancel or steal) — do not fabricate a pause.
|
||||
@@ -264,6 +278,12 @@ class WorkflowRunExecutor:
|
||||
)
|
||||
|
||||
# ── helpers ─────────────────────────────────────────────────────────
|
||||
async def _context_with(self, run_id: str, **updates: Any) -> dict[str, Any]:
|
||||
"""Merge checkpoints without dropping a draft execution graph snapshot."""
|
||||
run = await self._runs.get_run(run_id)
|
||||
current = dict(run.get("context") or {}) if run else {}
|
||||
return {**current, **updates}
|
||||
|
||||
def _sink(self, run: dict[str, Any]) -> PersistingWorkflowEventSink:
|
||||
return PersistingWorkflowEventSink(
|
||||
self._events,
|
||||
@@ -309,8 +329,10 @@ class WorkflowRunExecutor:
|
||||
|
||||
def _deps(self, *, depth: int = 0) -> WorkflowRuntimeDeps:
|
||||
from app.gateway.workflow_agent_runner import WorkflowAgentRunner
|
||||
from app.gateway.workflow_deep_research_adapter import WorkflowDeepResearchAdapter
|
||||
|
||||
agent_runner = WorkflowAgentRunner(self._app)
|
||||
deep_research_adapter = WorkflowDeepResearchAdapter(self._app)
|
||||
|
||||
async def save_artifact(**kwargs: Any) -> dict[str, Any]:
|
||||
return await self._runs.add_artifact(kwargs)
|
||||
@@ -350,6 +372,7 @@ class WorkflowRunExecutor:
|
||||
resolve_data_source=resolve_data_source,
|
||||
resolve_credential=resolve_credential,
|
||||
run_subworkflow=run_subworkflow,
|
||||
run_deep_research=deep_research_adapter.run,
|
||||
)
|
||||
|
||||
async def _run_child(
|
||||
|
||||
Reference in new issue
Block a user