SuperAPI AI Directory

dify-dsl-generator

General & other

View repository

Updated 10-15 23:43

About this skill

Dify DSL Workflow Generator

A professional Dify workflow DSL/YML file automatic generation tool, based on deep learning from 86+ real workflow cases, capable of automatically generating complete workflow configuration files that comply with the Dify specification according to user business requirements.

Core Features

  • ✅ Complete DSL Generation: Automatically generate complete YML files containing app, dependencies, workflow
  • ✅ Multi-node Support: Supports all node types such as start, llm, answer, code, http-request, if-else, tool, etc.
  • ✅ Intelligent Connections: Automatically generate edges connection relationships between nodes
  • ✅ Parameter Configuration: Intelligently recommend model parameters and prompt configurations
  • ✅ Plugin Integration: Automatically identify and configure required Dify plugin dependencies
  • ✅ Standardized Format: Strictly follow the Dify 0.3.0 version DSL specification

Usage

Basic Usage

生成一个 Dify 工作流用于 [业务需求描述]

Detailed Usage

帮我生成一个 Dify 工作流 DSL 文件:
- 功能: [工作流要实现的功能]
- 输入: [用户输入的内容]
- 处理步骤: [详细的处理逻辑]
- 输出: [期望的输出结果]
- 使用插件: [需要的插件,可选]

Dify DSL File Structure

Based on learning from 86+ real workflow cases, Dify DSL YML files follow the structure below:

1. App Configuration

app:
  description: '工作流描述'
  icon: 🤖
  icon_background: '#FFEAD5'
  mode: advanced-chat  # 或 workflow, agent-chat
  name: 工作流名称
  use_icon_as_answer_icon: false

Mode Description:

  • advanced-chat: Advanced chat mode (chatflow)
  • workflow: Workflow mode
  • agent-chat: AI Agent mode

2. Dependencies

dependencies:
- current_identifier: null
  type: marketplace
  value:
    marketplace_plugin_unique_identifier: 插件唯一标识符

Common Plugins:

  • langgenius/openai_api_compatible: OpenAI-compatible interface
  • bowenliang123/md_exporter: Markdown exporter
  • Other marketplace plugins are added as needed

3. Workflow

kind: app
version: 0.3.0
workflow:
  conversation_variables: []
  environment_variables: []
  features:
    file_upload:
      enabled: false
    speech_to_text:
      enabled: false
    text_to_speech:
      enabled: false
  graph:
    edges: []
    nodes: []

Node Type Details

Start Node

- data:
    desc: ''
    title: 开始
    type: start
    variables:
    - label: 用户输入
      max_length: 1000
      options: []
      required: true
      type: paragraph  # 或 text-input, select, file
      variable: query
  id: 'start'
  position:
    x: 100
    y: 300
  type: custom
  width: 244
  height: 90

Variable Types:

  • paragraph: Paragraph text (multi-line)
  • text-input: Single-line text
  • select: Dropdown selection
  • file: File upload
  • number: Number

LLM Large Language Model Node

