Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/new workflow loop node #13058

Open
wants to merge 15 commits into
base: plugins/beta
Choose a base branch
from

Conversation

Woo0ood
Copy link
Contributor

@Woo0ood Woo0ood commented Jan 26, 2025

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

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.

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.

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. labels Jan 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌊 feat:workflow Workflow related stuff. size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants