Skip to content

Feature/newnew workflow loop node - #14863

Merged
laipz8200 merged 25 commits into
langgenius:mainfrom
AICT-Team:feature/newnew-workflow-loop-node
Mar 5, 2025
Merged

Feature/newnew workflow loop node#14863
laipz8200 merged 25 commits into
langgenius:mainfrom
AICT-Team:feature/newnew-workflow-loop-node

Conversation

@Woo0ood

@Woo0ood Woo0ood commented Mar 4, 2025

Copy link
Copy Markdown
Contributor

Summary

This PR introduces the Loop Node, a feature designed to enable workflows or processes to execute repeatedly until specific conditions or formats are met. The node allows users to define internal variables and outputs that determine whether to exit the loop. A maximum iteration limit can also be set to prevent infinite loops.

The addition of the Loop Node addresses the community’s and team’s demand for executing repeated HTTP interface calls or invoking LLMs multiple times in a workflow. The implementation aligns with the feedback and requirements outlined in Issue #12354.

Resolves #12354
Close #12289

Screenshots

Loop node

Some Details

This section was automatically generated by GitHub Copilot actions.

This pull request introduces a new feature for handling single loop runs in workflows and advanced chat applications. The changes include adding new API endpoints, updating the app generator and runner classes, and modifying the task pipeline to support loop events.

New API endpoints:

  • Added Advanc /edChatDraftRunLoopNodeApi and WorkflowDraftRunLoopNodeApi classes to handle POST requests for running draft workflow loop nodes. (api/controllers/console/app/workflow.py)

App generator updates:

  • Introduced single_loop_generate method in AdvancedChatAppGenerator and WorkflowAppGenerator to generate app responses for single loop runs. (api/core/app/apps/advanced_chat/app_generator.py) [1] (api/core/app/apps/workflow/app_generator.py) [2]

App runner updates:

  • Updated AdvancedChatAppRunner and WorkflowAppRunner to handle single loop runs by adding logic to fetch and process graph and variable pool for loops. (api/core/app/apps/advanced_chat/app_runner.py) [1] (api/core/app/apps/workflow/app_runner.py) [2]

Task pipeline modifications:

  • Added new events (QueueLoopStartEvent, QueueLoopNextEvent, QueueLoopCompletedEvent, QueueNodeInLoopFailedEvent) and updated the _process_stream_response method to handle these events. (api/core/app/apps/advanced_chat/generate_task_pipeline.py) [1] [2] [3] (api/core/app/apps/workflow/generate_task_pipeline.py) [4] [5] [6]

These changes collectively enhance the system's ability to manage and execute single loop runs within workflows and advanced chat applications.

Author

This PR is submitted by the AICT Team from NetDragon Websoft Inc., aiming to contribute to the open-source community. The AICT Team is dedicated to promoting the continuous optimization and functional expansion of Dify and other open-source products. By introducing practical features such as the Loop Node, the team hopes to help community users build more efficient and intelligent workflow solutions, working together to create a stronger Dify ecosystem.

Checklist

Important

Please review the checklist below before submitting your pull request.

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

@dosubot dosubot Bot added size:XXL This PR changes 1000+ lines, ignoring generated files. 🌊 feat:workflow Workflow related stuff. 📚 documentation Improvements or additions to documentation labels Mar 4, 2025
@crazywoola
crazywoola requested review from laipz8200 and zxhlyh March 4, 2025 07:07
@Woo0ood
Woo0ood force-pushed the feature/newnew-workflow-loop-node branch from b443478 to 305e051 Compare March 4, 2025 07:20
@crazywoola

Copy link
Copy Markdown
Member
2025-03-04.22.37.46.mov

Suggestion:

  • See attached video, The LOOP TERMINATION CONDITION should be clickable and pointer-style=cursor, it can remove current condition.
  • MAXIMN LOOP COUNT is set to 100 at this moment, it's good to make it as an environment variable in .env.example

Export the formatNode functions for both Iteration and Loop, and merge
them into a unified method called formatIterationAndLoopNode. This
method will handle the NodeTracing List uniformly, addressing the
timing issues in the tracing logs caused by the previous categorized
handling.
@Woo0ood
Woo0ood force-pushed the feature/newnew-workflow-loop-node branch from 04aaacf to 6588bfd Compare March 4, 2025 16:51
@Woo0ood

Woo0ood commented Mar 4, 2025

Copy link
Copy Markdown
Contributor Author
  • The LOOP TERMINATION CONDITION should be clickable and pointer-style=cursor

I have addressed the first suggestion. The second suggestion will be handled later (maybe🌚..).


append: all done

@crazywoola crazywoola left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Mar 5, 2025
@crazywoola

Copy link
Copy Markdown
Member
  • Loop Node Description
    • The loop termination condition must be the return variable within the loop body.
    • LOOP_NODE_MAX_COUNT=100 can be modified via an environment variable. However, note that Run failed: Max steps 500 reached. requires modifying the WORKFLOW_MAX_EXECUTION_STEPS environment variable.

@laipz8200
laipz8200 merged commit 2c17bb2 into langgenius:main Mar 5, 2025
@Woo0ood
Woo0ood deleted the feature/newnew-workflow-loop-node branch March 5, 2025 17:35
jackzhuo pushed a commit to jackzhuo/dify that referenced this pull request Mar 14, 2025
Co-authored-by: arkunzz <4873204@qq.com>
parambharat pushed a commit to parambharat/dify that referenced this pull request Mar 31, 2025
Co-authored-by: arkunzz <4873204@qq.com>
jsincorporated pushed a commit to jsincorporated/asaAi that referenced this pull request Jul 8, 2025
Co-authored-by: arkunzz <4873204@qq.com>
clubanderson added a commit to kubestellar/console-kb that referenced this pull request Apr 3, 2026
The original fix PR langgenius/dify#13058 was closed without merging.
Replace with langgenius/dify#14863 which was merged and implements
the loop node feature.

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
clubanderson added a commit to kubestellar/console-kb that referenced this pull request Apr 3, 2026
…cution and (#1886)

* 🌱 Add dify: Enhancing Workflow with Loop and Sleep Nodes for Repeated mission

* 🌱 Add dify: Enhancing Workflow with Loop and Sleep Nodes for Repeated mission

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix: replace closed dify PR #13058 with merged PR #14863

The original fix PR langgenius/dify#13058 was closed without merging.
Replace with langgenius/dify#14863 which was merged and implements
the loop node feature.

Signed-off-by: Andrew Anderson <andy@clubanderson.com>

---------

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Signed-off-by: Andrew Anderson <andy@clubanderson.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Ssazurov pushed a commit to Ssazurov/dify that referenced this pull request Aug 8, 2026
Co-authored-by: arkunzz <4873204@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📚 documentation Improvements or additions to documentation 🌊 feat:workflow Workflow related stuff. lgtm This PR has been approved by a maintainer size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancing Workflow with Loop and Sleep Nodes for Repeated Execution and Interval Control Add WHILE loop or TRY block to workflow

4 participants