From 58f40942d0d5baf8221e1a2dc6af2b6fd27b9355 Mon Sep 17 00:00:00 2001 From: laansdole Date: Sat, 14 Nov 2026 10:59:45 +0700 Subject: [PATCH] feat: workflow designer agent and Generate dialog Describe a workflow in plain language and an agent writes the YAML. - yaml_instance/workflow_designer.yaml: one agent with function tools that read the authoring guide, node docs and bundled examples, and validate its YAML with check_config. Its validator also requires the BASE_URL, API_KEY and MODEL_NAME placeholders on agent nodes and rejects key-like strings. - functions/edge_processor/workflow_design.py: re-validates the output on the edge; invalid YAML reaches the end node with its errors as comments. - frontend: Generate button on the workflow list opens a dialog that runs the designer via POST /api/workflow/run, shows an editable preview, and saves with postYaml before opening the workbench. - postYaml now surfaces the server's error message ({error: {message}} and string detail) and returns the HTTP status; it previously showed 'Unknown error' or the status text. - docs: web UI guide (en, zh). --- docs/user_guide/en/web_ui_guide.md | 3 + docs/user_guide/zh/web_ui_guide.md | 3 + .../src/components/GenerateWorkflowModal.vue | 416 ++++++++++++++++++ frontend/src/locales/en.json | 21 + frontend/src/locales/zh.json | 21 + frontend/src/pages/WorkflowList.vue | 53 +++ frontend/src/utils/apiFunctions.js | 24 +- functions/edge_processor/workflow_design.py | 25 ++ functions/function_calling/workflow_design.py | 82 ++++ tests/test_workflow_designer.py | 51 +++ yaml_instance/workflow_designer.yaml | 55 +++ 11 files changed, 751 insertions(+), 3 deletions(-) create mode 100644 frontend/src/components/GenerateWorkflowModal.vue create mode 100644 functions/edge_processor/workflow_design.py create mode 100644 functions/function_calling/workflow_design.py create mode 100644 tests/test_workflow_designer.py create mode 100644 yaml_instance/workflow_designer.yaml diff --git a/docs/user_guide/en/web_ui_guide.md b/docs/user_guide/en/web_ui_guide.md index f20a393362..5c17c1e55d 100755 --- a/docs/user_guide/en/web_ui_guide.md +++ b/docs/user_guide/en/web_ui_guide.md @@ -20,6 +20,9 @@ View and manage all available workflow YAML files. - Browse workflows in `yaml_instance/` directory - Preview YAML configuration content - Select workflow to execute or edit +- **Generate**: describe a workflow in plain language and an agent writes the YAML (see below) + +**Generating a workflow**: Generate runs `yaml_instance/workflow_designer.yaml` with the server's `BASE_URL`, `API_KEY` and its `MODEL_NAME` (default `gpt-4o`). The designer reads the authoring guide, node docs and bundled examples through function tools, then validates its YAML with the same check the save route uses. Its validator also requires every agent node to use the `${BASE_URL}`, `${API_KEY}` and `${MODEL_NAME}` placeholders and rejects anything that looks like an API key. The result opens in an editable preview; **Save and open** writes it to `yaml_instance/.yaml` and opens it in the workbench. If the YAML still fails validation, the errors are listed as comments at the top; schema errors also block saving. The same workflow runs headless: `echo "your description" | uv run python run.py --path yaml_instance/workflow_designer.yaml --name designer`. ### 2.3 Launch View diff --git a/docs/user_guide/zh/web_ui_guide.md b/docs/user_guide/zh/web_ui_guide.md index b7cb8ccb0f..8ae687d9e7 100755 --- a/docs/user_guide/zh/web_ui_guide.md +++ b/docs/user_guide/zh/web_ui_guide.md @@ -20,6 +20,9 @@ - 浏览 `yaml_instance/` 目录下的工作流 - 预览 YAML 配置内容 - 选择工作流进入执行或编辑 +- **生成 (Generate)**:用自然语言描述工作流,由智能体编写 YAML(见下文) + +**生成工作流**:“生成”会使用服务器的 `BASE_URL`、`API_KEY` 以及工作流自身的 `MODEL_NAME`(默认 `gpt-4o`)运行 `yaml_instance/workflow_designer.yaml`。设计器通过函数工具阅读编写指南、节点文档和内置示例,并用与保存接口相同的校验检查生成的 YAML。它的校验还要求每个智能体节点使用 `${BASE_URL}`、`${API_KEY}` 和 `${MODEL_NAME}` 占位符,并拒绝任何疑似 API 密钥的内容。结果显示在可编辑的预览中;**保存并打开**会将其写入 `yaml_instance/<名称>.yaml` 并在工作台中打开。若 YAML 仍未通过校验,错误会以注释形式列在顶部;结构错误同样会阻止保存。也可以在命令行运行:`echo "你的描述" | uv run python run.py --path yaml_instance/workflow_designer.yaml --name designer`。 ### 2.3 启动页 (Launch View) diff --git a/frontend/src/components/GenerateWorkflowModal.vue b/frontend/src/components/GenerateWorkflowModal.vue new file mode 100644 index 0000000000..2328f5b61b --- /dev/null +++ b/frontend/src/components/GenerateWorkflowModal.vue @@ -0,0 +1,416 @@ + + + + + diff --git a/frontend/src/locales/en.json b/frontend/src/locales/en.json index d1fa54e6e8..9324188a13 100644 --- a/frontend/src/locales/en.json +++ b/frontend/src/locales/en.json @@ -71,6 +71,27 @@ "loading": "Loading workflows...", "no_files": "No workflow files found" }, + "workflow_generate": { + "button": "Generate", + "button_title": "Describe a workflow and let an agent write the YAML", + "title": "Generate workflow", + "description_label": "What should the workflow do?", + "description_placeholder": "Example: a writer drafts a blog post, an editor reviews it and sends feedback for up to 3 rounds, then the approved post is published.", + "description_hint": "Runs workflow_designer.yaml with the server's model and API key. Ctrl or Cmd + Enter to generate.", + "generate": "Generate", + "generating": "Designing the workflow... {seconds}s", + "yaml_label": "Generated YAML (editable)", + "needs_fixes": "This YAML did not pass validation. The errors are listed as comments at the top; fix them before saving.", + "filename_label": "File name", + "filename_invalid": "Use only letters, digits, dots, hyphens and underscores.", + "back": "Back", + "save_and_open": "Save and open", + "saving": "Saving...", + "empty_result": "The designer returned no output.", + "request_failed": "Generation failed: {reason}", + "save_failed": "Could not save: {reason}", + "save_conflict": "A workflow with this file name already exists. Choose another file name." + }, "workflow_view": { "yaml_parse_error": "YAML Parse Error: ", "loading_yaml": "Loading YAML content...", diff --git a/frontend/src/locales/zh.json b/frontend/src/locales/zh.json index 3b3754fe43..413f755e34 100644 --- a/frontend/src/locales/zh.json +++ b/frontend/src/locales/zh.json @@ -49,6 +49,27 @@ "loading": "加载工作流中...", "no_files": "未找到工作流文件" }, + "workflow_generate": { + "button": "生成", + "button_title": "描述工作流,由智能体编写 YAML", + "title": "生成工作流", + "description_label": "这个工作流要做什么?", + "description_placeholder": "示例:写手起草一篇博客,编辑审阅并最多反馈 3 轮,审核通过后发布。", + "description_hint": "使用服务器的模型和 API 密钥运行 workflow_designer.yaml。按 Ctrl 或 Cmd + Enter 生成。", + "generate": "生成", + "generating": "正在设计工作流... {seconds} 秒", + "yaml_label": "生成的 YAML(可编辑)", + "needs_fixes": "此 YAML 未通过校验。错误以注释形式列在顶部,请修复后再保存。", + "filename_label": "文件名", + "filename_invalid": "只能使用字母、数字、点、连字符和下划线。", + "back": "返回", + "save_and_open": "保存并打开", + "saving": "保存中...", + "empty_result": "设计器没有返回任何内容。", + "request_failed": "生成失败:{reason}", + "save_failed": "无法保存:{reason}", + "save_conflict": "已存在同名工作流文件,请换一个文件名。" + }, "workflow_view": { "yaml_parse_error": "YAML 解析错误:", "loading_yaml": "正在加载 YAML 内容...", diff --git a/frontend/src/pages/WorkflowList.vue b/frontend/src/pages/WorkflowList.vue index 6ede2cead2..9e10d5377d 100755 --- a/frontend/src/pages/WorkflowList.vue +++ b/frontend/src/pages/WorkflowList.vue @@ -16,6 +16,10 @@ /> + +