fastgpt-workflow-generator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

FastGPT Workflow Generator

FastGPT工作流生成器

Automatically generate production-ready FastGPT workflow JSON from natural language requirements
根据自然语言需求自动生成可直接用于生产环境的FastGPT工作流JSON

When to Use This Skill

何时使用该技能

Use this skill when you need to:
  • Create new workflows from scratch: User asks to "create a FastGPT workflow for X purpose"
  • Generate based on templates: User wants to build workflows similar to existing patterns (document processing, AI chat, data analysis, multi-agent systems)
  • Modify existing workflows: User needs to add/remove/update nodes in an existing workflow JSON
  • Validate workflow JSON: User has a workflow JSON that needs verification or fixing
  • Design multi-agent systems: User mentions parallel processing, agent coordination, or workflow orchestration
  • Automate workflow creation: User provides requirements document and needs executable JSON
  • Convert requirements to JSON: User has specifications and wants a FastGPT-compatible workflow
Trigger Keywords: FastGPT, workflow, JSON, multi-agent, 工作流, template matching, workflow automation, node configuration, workflow validation

在以下场景中使用本技能:
  • 从零创建新工作流:用户要求“为X用途创建FastGPT工作流”
  • 基于模板生成:用户希望构建与现有模式(文档处理、AI聊天、数据分析、多智能体系统)类似的工作流
  • 修改现有工作流:用户需要在现有工作流JSON中添加/删除/更新节点
  • 验证工作流JSON:用户有需要验证或修复的工作流JSON
  • 设计多智能体系统:用户提及并行处理、智能体协调或工作流编排
  • 自动化工作流创建:用户提供需求文档,需要可执行的JSON
  • 将需求转换为JSON:用户有规格说明,需要生成兼容FastGPT的工作流
触发关键词:FastGPT, workflow, JSON, multi-agent, 工作流, template matching, workflow automation, node configuration, workflow validation

Core Workflow

核心工作流

This skill follows a 5-phase process to generate production-ready workflow JSON:
本技能遵循5阶段流程生成可用于生产环境的工作流JSON:

Phase 1: Requirements Analysis

阶段1:需求分析

Goal: Extract structured requirements from natural language input
Process:
  1. Identify request type:
    • Create from scratch
    • Based on template
    • Modify existing workflow
    • Validate/fix existing JSON
  2. Extract key information using AI semantic analysis:
    json
    {
      "purpose": "Workflow objective (e.g., 'Travel planning assistance')",
      "domain": "Application domain (travel/event/document/data/general)",
      "complexity": "simple | medium | complex",
      "features": ["aiChat", "knowledgeBase", "httpRequest", "parallel"],
      "inputs": ["userChatInput", "city", "date"],
      "outputs": ["Complete plan", "Recommendations"],
      "externalIntegrations": ["Weather API", "Feishu API"],
      "specialRequirements": ["Multi-agent", "Real-time data"]
    }
  3. Completeness check: If information is insufficient, clarify through dialogue
Output: Structured requirements object

目标:从自然语言输入中提取结构化需求
流程
  1. 识别请求类型
    • 从零创建
    • 基于模板
    • 修改现有工作流
    • 验证/修复现有JSON
  2. 使用AI语义分析提取关键信息
    json
    {
      "purpose": "工作流目标(例如:'旅行规划协助')",
      "domain": "应用领域(旅行/活动/文档/数据/通用)",
      "complexity": "simple | medium | complex",
      "features": ["aiChat", "knowledgeBase", "httpRequest", "parallel"],
      "inputs": ["userChatInput", "city", "date"],
      "outputs": ["完整规划", "推荐建议"],
      "externalIntegrations": ["Weather API", "飞书API"],
      "specialRequirements": ["Multi-agent", "实时数据"]
    }
  3. 完整性检查:如果信息不足,通过对话澄清
输出:结构化需求对象

Phase 2: Template Matching

阶段2:模板匹配

Goal: Find the most similar built-in template
Built-in Templates (stored in
templates/
directory):
  • templates/文档翻译助手.json
    - Simple workflow (document processing)
  • templates/销售陪练大师.json
    - Medium complexity (conversational AI)
  • templates/简历筛选助手_飞书.json
    - Complex workflow (data processing + external integration)
  • templates/AI金融日报.json
    - Scheduled trigger + multi-agent (news aggregation)
Matching Strategy:
Step 1: Coarse Filtering (Metadata-based)
Calculate similarity scores:
- Domain match: travel vs travel = 1.0, travel vs event = 0.3
- Complexity match: simple vs simple = 1.0, simple vs complex = 0.3
- Feature overlap: Jaccard similarity of feature sets
- Node count similarity: 1 - |count1 - count2| / max(count1, count2)

Combined score = 0.3 * domain + 0.2 * complexity + 0.3 * features + 0.2 * nodeCount

Select Top 3 candidate templates
Step 2: Fine Filtering (Semantic Similarity)
For Top 3 candidates:
1. Analyze user requirements vs template characteristics
2. Evaluate workflow structure similarity
3. Calculate comprehensive score

Final score = 0.3 * domain + 0.2 * complexity + 0.3 * features + 0.2 * semantic
Step 3: Selection Strategy
- Highest score < 0.5: Start from blank template
- Highest score 0.5-0.7: Use template as reference, major modifications
- Highest score > 0.7: Use template as base, minor adjustments
Output:
  • Best matching template JSON object
  • Matching analysis report
  • Modification suggestions list

目标:找到最相似的内置模板
内置模板(存储在
templates/
目录中):
  • templates/文档翻译助手.json
    - 简单工作流(文档处理)
  • templates/销售陪练大师.json
    - 中等复杂度(对话式AI)
  • templates/简历筛选助手_飞书.json
    - 复杂工作流(数据处理+外部集成)
  • templates/AI金融日报.json
    - 定时触发+多智能体(新闻聚合)
匹配策略
步骤1:粗过滤(基于元数据)
计算相似度得分:
- 领域匹配:旅行vs旅行=1.0,旅行vs活动=0.3
- 复杂度匹配:简单vs简单=1.0,简单vs复杂=0.3
- 功能重叠:功能集合的杰卡德相似度
- 节点数量相似度:1 - |count1 - count2| / max(count1, count2)

综合得分 = 0.3*领域 + 0.2*复杂度 + 0.3*功能 + 0.2*节点数量

选择前3个候选模板
步骤2:细过滤(语义相似度)
对于前3个候选模板:
1. 分析用户需求与模板特征
2. 评估工作流结构相似度
3. 计算综合得分

最终得分 = 0.3*领域 + 0.2*复杂度 + 0.3*功能 + 0.2*语义
步骤3:选择策略
- 最高得分 < 0.5:从空白模板开始
- 最高得分 0.5-0.7:以模板为参考,进行重大修改
- 最高得分 > 0.7:以模板为基础,进行小幅调整
输出
  • 最佳匹配模板JSON对象
  • 匹配分析报告
  • 修改建议列表

Phase 3: JSON Generation

阶段3:JSON生成

Scenario 1: Generate Based on Template
1. Copy template structure

2. Modify nodes
   - Keep: structurally similar nodes (workflowStart, userGuide)
   - Modify: nodes requiring prompt/parameter adjustments
   - Delete: unnecessary nodes
   - Add: new requirement nodes

3. Regenerate NodeId
   function generateNodeId(nodeType, nodeName, existingIds) {
     // Fixed ID mapping
     if (nodeType === 'workflowStart') return 'workflowStart';
     if (nodeType === 'userGuide' || nodeType === 'systemConfig') return 'userGuide';

     // Generate semantic ID (camelCase)
     const baseName = nodeName.replace(/[\s\u4e00-\u9fa5]+/g, '');
     let nodeId = baseName ? `${baseName}Node` : `${nodeType}Node`;

     // Ensure uniqueness
     let counter = 1;
     while (existingIds.has(nodeId)) {
       nodeId = `${baseName}Node_${counter}`;
       counter++;
     }

     return nodeId;
   }

4. Update references
   - Traverse all inputs, replace old nodeId with new nodeId
   - Update edges' source/target
   - Handle two reference formats:
     - Array: ["nodeId", "key"]
     - Template: {{$nodeId.key$}}  (Note: double braces with single $)

5. Auto-layout positions (hierarchical layout algorithm)
   function autoLayout(nodes, edges) {
     // Topological sort to determine layers
     const layers = topologicalLayering(nodes, edges);

     // Calculate positions for each layer
     const LAYER_GAP_X = 350;
     const NODE_GAP_Y = 150;

     layers.forEach((layer, layerIndex) => {
       const x = -200 + layerIndex * LAYER_GAP_X;
       const totalHeight = (layer.length - 1) * NODE_GAP_Y;
       const startY = -totalHeight / 2;

       layer.forEach((nodeId, nodeIndex) => {
         positions[nodeId] = {
           x: x,
           y: startY + nodeIndex * NODE_GAP_Y
         };
       });
     });

     // Fixed position for special nodes
     positions['userGuide'] = { x: -600, y: -250 };
   }

6. Update configuration
   - Modify chatConfig.welcomeText
   - Update chatConfig.variables
Scenario 2: Create from Scratch
1. Determine node list
   - Required: workflowStart, userGuide
   - Add based on features: chatNode, datasetSearchNode, httpRequest468, etc.
   - Required: answerNode (output node)

2. Generate nodes and connections
   - Use standard node templates
   - Fill required fields
   - Customize inputs/outputs based on requirements

3. Calculate positions and generate configuration
Output: Complete FastGPT workflow JSON

场景1:基于模板生成
1. 复制模板结构

2. 修改节点
   - 保留:结构相似的节点(workflowStart, userGuide)
   - 修改:需要调整提示词/参数的节点
   - 删除:不必要的节点
   - 添加:满足新需求的节点

3. 重新生成NodeId
   function generateNodeId(nodeType, nodeName, existingIds) {
     // 固定ID映射
     if (nodeType === 'workflowStart') return 'workflowStart';
     if (nodeType === 'userGuide' || nodeType === 'systemConfig') return 'userGuide';

     // 生成语义化ID(驼峰式)
     const baseName = nodeName.replace(/[\s\u4e00-\u9fa5]+/g, '');
     let nodeId = baseName ? `${baseName}Node` : `${nodeType}Node`;

     // 确保唯一性
     let counter = 1;
     while (existingIds.has(nodeId)) {
       nodeId = `${baseName}Node_${counter}`;
       counter++;
     }

     return nodeId;
   }

