Skip to content

fix: #36183 add auto-generate workflow/chatflow functionality#36836

Open
duongynhi000005-oss wants to merge 1 commit into
langgenius:mainfrom
duongynhi000005-oss:fix/36183-auto-generate-workflow
Open

fix: #36183 add auto-generate workflow/chatflow functionality#36836
duongynhi000005-oss wants to merge 1 commit into
langgenius:mainfrom
duongynhi000005-oss:fix/36183-auto-generate-workflow

Conversation

@duongynhi000005-oss
Copy link
Copy Markdown
Contributor

Fixes #36183

Summary

Adds the ability to automatically generate chatflows or workflows from a natural language description using an LLM.

Changes

  • Backend API endpoint: POST /workflow-generate that accepts a description and app mode, then uses an LLM to generate a complete workflow graph (nodes + edges)
  • LLM prompt: A detailed system prompt that instructs the LLM on available node types, graph structure, and layout rules
  • Frontend service: generateWorkflow() function to call the new endpoint
  • Tests: Unit tests covering success, markdown fence stripping, error handling, and invalid JSON cases

How it works

  1. User provides a natural language description of the desired workflow (e.g., "A chatbot that retrieves knowledge from a database and answers questions")
  2. The system sends this to the configured LLM with a structured prompt describing all available node types and their schemas
  3. The LLM returns a valid workflow graph JSON
  4. The frontend can use this graph to populate the workflow canvas

What was tested

  • Python syntax validation of all modified files
  • Unit tests for the generate_workflow method (success, markdown fences, invoke errors, invalid JSON, missing fields)

…rom natural language description

Adds a new API endpoint POST /workflow-generate that uses an LLM to
generate a complete workflow graph (nodes + edges) from a natural
language description provided by the user.

Changes:
- api/core/llm_generator/prompts.py: Add WORKFLOW_GENERATE_PROMPT_SYSTEM
  and WORKFLOW_GENERATE_PROMPT_USER templates
- api/core/llm_generator/entities.py: Add WorkflowGeneratePayload model
- api/core/llm_generator/llm_generator.py: Add generate_workflow() method
- api/controllers/console/app/generator.py: Add /workflow-generate endpoint
- web/service/debug.ts: Add generateWorkflow() frontend service call
- api/tests/unit_tests/core/llm_generator/test_llm_generator.py: Add tests
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label May 29, 2026
@github-actions github-actions Bot added the web This relates to changes on the web. label May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files. web This relates to changes on the web.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

I hope Dify can add the functionality of automatically generating chatflows or workflows

1 participant