- data:
    context:
      enabled: false
      variable_selector: []
    model:
      completion_params:
        temperature: 0.7
        max_tokens: 2000
      mode: chat
      name: gpt-4
      provider: openai
    prompt_template:
    - id: 唯一ID
      role: system
      text: 系统提示词
    - id: 唯一ID
      role: user
      text: 用户提示词 {{#变量引用#}}
    title: LLM节点
    type: llm
    vision:
      enabled: false
  id: '节点ID'
  position:
    x: 400
    y: 300
  type: custom

Common model providers:

  • openai: OpenAI
  • langgenius/openai_api_compatible/openai_api_compatible: Compatible interface
  • anthropic: Claude
  • alibaba: Tongyi Qianwen

Variable reference format:

  • {{#节点ID.输出变量#}}: Reference the output of other nodes
  • {{#sys.query#}}: Reference system variables (user input)
  • {{#节点ID.text#}}: Reference LLM output text

Code Execution Node

- data:
    code: |
      import json

      def main(arg1: str, arg2: str) -> dict:
          # 处理逻辑
          result = process(arg1, arg2)
          return {
              "result": result,
              "status": "success"
          }
    code_language: python3
    outputs:
      result:
        type: string
      status:
        type: string
    title: 代码执行
    type: code
    variables:
    - value_selector:
      - '前置节点ID'
      - 输出变量
      variable: arg1
  id: '节点ID'
  position:
    x: 700
    y: 300
  type: custom

Code Language:

  • python3: Python 3
  • javascript: JavaScript (supported in some versions)

Output Types:

  • string: String
  • number: Number
  • object: Object
  • array[string]: String array
  • array[number]: Number array
  • array[object]: Object array

HTTP Request Node

- data:
    authorization:
      config: null
      type: no-auth
    body:
      data: '{"key": "{{#变量#}}"}'
      type: json
    headers: ''
    method: post
    timeout:
      max_connect_timeout: 0
      max_read_timeout: 0
      max_write_timeout: 0
    title: HTTP请求
    type: http-request
    url: https://api.example.com/endpoint
  id: '节点ID'
  position:
    x: 1000
    y: 300
  type: custom

HTTP Methods:

  • get: GET request
  • post: POST request
  • put: PUT request
  • patch: PATCH request
  • delete: DELETE request

Authentication Types:

  • no-auth: No authentication
  • api-key: API Key
  • bearer: Bearer Token

If-Else Conditional Judgement Node

- data:
    cases:
    - case_id: case1
      conditions:
      - comparison_operator: contains
        id: 条件ID
        value: 期望值
        variable_selector:
        - '节点ID'
        - 变量名
      id: case1
      logical_operator: and
    logical_operator: or
    title: 条件判断
    type: if-else
  id: '节点ID'
  position:
    x: 1300
    y: 300
  type: custom

Comparison Operators:

  • contains: Contains
  • not contains: Does not contain
  • is: Equals
  • is not: Not equals
  • empty: Is empty
  • not empty: Is not empty

Logical Operators:

  • and: And
  • or: Or

Tool Node

- data:
    provider_id: 工具提供者ID
    provider_name: 工具提供者名称
    provider_type: builtin  # 或 api
    title: 工具调用
    tool_configurations: {}
    tool_label: 工具标签
    tool_name: 工具名称
    tool_parameters:
      参数名:
        type: mixed
        value: '{{#变量#}}'
    type: tool
  id: '节点ID'
  position:
    x: 1600
    y: 300
  type: custom

Tool Types:

  • builtin: Built-in tools (such as search, weather, etc.)
  • api: API tools
  • plugin: Plugin tools

Answer direct reply node

- data:
    answer: |
      {{#LLM节点ID.text#}}

      {{#代码节点ID.result#}}
    title: 直接回复
    type: answer
    variables: []
  id: answer
  position:
    x: 1900
    y: 300
  type: custom

Variable Aggregator node

- data:
    advanced_settings: null
    desc: ''
    groups:
    - group_name: 分组1
      output_type: string
      variables:
      - value_selector:
        - '节点ID'
        - 变量名
        variable: 输出变量名
    title: 变量聚合器
    type: variable-aggregator
  id: '节点ID'
  position:
    x: 2200
    y: 300
  type: custom

Parameter Extractor node

- data:
    instruction: 提取指令说明
    is_array: false
    model:
      completion_params: {}
      mode: chat
      name: gpt-4
      provider: openai
    parameters:
    - description: 参数描述
      name: 参数名
      required: true
      type: string
    query:
    - role: user
      text: '{{#输入变量#}}'
    reasoning_mode: prompt
    title: 参数提取
    type: parameter-extractor
  id: '节点ID'
  position:
    x: 2500
    y: 300
  type: custom

Edges connection relationships

edges:
- data:
    isInIteration: false
    isInLoop: false
    sourceType: start
    targetType: llm
  id: 源节点ID-source-目标节点ID-target
  source: '源节点ID'
  sourceHandle: source
  target: '目标节点ID'
  targetHandle: target
  type: custom
  zIndex: 0

Connection rules:

  1. Each node has at most one incoming edge (except the start node)
  2. A node can have multiple outgoing edges (branch nodes such as if-else)
  3. Must ultimately connect to the answer node or other output nodes
  4. sourceType and targetType must match the actual node type

Position coordinate layout

Recommended layout:

  • Starting X: 100
  • Node spacing X: 300-400
  • Y coordinate: keep on the same horizontal line (300) or adjust appropriately based on branches
  • Y coordinate of child nodes of branch nodes: ±150

Example layout:

Start(100,300) → LLM(400,300) → Code(700,300) → Answer(1000,300)

Branch layout:

                    → Branch1(1100,150)
If-Else(800,300) →
                    → Branch2(1100,450)

Workflow generation steps

1. Requirements analysis

  • Understand the user's business requirements
  • Determine the workflow type (chatflow/workflow/agent)
  • Identify the required node types
  • Plan the processing flow

2. Node design

  • Design the input variables of the start node
  • Plan the prompts for LLM nodes
  • Determine the code execution logic
  • Configure HTTP request parameters
  • Design the output format

3. Flow connection

  • Establish the logical relationships between nodes
  • Configure variable passing
  • Handle conditional branches
  • Ensure the flow is closed-loop

4. DSL generation

  • Generate YAML format that conforms to the specification
  • Configure unique node IDs
  • Set reasonable coordinate positions
  • Add necessary dependency plugins

5. Verification check

  • Check the correctness of the YAML format
  • Verify the completeness of variable references
  • Confirm the reasonableness of node connections
  • Check the completeness of required fields

Learning from real cases

Summary of learning based on 86+ real workflow cases:

Case 1: Image OCR recognition workflow

Requirements: Upload image → OCR recognition → Extract text

Node flow:

  1. Start(file input) →
  2. LLM(vision enabled, OCR) →
  3. Answer(display result)

Key configuration:

  • Start node: type: file, allowed_file_types: [image]
  • LLM node: vision.enabled: true, vision.configs.variable_selector points to the file variable
  • System prompt: "Only output the text information recognized in the image"

Case 2: Text-to-HTML generation workflow

Requirements: Text description → Generate HTML code → Save as file

Node flow:

  1. Start(text input) →
  2. LLM(generate HTML) →
  3. Parameter Extractor(extract HTML code) →
  4. Tool(md_exporter, save file) →
  5. Answer(return file URL)

Key configuration:

  • LLM prompt: "Generate an HTML program, output only the HTML code"
  • Parameter Extractor: Extract the HTML code block
  • Tool: Use the md_exporter plugin to save the file

Case 3: Data query visualization workflow

Requirements: User question → SQL query → Chart display

Node flow:

  1. Start(query input) →
  2. LLM(generate SQL) →
  3. HTTP Request(database API) →
  4. Code(format data) →
  5. LLM(generate chart HTML) →
  6. Answer(display chart)

Key configuration:

  • LLM1: Text-to-SQL generation
  • HTTP: Call the database query API
  • Code: Format JSON data into chart data format
  • LLM2: Generate ECharts/Chart.js HTML

Case 4: AI Agent workflow

Requirements: Complex task → Agent autonomous planning → Call tools → Return results

Node flow:

  1. Start(task input) →
  2. LLM(reasoning, with tools) →
  3. Multiple Tool nodes(parallel) →
  4. Variable Aggregator(collect results) →
  5. LLM(summarize) →
  6. Answer(final response)

Key configuration:

  • mode: agent-chat
  • LLM configuration: Enable multiple tools
  • Tool parallel execution: Multiple edges from LLM pointing to different Tools
  • Variable Aggregator: Aggregate the outputs of multiple Tools

Common prompt templates

Text-to-SQL

你是一个专业的 SQL 专家。根据用户的自然语言问题生成准确的 SQL 查询语句。

数据库schema:
{{#数据库结构#}}

用户问题: {{#sys.query#}}

要求:
1. 只输出 SQL 语句,不要有其他说明
2. 确保 SQL 语法正确
3. 使用合适的 JOIN 和 WHERE 条件

Data extraction

从以下文本中提取指定信息:

文本内容:
{{#输入文本#}}

提取要求:
- 提取所有日期
- 提取所有人名
- 提取所有金额

以 JSON 格式输出:
{
  "dates": [],
  "names": [],
  "amounts": []
}

HTML generation

根据用户需求生成完整的 HTML 页面。

需求: {{#用户需求#}}

要求:
1. 生成完整的 HTML 文档
2. 包含必要的 CSS 样式
3. 添加必要的 JavaScript 交互
4. 确保代码格式规范
5. 只输出 HTML 代码,不要 markdown 代码块标记

Notes

Rules that must be followed

  1. Unique ID generation: Each node must have a unique ID (recommended to use a timestamp: 1747991890414)
  2. Variable reference format: Must use {{#节点ID.变量名#}} format
  3. Node type matching: The sourceType and targetType in edges must match the actual node types
  4. Required fields: Required fields in YAML cannot be omitted
  5. YAML format: Strictly follow YAML indentation rules (2 spaces)

Avoid common errors

  1. ❌ Variable reference error: {{节点ID.变量}} ✅ Correct format: {{#节点ID.变量#}}

  2. ❌ Missing node connection: Node is isolated and unconnected ✅ Ensure all nodes have connection relationships in edges

  3. ❌ Duplicate ID: Multiple nodes use the same ID ✅ Each node uses a unique ID

  4. ❌ Position overlap: Multiple nodes have the same coordinates ✅ Plan node positions reasonably to avoid overlap

  5. ❌ Missing dependency: A plugin is used but not declared in dependencies ✅ When using a plugin, the corresponding dependency must be added

Output format

The generated DSL file must be a complete YAML format that can be directly imported into Dify:

app:
  # App 配置

dependencies:
  # 依赖列表

kind: app
version: 0.3.0

workflow:
  conversation_variables: []
  environment_variables: []
  features:
    # 功能配置
  graph:
    edges:
      # 连接关系
    nodes:
      # 节点定义

Quality standards

Qualified standards (mandatory)

  • ✅ YAML format is correct and can be parsed
  • ✅ Includes complete app, dependencies, and workflow configuration
  • ✅ Includes at least start and answer nodes
  • ✅ Nodes have correct connection relationships
  • ✅ Variable reference format is correct
  • ✅ All required fields are complete

Excellent standards (recommended)

  • 🌟 Prompt design is professional and meets business needs
  • 🌟 Node layout is visually appealing and logic is clear
  • 🌟 Includes appropriate error handling (if-else judgment)
  • 🌟 Uses suitable plugins to enhance functionality
  • 🌟 Code execution nodes are highly robust
  • 🌟 Variable naming is semantic

Trigger keywords

Keywords that automatically trigger the dify-dsl-generator skill:

  • "Generate Dify workflow"
  • "Create Dify DSL"
  • "Dify YML file"
  • "Workflow configuration file"

Update log

v1.0.0 (2025-11-22)

  • ✅ Initial version
  • ✅ Based on learning from 86+ real cases
  • ✅ Supports all major node types
  • ✅ Complete DSL generation capability
  • ✅ Intelligent node connection
  • ✅ Standardized format output

Technical support

Reference resources: