[PR #14863] Feature/newnew workflow loop node #28232

Closed
opened 2026-02-21 20:43:03 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/14863

State: closed
Merged: Yes


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
**Original Pull Request:** https://github.com/langgenius/dify/pull/14863 **State:** closed **Merged:** Yes --- # 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](https://github.com/user-attachments/assets/a0516979-77ae-4074-8dc5-02f1444dcb8f) # 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]](diffhunk://#diff-8f181029dd884c26b36c57b7bf624363b2d848df15d71fffc08204fc4444f6e8R228-R284) (`api/core/app/apps/workflow/app_generator.py`) [[2]](diffhunk://#diff-e7d487acc5669b1517bb51b5176ad7840e060c538a7a328b813c7398373de790R253-R308) 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]](diffhunk://#diff-d8d71a322c10f256e8d6fe4666047395af9d48306cb89488b3386d9c70c1aef4R82-R88) (`api/core/app/apps/workflow/app_runner.py`) [[2]](diffhunk://#diff-d3b9896787465e317f2b1770f717288f4e39e4d95cf99aaea491b48f869795c7R84-R90) 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]](diffhunk://#diff-0407079ac76b3e5d5c414d9037f2ab5b30d2de5b183bc5d3acc438e99af87a43R26-R33) [[2]](diffhunk://#diff-0407079ac76b3e5d5c414d9037f2ab5b30d2de5b183bc5d3acc438e99af87a43L375-R379) [[3]](diffhunk://#diff-0407079ac76b3e5d5c414d9037f2ab5b30d2de5b183bc5d3acc438e99af87a43R479-R526) (`api/core/app/apps/workflow/generate_task_pipeline.py`) [[4]](diffhunk://#diff-30af34d9961f08e9c8563566c855c27b89bb9dfa9d347b8a4ef4f30c66d67ccdR21-R27) [[5]](diffhunk://#diff-30af34d9961f08e9c8563566c855c27b89bb9dfa9d347b8a4ef4f30c66d67ccdL326-R330) [[6]](diffhunk://#diff-30af34d9961f08e9c8563566c855c27b89bb9dfa9d347b8a4ef4f30c66d67ccdR436-R486) 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](https://github.com/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. - [x] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:43:03 -05:00
yindo closed this issue 2026-02-21 20:43:03 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#28232