初始化
This commit is contained in:
1 parent
34474bd5fc
commit
b638b541d0
3008 files changed
+837699
No files matched your search
+54
@@ -0,0 +1,54 @@
|
||||
"""Load frozen workflow sample graphs shipped with the harness."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from functools import lru_cache
|
||||
from pathlib import Path
|
||||
|
||||
from deerflow.workflows.schemas import WorkflowGraph
|
||||
|
||||
_SAMPLES_DIR = Path(__file__).resolve().parent
|
||||
_NODES_DIR = _SAMPLES_DIR / "nodes"
|
||||
|
||||
|
||||
def samples_dir() -> Path:
|
||||
return _SAMPLES_DIR
|
||||
|
||||
|
||||
def nodes_dir() -> Path:
|
||||
return _NODES_DIR
|
||||
|
||||
|
||||
@lru_cache(maxsize=32)
|
||||
def load_sample_graph(name: str = "report_generation") -> WorkflowGraph:
|
||||
"""Load and validate a sample graph by stem name (without ``.json``)."""
|
||||
path = _SAMPLES_DIR / f"{name}.json"
|
||||
if not path.is_file():
|
||||
raise FileNotFoundError(f"workflow sample not found: {path}")
|
||||
raw = json.loads(path.read_text(encoding="utf-8"))
|
||||
return WorkflowGraph.model_validate(raw)
|
||||
|
||||
|
||||
@lru_cache(maxsize=64)
|
||||
def load_node_sample(node_type: str) -> dict:
|
||||
"""Load a minimal single-node fixture (raw dict, not a full graph)."""
|
||||
path = _NODES_DIR / f"{node_type}.json"
|
||||
if not path.is_file():
|
||||
raise FileNotFoundError(f"node sample not found: {path}")
|
||||
return json.loads(path.read_text(encoding="utf-8"))
|
||||
|
||||
|
||||
def list_node_samples() -> list[str]:
|
||||
if not _NODES_DIR.is_dir():
|
||||
return []
|
||||
return sorted(p.stem for p in _NODES_DIR.glob("*.json"))
|
||||
|
||||
|
||||
__all__ = [
|
||||
"list_node_samples",
|
||||
"load_node_sample",
|
||||
"load_sample_graph",
|
||||
"nodes_dir",
|
||||
"samples_dir",
|
||||
]
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"schemaVersion": "1.0",
|
||||
"runId": "run_01",
|
||||
"workflowId": "wf_report_generation",
|
||||
"versionId": "wv_03",
|
||||
"seq": 42,
|
||||
"event": "node.output.delta",
|
||||
"nodeId": "agent_write",
|
||||
"nodeRunId": "nr_09",
|
||||
"timestamp": "2026-08-26T10:00:00+08:00",
|
||||
"data": {
|
||||
"channel": "answer",
|
||||
"delta": "第一段内容"
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"id": "agent_1",
|
||||
"type": "agent",
|
||||
"name": "智能体",
|
||||
"config": {
|
||||
"agentId": "report-writer",
|
||||
"promptTemplate": "根据材料撰写:{{ nodes.merge_1.data }}",
|
||||
"responseMode": "text",
|
||||
"threadMode": "isolated_per_node",
|
||||
"timeoutSeconds": 600,
|
||||
"skillNames": []
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"id": "code_1",
|
||||
"type": "code",
|
||||
"name": "代码(沙箱)",
|
||||
"config": {
|
||||
"language": "python",
|
||||
"source": "def main(inputs):\n rows = inputs.get(\"rows\") or []\n return {\"count\": len(rows), \"titles\": [r.get(\"title\") for r in rows[:10]]}\n",
|
||||
"timeoutSeconds": 60,
|
||||
"allowNetwork": false
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"id": "cond_1",
|
||||
"type": "condition",
|
||||
"name": "条件",
|
||||
"config": {
|
||||
"branches": [
|
||||
{
|
||||
"name": "passed",
|
||||
"expression": "{{ nodes.agent_review.data.passed }} == true"
|
||||
},
|
||||
{
|
||||
"name": "rejected",
|
||||
"expression": "{{ nodes.agent_review.data.passed }} == false"
|
||||
}
|
||||
],
|
||||
"defaultBranch": "rejected"
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"id": "http_1",
|
||||
"type": "http",
|
||||
"name": "HTTP",
|
||||
"config": {
|
||||
"method": "GET",
|
||||
"url": "https://api.example.internal/items/{{ inputs.taskId }}",
|
||||
"headers": { "Accept": "application/json" },
|
||||
"query": {},
|
||||
"body": null,
|
||||
"credentialRef": "cred_task_api",
|
||||
"timeoutSeconds": 30,
|
||||
"maxResponseBytes": 1048576,
|
||||
"allowRedirects": false
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"id": "human_1",
|
||||
"type": "human_input",
|
||||
"name": "人工介入",
|
||||
"config": {
|
||||
"formSchema": {
|
||||
"type": "object",
|
||||
"required": ["decision"],
|
||||
"properties": {
|
||||
"decision": {
|
||||
"type": "string",
|
||||
"enum": ["approve", "revise"]
|
||||
},
|
||||
"comment": { "type": "string" }
|
||||
}
|
||||
},
|
||||
"prompt": "请确认是否放行当前报告草稿。",
|
||||
"actions": ["approve", "revise"]
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"id": "loop_1",
|
||||
"type": "loop",
|
||||
"name": "受限循环",
|
||||
"config": {
|
||||
"maxIterations": 2,
|
||||
"continueWhen": "{{ nodes.agent_review.data.passed }} == false",
|
||||
"bodyEntry": "agent_write"
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"id": "merge_1",
|
||||
"type": "merge",
|
||||
"name": "合并",
|
||||
"config": {
|
||||
"strategy": "all",
|
||||
"sources": ["sql_1", "http_1", "agent_collect"]
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"id": "output_1",
|
||||
"type": "output",
|
||||
"name": "输出",
|
||||
"config": {
|
||||
"mapping": {
|
||||
"reportMarkdown": "{{ nodes.agent_write.data.answer }}"
|
||||
},
|
||||
"llmRepair": false
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"id": "skill_1",
|
||||
"type": "skill",
|
||||
"name": "技能(agent_skill)",
|
||||
"config": {
|
||||
"mode": "agent_skill",
|
||||
"agentId": "report-collector",
|
||||
"skillNames": ["web-research"],
|
||||
"promptTemplate": "使用指定技能完成:{{ inputs.topic }}",
|
||||
"timeoutSeconds": 300
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"id": "sql_1",
|
||||
"type": "sql_read",
|
||||
"name": "SQL 只读",
|
||||
"config": {
|
||||
"dataSourceId": "ds_report_readonly",
|
||||
"statement": "SELECT id, title FROM report_source WHERE task_id = :task_id",
|
||||
"parameters": {
|
||||
"task_id": "{{ inputs.taskId }}"
|
||||
},
|
||||
"maxRows": 1000
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"id": "start_1",
|
||||
"type": "start",
|
||||
"name": "开始",
|
||||
"config": {}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"id": "sub_1",
|
||||
"type": "subworkflow",
|
||||
"name": "子工作流",
|
||||
"config": {
|
||||
"workflowId": "wf_collect_pack",
|
||||
"versionId": "wv_01",
|
||||
"inputMapping": {
|
||||
"topic": "{{ inputs.topic }}",
|
||||
"taskId": "{{ inputs.taskId }}"
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"id": "transform_1",
|
||||
"type": "transform",
|
||||
"name": "模板/转换",
|
||||
"config": {
|
||||
"operations": [
|
||||
{
|
||||
"op": "map",
|
||||
"from": "{{ nodes.sql_1.data.rows }}",
|
||||
"to": "rows"
|
||||
},
|
||||
{
|
||||
"op": "template",
|
||||
"template": "# {{ inputs.topic }}\n\n共 {{ nodes.sql_1.metadata.rowCount }} 行。",
|
||||
"to": "markdown"
|
||||
}
|
||||
],
|
||||
"template": null
|
||||
}
|
||||
}
|
||||
+260
@@ -0,0 +1,260 @@
|
||||
{
|
||||
"schemaVersion": "1.0",
|
||||
"id": "wf_report_generation",
|
||||
"name": "专题报告生成",
|
||||
"description": "阶段0验收基线:并行取数 → 合并 → 整理 → 撰写 → 审核 → 条件退回/输出",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"required": ["topic", "taskId"],
|
||||
"properties": {
|
||||
"topic": { "type": "string", "description": "报告主题" },
|
||||
"taskId": { "type": "string", "description": "业务任务 ID" },
|
||||
"dateRange": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"start": { "type": "string" },
|
||||
"end": { "type": "string" }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"outputSchema": {
|
||||
"type": "object",
|
||||
"required": ["reportMarkdown", "passed"],
|
||||
"properties": {
|
||||
"reportMarkdown": { "type": "string" },
|
||||
"passed": { "type": "boolean" },
|
||||
"artifacts": { "type": "array" },
|
||||
"issues": { "type": "array" }
|
||||
}
|
||||
},
|
||||
"nodes": [
|
||||
{
|
||||
"id": "start_1",
|
||||
"type": "start",
|
||||
"name": "开始",
|
||||
"config": {}
|
||||
},
|
||||
{
|
||||
"id": "sql_1",
|
||||
"type": "sql_read",
|
||||
"name": "查询内部结构化数据",
|
||||
"config": {
|
||||
"dataSourceId": "ds_report_readonly",
|
||||
"statement": "SELECT id, title, content, updated_at FROM report_source WHERE task_id = :task_id ORDER BY updated_at DESC",
|
||||
"parameters": {
|
||||
"task_id": "{{ inputs.taskId }}"
|
||||
},
|
||||
"maxRows": 1000
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "http_1",
|
||||
"type": "http",
|
||||
"name": "调用只读业务接口",
|
||||
"config": {
|
||||
"method": "GET",
|
||||
"url": "https://api.example.internal/tasks/{{ inputs.taskId }}/summary",
|
||||
"headers": {
|
||||
"Accept": "application/json"
|
||||
},
|
||||
"credentialRef": "cred_task_api",
|
||||
"timeoutSeconds": 30,
|
||||
"maxResponseBytes": 524288,
|
||||
"allowRedirects": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "agent_collect",
|
||||
"type": "agent",
|
||||
"name": "外部材料采集",
|
||||
"config": {
|
||||
"agentId": "report-collector",
|
||||
"promptTemplate": "围绕主题「{{ inputs.topic }}」搜集外部公开材料,任务 ID:{{ inputs.taskId }}。输出 JSON:{sources:[], notes:string}",
|
||||
"responseMode": "json",
|
||||
"responseSchema": {
|
||||
"type": "object",
|
||||
"required": ["sources", "notes"],
|
||||
"properties": {
|
||||
"sources": { "type": "array" },
|
||||
"notes": { "type": "string" }
|
||||
}
|
||||
},
|
||||
"threadMode": "isolated_per_node",
|
||||
"timeoutSeconds": 600,
|
||||
"skillNames": ["web-research"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "merge_1",
|
||||
"type": "merge",
|
||||
"name": "合并材料并保留来源",
|
||||
"config": {
|
||||
"strategy": "all",
|
||||
"sources": ["sql_1", "http_1", "agent_collect"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "agent_clean",
|
||||
"type": "agent",
|
||||
"name": "数据整理与事实去重",
|
||||
"config": {
|
||||
"agentId": "report-cleaner",
|
||||
"promptTemplate": "整理并去重以下材料,输出严格 JSON:{{ nodes.merge_1.data }}",
|
||||
"responseMode": "json",
|
||||
"responseSchema": {
|
||||
"type": "object",
|
||||
"required": ["facts", "sources"],
|
||||
"properties": {
|
||||
"facts": { "type": "array" },
|
||||
"sources": { "type": "array" }
|
||||
}
|
||||
},
|
||||
"threadMode": "isolated_per_node",
|
||||
"timeoutSeconds": 600
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "agent_write",
|
||||
"type": "agent",
|
||||
"name": "撰写 Markdown 报告",
|
||||
"config": {
|
||||
"agentId": "report-writer",
|
||||
"promptTemplate": "根据整理结果撰写专题报告(Markdown)。主题:{{ inputs.topic }}\n材料:{{ nodes.agent_clean.data }}\n若存在审核意见:{{ nodes.agent_review.data.revisedAdvice }}",
|
||||
"responseMode": "text",
|
||||
"threadMode": "isolated_per_node",
|
||||
"timeoutSeconds": 900
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "agent_review",
|
||||
"type": "agent",
|
||||
"name": "审核报告",
|
||||
"config": {
|
||||
"agentId": "report-reviewer",
|
||||
"promptTemplate": "审核以下报告,输出 JSON {passed:boolean, issues:array, revisedAdvice:string}:\n{{ nodes.agent_write.data.answer }}",
|
||||
"responseMode": "json",
|
||||
"responseSchema": {
|
||||
"type": "object",
|
||||
"required": ["passed", "issues", "revisedAdvice"],
|
||||
"properties": {
|
||||
"passed": { "type": "boolean" },
|
||||
"issues": { "type": "array" },
|
||||
"revisedAdvice": { "type": "string" }
|
||||
}
|
||||
},
|
||||
"threadMode": "isolated_per_node",
|
||||
"timeoutSeconds": 600
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "cond_review",
|
||||
"type": "condition",
|
||||
"name": "审核结果分支",
|
||||
"config": {
|
||||
"branches": [
|
||||
{
|
||||
"name": "passed",
|
||||
"expression": "{{ nodes.agent_review.data.passed }} == true"
|
||||
},
|
||||
{
|
||||
"name": "rejected",
|
||||
"expression": "{{ nodes.agent_review.data.passed }} == false"
|
||||
}
|
||||
],
|
||||
"defaultBranch": "rejected"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "loop_revise",
|
||||
"type": "loop",
|
||||
"name": "退回修改(最多 2 次)",
|
||||
"config": {
|
||||
"maxIterations": 2,
|
||||
"continueWhen": "{{ nodes.agent_review.data.passed }} == false",
|
||||
"bodyEntry": "agent_write"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "transform_pack",
|
||||
"type": "transform",
|
||||
"name": "组装最终字段",
|
||||
"config": {
|
||||
"operations": [
|
||||
{
|
||||
"op": "map",
|
||||
"from": "{{ nodes.agent_write.data.answer }}",
|
||||
"to": "reportMarkdown"
|
||||
},
|
||||
{
|
||||
"op": "map",
|
||||
"from": "{{ nodes.agent_review.data.passed }}",
|
||||
"to": "passed"
|
||||
},
|
||||
{
|
||||
"op": "map",
|
||||
"from": "{{ nodes.agent_review.data.issues }}",
|
||||
"to": "issues"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "output_1",
|
||||
"type": "output",
|
||||
"name": "输出",
|
||||
"config": {
|
||||
"mapping": {
|
||||
"reportMarkdown": "{{ nodes.transform_pack.data.reportMarkdown }}",
|
||||
"passed": "{{ nodes.transform_pack.data.passed }}",
|
||||
"issues": "{{ nodes.transform_pack.data.issues }}"
|
||||
},
|
||||
"llmRepair": false
|
||||
}
|
||||
}
|
||||
],
|
||||
"edges": [
|
||||
{ "id": "e_start_sql", "source": "start_1", "target": "sql_1" },
|
||||
{ "id": "e_start_http", "source": "start_1", "target": "http_1" },
|
||||
{ "id": "e_start_collect", "source": "start_1", "target": "agent_collect" },
|
||||
{ "id": "e_sql_merge", "source": "sql_1", "target": "merge_1" },
|
||||
{ "id": "e_http_merge", "source": "http_1", "target": "merge_1" },
|
||||
{ "id": "e_collect_merge", "source": "agent_collect", "target": "merge_1" },
|
||||
{ "id": "e_merge_clean", "source": "merge_1", "target": "agent_clean" },
|
||||
{ "id": "e_clean_write", "source": "agent_clean", "target": "agent_write" },
|
||||
{ "id": "e_write_review", "source": "agent_write", "target": "agent_review" },
|
||||
{ "id": "e_review_cond", "source": "agent_review", "target": "cond_review" },
|
||||
{
|
||||
"id": "e_cond_pass",
|
||||
"source": "cond_review",
|
||||
"target": "transform_pack",
|
||||
"sourcePort": "passed"
|
||||
},
|
||||
{
|
||||
"id": "e_cond_reject",
|
||||
"source": "cond_review",
|
||||
"target": "loop_revise",
|
||||
"sourcePort": "rejected"
|
||||
},
|
||||
{
|
||||
"id": "e_loop_write",
|
||||
"source": "loop_revise",
|
||||
"target": "agent_write",
|
||||
"sourcePort": "continue"
|
||||
},
|
||||
{
|
||||
"id": "e_loop_fail",
|
||||
"source": "loop_revise",
|
||||
"target": "transform_pack",
|
||||
"sourcePort": "exhausted"
|
||||
},
|
||||
{ "id": "e_pack_out", "source": "transform_pack", "target": "output_1" }
|
||||
],
|
||||
"settings": {
|
||||
"runTimeoutSeconds": 1800,
|
||||
"nodeTimeoutSeconds": 300,
|
||||
"maxSteps": 200,
|
||||
"maxLoopIterations": 5,
|
||||
"maxParallelism": 4
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"schemaVersion": "1.0",
|
||||
"id": "wf_start_output",
|
||||
"name": "空图:开始→输出",
|
||||
"description": "阶段2运行骨架用的最小可执行图",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"message": { "type": "string" }
|
||||
}
|
||||
},
|
||||
"outputSchema": {
|
||||
"type": "object",
|
||||
"required": ["message"],
|
||||
"properties": {
|
||||
"message": { "type": "string" }
|
||||
}
|
||||
},
|
||||
"nodes": [
|
||||
{ "id": "start_1", "type": "start", "name": "开始", "config": {} },
|
||||
{
|
||||
"id": "output_1",
|
||||
"type": "output",
|
||||
"name": "输出",
|
||||
"config": {
|
||||
"mapping": { "message": "{{ inputs.message }}" },
|
||||
"llmRepair": false
|
||||
}
|
||||
}
|
||||
],
|
||||
"edges": [
|
||||
{ "id": "e1", "source": "start_1", "target": "output_1" }
|
||||
],
|
||||
"settings": {
|
||||
"runTimeoutSeconds": 60,
|
||||
"nodeTimeoutSeconds": 30,
|
||||
"maxSteps": 10,
|
||||
"maxLoopIterations": 1,
|
||||
"maxParallelism": 1
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user