[PR #22200] Allow Variable Aggregator to aggregate all #29866

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

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

State: closed
Merged: No


feat(workflow): Allow Variable Aggregator to aggregate all inputs

Problem

Currently, the variable-aggregator node in the workflow operates on a "first-come, first-served" basis.
When it receives inputs from multiple upstream branches, it only processes the first non-empty variable it
encounters and then immediately stops. This behavior causes all subsequent inputs from other branches to
be ignored.

This limitation restricts scenarios where it is necessary to merge results from multiple sources, such as
combining outputs from several Knowledge Retrieval nodes, HTTP requests, or other tools.

Solution

To address this, this pull request introduces a new configuration option for the variable-aggregator node:
an aggregate_all switch.

  • When aggregate_all is disabled (default behavior): The node maintains its original logic, capturing
    only the first valid input it receives.
  • When aggregate_all is enabled: The node iterates through all connected input branches, collects every
    valid variable, and aggregates them into a single list as its final output.

Implementation Details

  1. Backend (API):

    • In api/core/workflow/nodes/variable_aggregator/variable_aggregator_node.py:
      • Added the aggregate_all: bool field to the VariableAggregatorNodeData model.
      • Modified the _run method: when aggregate_all is true, the break statement is removed, and the
        logic is updated to collect all incoming variables into a list for output.
  2. Frontend (Web):

    • Since the variable-aggregator node reuses the frontend components of the variable-assigner, the
      changes were made in the web/app/components/workflow/nodes/variable-assigner/ directory.
    • panel.tsx: Added a new "Aggregate All" Switch UI control to the node's configuration panel.
    • types.ts: Updated the VariableAssignerNodeType definition to include the optional aggregate_all:
      boolean property.
    • use-config.ts: Implemented the handleAggregateAllChange function to manage the state of the new
      switch.
    • web/i18n/: Added corresponding labels and tooltips for the new switch in the zh-Hans and en-US
      workflow.ts translation files.

How to Test

  1. Create a new workflow.
  2. Add two or more Knowledge Retrieval nodes and configure them with different Knowledge Bases.
  3. Add a Variable Aggregator node and connect the outputs of the Knowledge Retrieval nodes to it.
  4. Connect an End node after the aggregator to inspect the final output.
  5. Test Default Behavior: Run the workflow. Check the output at the End node. It should contain the
    retrieval results from only one of the Knowledge Bases.
  6. Test New Feature:
    • Click the Variable Aggregator node to open its configuration panel.
    • Find and enable the new "Aggregate All" switch.
    • Run the workflow again.
    • Check the output at the End node. It should now be an array containing the retrieval results from all
      connected Knowledge Bases.

Screenshots

| After
image

Checklist

  • 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/22200 **State:** closed **Merged:** No --- feat(workflow): Allow Variable Aggregator to aggregate all inputs Problem Currently, the variable-aggregator node in the workflow operates on a "first-come, first-served" basis. When it receives inputs from multiple upstream branches, it only processes the first non-empty variable it encounters and then immediately stops. This behavior causes all subsequent inputs from other branches to be ignored. This limitation restricts scenarios where it is necessary to merge results from multiple sources, such as combining outputs from several Knowledge Retrieval nodes, HTTP requests, or other tools. Solution To address this, this pull request introduces a new configuration option for the variable-aggregator node: an aggregate_all switch. - When `aggregate_all` is disabled (default behavior): The node maintains its original logic, capturing only the first valid input it receives. - When `aggregate_all` is enabled: The node iterates through all connected input branches, collects every valid variable, and aggregates them into a single list as its final output. Implementation Details 1. Backend (API): - In api/core/workflow/nodes/variable_aggregator/variable_aggregator_node.py: - Added the aggregate_all: bool field to the VariableAggregatorNodeData model. - Modified the _run method: when aggregate_all is true, the break statement is removed, and the logic is updated to collect all incoming variables into a list for output. 2. Frontend (Web): - Since the variable-aggregator node reuses the frontend components of the variable-assigner, the changes were made in the web/app/components/workflow/nodes/variable-assigner/ directory. - `panel.tsx`: Added a new "Aggregate All" Switch UI control to the node's configuration panel. - `types.ts`: Updated the VariableAssignerNodeType definition to include the optional aggregate_all: boolean property. - `use-config.ts`: Implemented the handleAggregateAllChange function to manage the state of the new switch. - `web/i18n/`: Added corresponding labels and tooltips for the new switch in the zh-Hans and en-US workflow.ts translation files. How to Test 1. Create a new workflow. 2. Add two or more Knowledge Retrieval nodes and configure them with different Knowledge Bases. 3. Add a Variable Aggregator node and connect the outputs of the Knowledge Retrieval nodes to it. 4. Connect an End node after the aggregator to inspect the final output. 5. Test Default Behavior: Run the workflow. Check the output at the End node. It should contain the retrieval results from only one of the Knowledge Bases. 6. Test New Feature: - Click the Variable Aggregator node to open its configuration panel. - Find and enable the new "Aggregate All" switch. - Run the workflow again. - Check the output at the End node. It should now be an array containing the retrieval results from all connected Knowledge Bases. ## Screenshots | After <img width="1920" height="919" alt="image" src="https://github.com/user-attachments/assets/2f4d707d-3a36-48af-87b5-ec1ae631f582" /> ## Checklist - [ ] 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:46:23 -05:00
yindo closed this issue 2026-02-21 20:46:24 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#29866