4. 更新引用
   - 遍历所有输入,将旧nodeId替换为新nodeId
   - 更新edges的source/target
   - 处理两种引用格式:
     - 数组格式:["nodeId", "key"]
     - 模板格式:{{$nodeId.key$}} (注意:双大括号加单个$)

5. 自动布局位置(分层布局算法)
   function autoLayout(nodes, edges) {
     // 拓扑排序确定层级
     const layers = topologicalLayering(nodes, edges);

     // 计算每个层级的位置
     const LAYER_GAP_X = 350;
     const NODE_GAP_Y = 150;

     layers.forEach((layer, layerIndex) => {
       const x = -200 + layerIndex * LAYER_GAP_X;
       const totalHeight = (layer.length - 1) * NODE_GAP_Y;
       const startY = -totalHeight / 2;

       layer.forEach((nodeId, nodeIndex) => {
         positions[nodeId] = {
           x: x,
           y: startY + nodeIndex * NODE_GAP_Y
         };
       });
     });

     // 特殊节点的固定位置
     positions['userGuide'] = { x: -600, y: -250 };
   }

6. 更新配置
   - 修改chatConfig.welcomeText
   - 更新chatConfig.variables
场景2:从零创建
1. 确定节点列表
   - 必填:workflowStart, userGuide
   - 根据功能添加:chatNode, datasetSearchNode, httpRequest468等
   - 必填:answerNode(输出节点)

2. 生成节点和连接
   - 使用标准节点模板
   - 填充必填字段
   - 根据需求自定义输入/输出

3. 计算位置并生成配置
输出:完整的FastGPT工作流JSON

Phase 4: Validation

阶段4:验证

Level 1: JSON Format Validation
✅ JSON is parseable
✅ Top level contains nodes, edges, chatConfig
✅ Each node contains: nodeId, name, flowNodeType, position, inputs, outputs
✅ flowNodeType is in valid type list (40+ types)
✅ position contains x, y numeric coordinates
Level 2: Node Connection Validation
✅ edges' source/target nodes exist
✅ sourceHandle/targetHandle format correct (nodeId-source-right, nodeId-target-left)
✅ Node input references' nodes and output keys exist
✅ Reference types match (string → string)
✅ Template references {{$nodeId.key$}} nodes and keys exist
✅ No self-loops, no duplicate connections
Level 3: Logic Completeness Validation
✅ Required nodes exist (workflowStart, userGuide, at least one output node)
✅ All nodes reachable from workflowStart (connectivity)
✅ No illegal cycles (unless using loop node)
✅ loop nodes correctly configured with parentNodeId and childrenNodeIdList
✅ No dead ends (non-output nodes without outgoing edges)
✅ All required inputs have values
Output: Validation report (containing errors, warnings, fix suggestions)

第一层:JSON格式验证
✅ JSON可解析
✅ 顶层包含nodes, edges, chatConfig
✅ 每个节点包含:nodeId, name, flowNodeType, position, inputs, outputs
✅ flowNodeType属于有效类型列表(40+种)
✅ position包含x, y数值坐标
第二层:节点连接验证
✅ edges的source/target节点存在
✅ sourceHandle/targetHandle格式正确(nodeId-source-right, nodeId-target-left)
✅ 节点输入引用的节点和输出键存在
✅ 引用类型匹配(字符串→字符串)
✅ 模板引用{{$nodeId.key$}}的节点和键存在
✅ 无自环,无重复连接
第三层:逻辑完整性验证
✅ 必填节点存在(workflowStart, userGuide, 至少一个输出节点)
✅ 所有节点可从workflowStart到达(连通性)
✅ 无非法循环(除非使用loop节点)
✅ loop节点正确配置parentNodeId和childrenNodeIdList
✅ 无死胡同(非输出节点没有出边)
✅ 所有必填输入都有值
输出:验证报告(包含错误、警告、修复建议)

Phase 5: Incremental Modification (Optional)

阶段5:增量修改(可选)

Use Cases: Add/delete/modify nodes
Processing Steps:
1. Understand modification intent
Use AI to analyze user request, extract:
{
  "action": "add" | "delete" | "modify" | "reconnect",
  "targetNodes": ["aiChatNode"],
  "insertBefore": "aiChatNode",
  "newNodes": [{ "type": "datasetSearchNode", "name": "Knowledge Base Search" }],
  "modifications": {
    "aiChatNode": {
      "inputs": { "quoteQA": ["knowledgeBaseSearch", "searchResult"] }
    }
  }
}
2. Execute modifications
- Add node: generate new node, reconnect, calculate position
- Delete node: remove node, bypass reconnect, clean references
- Modify node: update inputs/outputs, validate references
3. Re-layout and validate

使用场景:添加/删除/修改节点
处理步骤
1. 理解修改意图
使用AI分析用户请求,提取:
{
  "action": "add" | "delete" | "modify" | "reconnect",
  "targetNodes": ["aiChatNode"],
  "insertBefore": "aiChatNode",
  "newNodes": [{ "type": "datasetSearchNode", "name": "知识库搜索" }],
  "modifications": {
    "aiChatNode": {
      "inputs": { "quoteQA": ["knowledgeBaseSearch", "searchResult"] }
    }
  }
}
2. 执行修改
- 添加节点:生成新节点,重新连接,计算位置
- 删除节点:移除节点,绕过连接,清理引用
- 修改节点:更新输入/输出,验证引用
3. 重新布局并验证

Examples

示例

Example 1: Simple AI Q&A Workflow

示例1:简单AI问答工作流

User Request:
"Create a simple AI Q&A workflow where users input questions and AI responds directly"
Skill Processing:
  1. Requirements Analysis
    json
    {
      "purpose": "AI question answering",
      "domain": "general",
      "complexity": "simple",
      "features": ["aiChat"],
      "inputs": ["userChatInput"],
      "outputs": ["AI response"]
    }
  2. Template Matching
    • 文档翻译助手.json
      - Score: 0.85 (simple workflow, direct processing)
  3. JSON Generation
    • Use template, modify systemPrompt and welcomeText
  4. Validation Result
    • ✅ All three layers pass validation
Generated JSON (key parts):
json
{
  "nodes": [
    {
      "nodeId": "userGuide",
      "name": "System Configuration",
      "flowNodeType": "userGuide",
      "position": {"x": -600, "y": -250}
    },
    {
      "nodeId": "workflowStart",
      "name": "Start",
      "flowNodeType": "workflowStart",
      "position": {"x": -150, "y": 100},
      "outputs": [
        {"key": "userChatInput", "type": "static", "valueType": "string"}
      ]
    },
    {
      "nodeId": "aiChatNode",
      "name": "AI Response",
      "flowNodeType": "chatNode",
      "position": {"x": 200, "y": 100},
      "inputs": [
        {
          "key": "model",
          "valueType": "string",
          "value": "gpt-4"
        },
        {
          "key": "systemPrompt",
          "valueType": "string",
          "value": "You are a professional AI assistant that can answer various questions. Please provide accurate and helpful answers based on user questions."
        },
        {
          "key": "userChatInput",
          "valueType": "string",
          "value": ["workflowStart", "userChatInput"]
        }
      ],
      "outputs": [
        {"key": "answerText", "type": "static", "valueType": "string"}
      ]
    },
    {
      "nodeId": "outputNode",
      "name": "Output Answer",
      "flowNodeType": "answerNode",
      "position": {"x": 550, "y": 100},
      "inputs": [
        {
          "key": "text",
          "valueType": "string",
          "value": ["aiChatNode", "answerText"]
        }
      ]
    }
  ],
  "edges": [
    {
      "source": "workflowStart",
      "target": "aiChatNode",
      "sourceHandle": "workflowStart-source-right",
      "targetHandle": "aiChatNode-target-left"
    },
    {
      "source": "aiChatNode",
      "target": "outputNode",
      "sourceHandle": "aiChatNode-source-right",
      "targetHandle": "outputNode-target-left"
    }
  ],
  "chatConfig": {
    "welcomeText": "Welcome to the AI Q&A assistant! Please enter your question.",
    "variables": []
  }
}

用户请求
"创建一个简单的AI问答工作流,用户输入问题后AI直接回复"
技能处理
  1. 需求分析
    json
    {
      "purpose": "AI问答",
      "domain": "general",
      "complexity": "simple",
      "features": ["aiChat"],
      "inputs": ["userChatInput"],
      "outputs": ["AI回复"]
    }
  2. 模板匹配
    • 文档翻译助手.json
      - 得分:0.85(简单工作流,直接处理)
  3. JSON生成
    • 使用模板,修改systemPrompt和welcomeText
  4. 验证结果
    • ✅ 三层验证全部通过
生成的JSON(关键部分):
json
{
  "nodes": [
    {
      "nodeId": "userGuide",
      "name": "系统配置",
      "flowNodeType": "userGuide",
      "position": {"x": -600, "y": -250}
    },
    {
      "nodeId": "workflowStart",
      "name": "开始",
      "flowNodeType": "workflowStart",
      "position": {"x": -150, "y": 100},
      "outputs": [
        {"key": "userChatInput", "type": "static", "valueType": "string"}
      ]
    },
    {
      "nodeId": "aiChatNode",
      "name": "AI回复",
      "flowNodeType": "chatNode",
      "position": {"x": 200, "y": 100},
      "inputs": [
        {
          "key": "model",
          "valueType": "string",
          "value": "gpt-4"
        },
        {
          "key": "systemPrompt",
          "valueType": "string",
          "value": "你是专业的AI助手,可以回答各类问题。请根据用户问题提供准确且有帮助的答案。"
        },
        {
          "key": "userChatInput",
          "valueType": "string",
          "value": ["workflowStart", "userChatInput"]
        }
      ],
      "outputs": [
        {"key": "answerText", "type": "static", "valueType": "string"}
      ]
    },
    {
      "nodeId": "outputNode",
      "name": "输出答案",
      "flowNodeType": "answerNode",
      "position": {"x": 550, "y": 100},
      "inputs": [
        {
          "key": "text",
          "valueType": "string",
          "value": ["aiChatNode", "answerText"]
        }
      ]
    }
  ],
  "edges": [
    {
      "source": "workflowStart",
      "target": "aiChatNode",
      "sourceHandle": "workflowStart-source-right",
      "targetHandle": "aiChatNode-target-left"
    },
    {
      "source": "aiChatNode",
      "target": "outputNode",
      "sourceHandle": "aiChatNode-source-right",
      "targetHandle": "outputNode-target-left"
    }
  ],
  "chatConfig": {
    "welcomeText": "欢迎使用AI问答助手!请输入你的问题。",
    "variables": []
  }
}

Example 2: Document Translation Workflow (Based on Template)

示例2:文档翻译工作流(基于模板)

User Request:
"Create a document translation workflow that translates user-uploaded documents from Chinese to English"
Skill Processing:
  1. Requirements Analysis
    json
    {
      "purpose": "Document translation",
      "domain": "document",
      "complexity": "medium",
      "features": ["readFiles", "aiChat", "textOutput"],
      "inputs": ["userFiles"],
      "outputs": ["translated document"]
    }
  2. Template Matching
    • 文档翻译助手.json
      - Score: 0.95 (perfect match!)
  3. JSON Generation
    • Use template directly, only adjust language direction in prompt
Generated Workflow Structure:
workflowStart → readFiles → translateNode → outputNode
Key Node Configuration:
  • readFiles Node: Reads user-uploaded files
  • translateNode (chatNode): AI translates with specialized prompt
  • outputNode (answerNode): Outputs translated text

用户请求
"创建一个文档翻译工作流,将用户上传的文档从中文翻译成英文"
技能处理
  1. 需求分析
    json
    {
      "purpose": "文档翻译",
      "domain": "document",
      "complexity": "medium",
      "features": ["readFiles", "aiChat", "textOutput"],
      "inputs": ["userFiles"],
      "outputs": ["翻译后的文档"]
    }
  2. 模板匹配
    • 文档翻译助手.json
      - 得分:0.95(完美匹配!)
  3. JSON生成
    • 直接使用模板,仅调整提示词中的语言方向
生成的工作流结构
workflowStart → readFiles → translateNode → outputNode
关键节点配置
  • readFiles节点:读取用户上传的文件
  • translateNode(chatNode):AI使用专用提示词进行翻译
  • outputNode(answerNode):输出翻译后的文本

Example 3: Incremental Modification (Add Knowledge Base)

示例3:增量修改(添加知识库)

User Request:
"I have an existing AI Q&A workflow (simple_qa_workflow.json),
I want to search the knowledge base first before AI answers,
find relevant information then generate response"
Existing Workflow Structure:
workflowStart → aiChatNode → outputNode
Modification Goal:
workflowStart → knowledgeBaseSearch → aiChatNode → outputNode
Skill Processing:
  1. Analyze Modification Intent
    json
    {
      "action": "add",
      "targetNodes": ["aiChatNode"],
      "insertBefore": "aiChatNode",
      "newNodes": [
        {
          "type": "datasetSearchNode",
          "name": "Knowledge Base Search"
        }
      ],
      "modifications": {
        "aiChatNode": {
          "inputs": {
            "quoteQA": ["knowledgeBaseSearch", "searchResult"]
          }
        }
      }
    }
  2. Execute Modification
    • Add
      knowledgeBaseSearch
      node
    • Modify edge:
      workflowStart → knowledgeBaseSearch
    • Add edge:
      knowledgeBaseSearch → aiChatNode
    • Modify aiChatNode's inputs (add quoteQA)
  3. Re-layout Positions
    • workflowStart: (-150, 100)
    • knowledgeBaseSearch: (50, 100) ← newly inserted
    • aiChatNode: (400, 100) ← shifted right
    • outputNode: (750, 100) ← shifted right
  4. Validation Result
    • ✅ All validations pass
Modified JSON (new and modified parts):
json
{
  "nodes": [
    {
      "nodeId": "knowledgeBaseSearch",
      "name": "Knowledge Base Search",
      "flowNodeType": "datasetSearchNode",
      "position": {"x": 50, "y": 100},
      "inputs": [
        {
          "key": "datasetIds",
          "valueType": "selectDataset",
          "value": [],
          "required": true
        },
        {
          "key": "searchQuery",
          "valueType": "string",
          "value": ["workflowStart", "userChatInput"],
          "required": true
        },
        {
          "key": "similarity",
          "valueType": "number",
          "value": 0.5
        },
        {
          "key": "limitCount",
          "valueType": "number",
          "value": 5
        }
      ],
      "outputs": [
        {
          "key": "searchResult",
          "type": "static",
          "valueType": "datasetQuote"
        }
      ]
    },
    {
      "nodeId": "aiChatNode",
      "inputs": [
        {
          "key": "quoteQA",
          "valueType": "datasetQuote",
          "value": ["knowledgeBaseSearch", "searchResult"]
        }
      ]
    }
  ],
  "edges": [
    {
      "source": "workflowStart",
      "target": "knowledgeBaseSearch"
    },
    {
      "source": "knowledgeBaseSearch",
      "target": "aiChatNode"
    },
    {
      "source": "aiChatNode",
      "target": "outputNode"
    }
  ]
}
Modification Summary Report:
  • ✅ Added 1 node:
    knowledgeBaseSearch
    (datasetSearchNode)
  • ✅ Modified 1 node:
    aiChatNode
    (added quoteQA input)
  • ✅ Added 1 edge:
    knowledgeBaseSearch → aiChatNode
  • ✅ Modified 1 edge:
    workflowStart → knowledgeBaseSearch
    (originally
    workflowStart → aiChatNode
    )
  • ✅ Re-layouted all positions

用户请求
"我有一个现有的AI问答工作流(simple_qa_workflow.json),
我希望AI回答前先搜索知识库,
找到相关信息后再生成回复"
现有工作流结构
workflowStart → aiChatNode → outputNode
修改目标
workflowStart → knowledgeBaseSearch → aiChatNode → outputNode
技能处理
  1. 分析修改意图
    json
    {
      "action": "add",
      "targetNodes": ["aiChatNode"],
      "insertBefore": "aiChatNode",
      "newNodes": [
        {
          "type": "datasetSearchNode",
          "name": "知识库搜索"
        }
      ],
      "modifications": {
        "aiChatNode": {
          "inputs": {
            "quoteQA": ["knowledgeBaseSearch", "searchResult"]
          }
        }
      }
    }
  2. 执行修改
    • 添加
      knowledgeBaseSearch
      节点
    • 修改边:
      workflowStart → knowledgeBaseSearch
    • 添加边:
      knowledgeBaseSearch → aiChatNode
    • 修改aiChatNode的输入(添加quoteQA)
  3. 重新布局位置
    • workflowStart: (-150, 100)
    • knowledgeBaseSearch: (50, 100) ← 新插入
    • aiChatNode: (400, 100) ← 右移
    • outputNode: (750, 100) ← 右移
  4. 验证结果
    • ✅ 所有验证通过
修改后的JSON(新增和修改部分):
json
{
  "nodes": [
    {
      "nodeId": "knowledgeBaseSearch",
      "name": "知识库搜索",
      "flowNodeType": "datasetSearchNode",
      "position": {"x": 50, "y": 100},
      "inputs": [
        {
          "key": "datasetIds",
          "valueType": "selectDataset",
          "value": [],
          "required": true
        },
        {
          "key": "searchQuery",
          "valueType": "string",
          "value": ["workflowStart", "userChatInput"],
          "required": true
        },
        {
          "key": "similarity",
          "valueType": "number",
          "value": 0.5
        },
        {
          "key": "limitCount",
          "valueType": "number",
          "value": 5
        }
      ],
      "outputs": [
        {
          "key": "searchResult",
          "type": "static",
          "valueType": "datasetQuote"
        }
      ]
    },
    {
      "nodeId": "aiChatNode",
      "inputs": [
        {
          "key": "quoteQA",
          "valueType": "datasetQuote",
          "value": ["knowledgeBaseSearch", "searchResult"]
        }
      ]
    }
  ],
  "edges": [
    {
      "source": "workflowStart",
      "target": "knowledgeBaseSearch"
    },
    {
      "source": "knowledgeBaseSearch",
      "target": "aiChatNode"
    },
    {
      "source": "aiChatNode",
      "target": "outputNode"
    }
  ]
}
修改总结报告
  • ✅ 添加1个节点:
    knowledgeBaseSearch
    (datasetSearchNode)
  • ✅ 修改1个节点:
    aiChatNode
    (添加quoteQA输入)
  • ✅ 添加1条边:
    knowledgeBaseSearch → aiChatNode
  • ✅ 修改1条边:
    workflowStart → knowledgeBaseSearch
    (原先是
    workflowStart → aiChatNode
  • ✅ 重新布局所有位置

Technical Implementation

技术实现

NodeId Generation Algorithm

NodeId生成算法

Rules:
  1. Fixed IDs:
    workflowStart
    ,
    userGuide
    (systemConfig)
  2. Semantic naming: Generate based on node name (remove spaces and Chinese, convert to camelCase)
  3. Uniqueness guarantee: If conflict, add
    _1
    ,
    _2
    suffix
Examples:
  • generateNodeId('chatNode', 'Travel Planning Assistant')
    TravelPlanningAssistantNode
  • generateNodeId('httpRequest468', 'Weather Query')
    WeatherQueryNode
  • generateNodeId('chatNode', 'Assistant', {TravelPlanningAssistantNode})
    AssistantNode_1
规则
  1. 固定ID:
    workflowStart
    ,
    userGuide
    (systemConfig)
  2. 语义化命名:基于节点名称生成(移除空格和中文,转换为驼峰式)
  3. 唯一性保证:如果冲突,添加
    _1
    ,
    _2
    后缀
示例
  • generateNodeId('chatNode', '旅行规划助手')
    TravelPlanningAssistantNode
  • generateNodeId('httpRequest468', '天气查询')
    WeatherQueryNode
  • generateNodeId('chatNode', '助手', {TravelPlanningAssistantNode})
    AssistantNode_1

Position Auto-Layout Algorithm

位置自动布局算法

Algorithm: Hierarchical Layout
Steps:
  1. Topological sort to determine layers (BFS)
  2. Calculate horizontal position and vertical spacing for each layer
  3. Fixed position for special nodes (userGuide: {x: -600, y: -250})
Parameters:
  • LAYER_GAP_X = 350 (horizontal spacing between layers)
  • NODE_GAP_Y = 150 (vertical spacing within layer)
  • START_X = -200, START_Y = 0
算法:分层布局
步骤
  1. 拓扑排序确定层级(BFS)
  2. 计算每个层级的水平位置和垂直间距
  3. 特殊节点的固定位置(userGuide: {x: -600, y: -250})
参数
  • LAYER_GAP_X = 350(层级间的水平间距)
  • NODE_GAP_Y = 150(层级内的垂直间距)
  • START_X = -200, START_Y = 0

Reference Format Description

引用格式说明

Two Reference Formats:
1. Array Format (direct value reference):
json
"value": ["workflowStart", "userChatInput"]
2. Template Syntax (string concatenation):
json
"value": "Please create a plan for me.\n\nDestination: {{$workflowStart.userChatInput$}}\n\nWeather: {{$weatherQueryNode.httpRawResponse$}}"
Important: Template syntax is
{{$nodeId.key$}}
(double braces with single $)
两种引用格式
1. 数组格式(直接值引用)
json
"value": ["workflowStart", "userChatInput"]
2. 模板语法(字符串拼接)
json
"value": "请为我创建一份规划。\n\n目的地:{{$workflowStart.userChatInput$}}\n\n天气:{{$weatherQueryNode.httpRawResponse$}}"
重要提示:模板语法为
{{$nodeId.key$}}
(双大括号加单个$)

Special Node Handling

特殊节点处理

loop Node:
  • Must have
    childrenNodeIdList
    field
  • Child nodes must have
    parentNodeId
    field
  • Child nodes include: loopStart, [processing nodes...], loopEnd
ifElse Node:
  • Has multiple output branches
  • Each branch corresponds to different conditions

loop节点
  • 必须包含
    childrenNodeIdList
    字段
  • 子节点必须包含
    parentNodeId
    字段
  • 子节点包括:loopStart, [处理节点...], loopEnd
ifElse节点
  • 有多个输出分支
  • 每个分支对应不同的条件

Best Practices

最佳实践

Do's (Recommended Practices)

推荐做法

  • Always validate at three levels - format, connections, logic
  • Use meaningful nodeIds - use semantic names (e.g.,
    weatherQueryNode
    )
  • Prefer template matching - template-based generation is more reliable than creating from scratch
  • Use array references for direct values -
    ["nodeId", "key"]
  • Use template references for string concatenation -
    {{$nodeId.key$}}
  • Auto-layout positions - use auto-layout algorithm
  • Include system config node - always include userGuide
  • Test with validation - use built-in validation before importing to FastGPT
  • Provide clear error messages - include location and fix suggestions
  • Document modifications - generate modification summary report
  • 始终执行三层验证 - 格式、连接、逻辑
  • 使用有意义的nodeId - 使用语义化名称(例如:
    weatherQueryNode
  • 优先使用模板匹配 - 基于模板生成比从零创建更可靠
  • 直接值引用使用数组格式 -
    ["nodeId", "key"]
  • 字符串拼接使用模板引用 -
    {{$nodeId.key$}}
  • 使用自动布局位置 - 使用自动布局算法
  • 包含系统配置节点 - 始终包含userGuide
  • 通过验证测试 - 导入FastGPT前使用内置验证
  • 提供清晰的错误信息 - 包含位置和修复建议
  • 记录修改内容 - 生成修改总结报告

Don'ts (Prohibited Practices)

禁止做法

  • Don't skip validation - never skip validation
  • Don't use invalid node types - check flowNodeType validity
  • Don't create circular references without loop nodes - no illegal cycles
  • Don't forget required fields - nodeId, name, flowNodeType, position, inputs, outputs
  • Don't use wrong reference format - prohibited:
    {{nodeId.key}}
    (missing $)
  • Don't ignore warnings - warnings should be fixed
  • Don't hardcode positions - except userGuide, use auto-layout
  • Don't create unreachable nodes - ensure reachable from workflowStart
  • Don't generate overly complex workflows - workflows with >20 nodes should be split

  • 不要跳过验证 - 绝不跳过验证
  • 不要使用无效节点类型 - 检查flowNodeType的有效性
  • 不要在未使用loop节点的情况下创建循环引用 - 无非法循环
  • 不要遗漏必填字段 - nodeId, name, flowNodeType, position, inputs, outputs
  • 不要使用错误的引用格式 - 禁止:
    {{nodeId.key}}
    (缺少$)
  • 不要忽略警告 - 警告应被修复
  • 不要硬编码位置 - 除userGuide外,使用自动布局
  • 不要创建不可达节点 - 确保可从workflowStart到达
  • 不要生成过于复杂的工作流 - 超过20个节点的工作流应拆分

Troubleshooting

故障排除

FAQ

常见问题

Q1: Import to FastGPT reports "Invalid node type"
A: Check the
flowNodeType
field, ensure using supported types. Reference
references/node_types_reference.md
. Common errors:
  • chatNode
    is correct (not
    aiChat
    )
  • Number suffixes (like
    httpRequest468
    ) should be retained
Q2: References between nodes not working
A: Check reference format:
  • ✅ Correct:
    ["workflowStart", "userChatInput"]
    or
    {{$workflowStart.userChatInput$}}
  • ❌ Wrong:
    {$workflowStart.userChatInput$}
    (single brace, should be double)
Q3: Some nodes not executing at runtime
A: Use built-in validation to check Level 3, ensure all nodes reachable from workflowStart
Q4: Parallel nodes not executing in parallel
A: Ensure multiple nodes' targets are the same aggregation node, and these nodes have no dependencies
Q5: Loop workflow errors
A: Must use
flowNodeType: "loop"
node, configure
parentNodeId
and
childrenNodeIdList
Q1:导入FastGPT时提示“无效节点类型”
A:检查
flowNodeType
字段,确保使用支持的类型。参考
references/node_types_reference.md
。常见错误:
  • chatNode
    是正确的(不是
    aiChat
  • 应保留数字后缀(例如
    httpRequest468
Q2:节点间的引用不生效
A:检查引用格式:
  • ✅ 正确:
    ["workflowStart", "userChatInput"]
    {{$workflowStart.userChatInput$}}
  • ❌ 错误:
    {$workflowStart.userChatInput$}
    (单大括号,应为双大括号)
Q3:运行时部分节点未执行
A:使用内置验证检查第三层,确保所有节点可从workflowStart到达
Q4:并行节点未并行执行
A:确保多个节点的目标是同一个聚合节点,且这些节点之间无依赖关系
Q5:循环工作流出错
A:必须使用
flowNodeType: "loop"
节点,配置
parentNodeId
childrenNodeIdList

Debug Checklist

调试检查清单

markdown
undefined
markdown
undefined

Phase 1: JSON Format Check

阶段1:JSON格式检查

  • JSON is parseable
  • Contains nodes, edges, chatConfig
  • All strings use double quotes
  • No trailing commas
  • JSON可解析
  • 包含nodes, edges, chatConfig
  • 所有字符串使用双引号
  • 无 trailing commas

Phase 2: Node Check

阶段2:节点检查

  • workflowStart node exists
  • At least one output node exists
  • All flowNodeType valid
  • All nodeId unique
  • All position contains x, y
  • workflowStart节点存在
  • 至少有一个输出节点存在
  • 所有flowNodeType有效
  • 所有nodeId唯一
  • 所有position包含x, y

Phase 3: Connection Check

阶段3:连接检查

  • All edges' source and target exist
  • All handle format correct
  • No duplicate edges, no self-loops
  • 所有edges的source和target存在
  • 所有handle格式正确
  • 无重复边,无自环

Phase 4: Reference Check

阶段4:引用检查

  • All array references' nodes and keys exist
  • All template references' nodes and keys exist
  • Reference types match
  • 所有数组引用的节点和键存在
  • 所有模板引用的节点和键存在
  • 引用类型匹配

Phase 5: Logic Check

阶段5:逻辑检查

  • All nodes reachable from workflowStart
  • No illegal cycles
  • No dead-end nodes
  • All required inputs have values
  • 所有节点可从workflowStart到达
  • 无非法循环
  • 无死节点
  • 所有必填输入都有值

Phase 6: Runtime Test

阶段6:运行时测试

  • Import to FastGPT without errors
  • Configure necessary parameters
  • Run test cases
  • Check output meets expectations

---
  • 导入FastGPT无错误
  • 配置必要的参数
  • 运行测试用例
  • 检查输出符合预期

---

Quick Reference

快速参考

Built-in Template Files

内置模板文件

  • templates/文档翻译助手.json
    - Simple workflow, document processing
  • templates/销售陪练大师.json
    - Medium complexity, conversational AI
  • templates/简历筛选助手_飞书.json
    - Complex workflow, data + external integration
  • templates/AI金融日报.json
    - Scheduled trigger, multi-agent
  • templates/文档翻译助手.json
    - 简单工作流,文档处理
  • templates/销售陪练大师.json
    - 中等复杂度,对话式AI
  • templates/简历筛选助手_飞书.json
    - 复杂工作流,数据+外部集成
  • templates/AI金融日报.json
    - 定时触发,多智能体

Detailed Documentation

详细文档

  • references/node_types_reference.md
    - Complete reference of 40+ node types
  • references/validation_rules.md
    - Detailed three-layer validation rules
  • references/template_matching.md
    - Template matching algorithm
  • references/json_structure_spec.md
    - Complete FastGPT JSON structure specification
  • references/node_types_reference.md
    - 40+种节点类型的完整参考
  • references/validation_rules.md
    - 三层验证规则的详细说明
  • references/template_matching.md
    - 模板匹配算法
  • references/json_structure_spec.md
    - 完整的FastGPT JSON结构规范

Example Documents

示例文档

  • examples/example1_simple_qa.md
    - Complete example: Simple Q&A workflow
  • examples/example2_travel_planning.md
    - Complete example: Travel planning workflow
  • examples/example3_incremental_modify.md
    - Complete example: Incremental modification
  • examples/example1_simple_qa.md
    - 完整示例:简单问答工作流
  • examples/example2_travel_planning.md
    - 完整示例:旅行规划工作流
  • examples/example3_incremental_modify.md
    - 完整示例:增量修改

Common Commands

常用命令

bash
undefined
bash
undefined

Validate workflow JSON

验证工作流JSON

node scripts/validate_workflow.js path/to/workflow.json
node scripts/validate_workflow.js path/to/workflow.json

Copy template

复制模板

cp templates/文档翻译助手.json my_workflow.json
cp templates/文档翻译助手.json my_workflow.json

View template list

查看模板列表

ls -lh templates/

---

**Version**: 1.0
**Last Updated**: 2025-01-02
**Compatibility**: FastGPT v4.8+
ls -lh templates/

---

**版本**:1.0
**最后更新**:2025-01-02
**兼容性**:FastGPT v4.8+