Why can the variable aggregator only output the result of the first variable? #5619

Closed
opened 2026-02-21 18:11:54 -05:00 by yindo · 20 comments
Owner

Originally created by @seasoncool on GitHub (Sep 14, 2024).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.8.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

I am using a parallel approach to have each role analyze the product I provided.

I want to combine the analysis results from the large models and output them together uniformly.

Why is it that each time I can only see the output of the first variable at the endpoint?

Variable Aggregator

✔️ Expected Behavior

I hope the analysis results from each large model can be organized together through a variable aggregator.

Actual Behavior

only one output

Originally created by @seasoncool on GitHub (Sep 14, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.8.0 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce I am using a parallel approach to have each role analyze the product I provided. I want to combine the analysis results from the large models and output them together uniformly. Why is it that each time I can only see the output of the first variable at the endpoint? ![Variable Aggregator](https://github.com/user-attachments/assets/038a1e87-329a-4d74-9669-c2507ab7ea7d) ### ✔️ Expected Behavior I hope the analysis results from each large model can be organized together through a variable aggregator. ### ❌ Actual Behavior only one output
yindo added the 🐞 bug label 2026-02-21 18:11:54 -05:00
yindo closed this issue 2026-02-21 18:11:54 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 14, 2024):

Hey there, @seasoncool! 👋 I'm Dosu, a bot here to help you with bug fixes, questions, and becoming a contributor.

The variable aggregator can only output the result of the first variable when combining analysis results from large models because it is designed to prioritize the first matching variable it encounters. If advanced settings or group settings are not enabled, the aggregator will stop after finding the first variable that matches the selector criteria. This behavior ensures that the aggregator outputs a single, consistent result, but it also means that only the first variable is considered in the absence of more complex configuration [1][2].

To achieve the desired behavior of combining analysis results from multiple large models, you can enable and configure the advanced settings for the variable aggregator node. This includes enabling grouping and defining groups with specific output types and variables. Here is an example configuration:

from typing import Literal, Optional
from pydantic import BaseModel

class AdvancedSettings(BaseModel):
    group_enabled: bool

    class Group(BaseModel):
        output_type: Literal["string", "number", "object", "array[string]", "array[number]", "array[object]"]
        variables: list[list[str]]
        group_name: str

    groups: list[Group]

# Example configuration
advanced_settings = AdvancedSettings(
    group_enabled=True,
    groups=[
        AdvancedSettings.Group(
            output_type="string",
            variables=[["var1", "var2"], ["var3"]],
            group_name="group1"
        ),
        AdvancedSettings.Group(
            output_type="number",
            variables=[["var4"]],
            group_name="group2"
        )
    ]
)

This configuration enables grouping and defines two groups with specified output types, variables, and group names. When grouping is enabled, the variable aggregator will map each group to an object type with children representing the output type of each group [3][4][2].

For more detailed examples and use cases, you can refer to the documentation on variable aggregation, which demonstrates how to aggregate multiple variables successfully [1][5][6].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Sep 14, 2024): <!-- Greeting --> Hey there, @seasoncool! 👋 I'm [Dosu](https://dosu.dev), a bot here to help you with bug fixes, questions, and becoming a contributor. <!-- Answer --> The variable aggregator can only output the result of the first variable when combining analysis results from large models because it is designed to prioritize the first matching variable it encounters. If advanced settings or group settings are not enabled, the aggregator will stop after finding the first variable that matches the selector criteria. This behavior ensures that the aggregator outputs a single, consistent result, but it also means that only the first variable is considered in the absence of more complex configuration <sup>[[1]](https://github.com/langgenius/dify-docs/blob/main/en/guides/workflow/node/variable-assigner.md)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/api/core/workflow/nodes/variable_aggregator/variable_aggregator_node.py)</sup>. To achieve the desired behavior of combining analysis results from multiple large models, you can enable and configure the advanced settings for the variable aggregator node. This includes enabling grouping and defining groups with specific output types and variables. Here is an example configuration: ```python from typing import Literal, Optional from pydantic import BaseModel class AdvancedSettings(BaseModel): group_enabled: bool class Group(BaseModel): output_type: Literal["string", "number", "object", "array[string]", "array[number]", "array[object]"] variables: list[list[str]] group_name: str groups: list[Group] # Example configuration advanced_settings = AdvancedSettings( group_enabled=True, groups=[ AdvancedSettings.Group( output_type="string", variables=[["var1", "var2"], ["var3"]], group_name="group1" ), AdvancedSettings.Group( output_type="number", variables=[["var4"]], group_name="group2" ) ] ) ``` This configuration enables grouping and defines two groups with specified output types, variables, and group names. When grouping is enabled, the variable aggregator will map each group to an object type with children representing the output type of each group <sup>[[3]](https://github.com/langgenius/dify/blob/main/api/core/workflow/nodes/variable_aggregator/entities.py)</sup><sup>[[4]](https://github.com/langgenius/dify/blob/main/web/app/components/workflow/nodes/_base/components/variable/utils.ts)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/api/core/workflow/nodes/variable_aggregator/variable_aggregator_node.py)</sup>. For more detailed examples and use cases, you can refer to the documentation on variable aggregation, which demonstrates how to aggregate multiple variables successfully <sup>[[1]](https://github.com/langgenius/dify-docs/blob/main/en/guides/workflow/node/variable-assigner.md)</sup><sup>[[5]](https://github.com/langgenius/dify-docs/blob/main/zh_CN/guides/workflow/node/variable-assigner.md)</sup><sup>[[6]](https://github.com/langgenius/dify-docs/blob/main/jp/guides/workflow/node/variable-assigner.md)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@crazywoola commented on GitHub (Sep 14, 2024):

Please upgrade to v0.8.3. We have fixed several issues related to the output.

@crazywoola commented on GitHub (Sep 14, 2024): Please upgrade to v0.8.3. We have fixed several issues related to the output.
Author
Owner

@seasoncool commented on GitHub (Sep 14, 2024):

@crazywoola

Thank you for your quick response. I see that currently only version 0.8.2 is available for download.
Do you mean we need to wait until version 0.8.3 is released?

@seasoncool commented on GitHub (Sep 14, 2024): @crazywoola Thank you for your quick response. I see that currently only version 0.8.2 is available for download. Do you mean we need to wait until version 0.8.3 is released?
Author
Owner

@crazywoola commented on GitHub (Sep 14, 2024):

Actually I reproduced this problem, I need to take a deep look at the code.

@crazywoola commented on GitHub (Sep 14, 2024): Actually I reproduced this problem, I need to take a deep look at the code.
Author
Owner

@crazywoola commented on GitHub (Sep 14, 2024):

A workaround might be

QQ_1726299330026
QQ_1726299369598

@crazywoola commented on GitHub (Sep 14, 2024): A workaround might be ![QQ_1726299330026](https://github.com/user-attachments/assets/3e51cb7f-6e98-4996-9210-dbaa6a80f385) ![QQ_1726299369598](https://github.com/user-attachments/assets/8b3ecdb9-7fbb-4bf2-8500-228ebc308053)
Author
Owner

@AAEE86 commented on GitHub (Sep 14, 2024):

@crazywoola
根据测试是变量聚合器的问题,他只会输出变量赋值中的第一个LLM内容

@AAEE86 commented on GitHub (Sep 14, 2024): > @crazywoola 根据测试是变量聚合器的问题,他只会输出变量赋值中的第一个LLM内容
Author
Owner

@AAEE86 commented on GitHub (Sep 14, 2024):

聚合分组并没有作用

@AAEE86 commented on GitHub (Sep 14, 2024): 聚合分组并没有作用
Author
Owner

@crazywoola commented on GitHub (Sep 14, 2024):

将多路分支的变量聚合为一个变量,以实现下游节点统一配置。

变量聚合节点(原变量赋值节点)是工作流程中的一个关键节点,它负责整合不同分支的输出结果,确保无论哪个分支被执行,其结果都能通过一个统一的变量来引用和访问。这在多分支的情况下非常有用,可将不同分支下相同作用的变量映射为一个输出变量,避免下游节点重复定义。

I checked with our team, this seems to be an expected behavior, actually it equals to 'choose 1 from n'. @seasoncool @AAEE86

@crazywoola commented on GitHub (Sep 14, 2024): > 将多路分支的变量聚合为一个变量,以实现下游节点统一配置。 > 变量聚合节点(原变量赋值节点)是工作流程中的一个关键节点,它负责整合不同分支的输出结果,确保无论哪个分支被执行,其结果都能通过一个统一的变量来引用和访问。这在多分支的情况下非常有用,可将不同分支下相同作用的变量映射为一个输出变量,避免下游节点重复定义。 I checked with our team, this seems to be an expected behavior, actually it equals to 'choose 1 from n'. @seasoncool @AAEE86
Author
Owner

@AAEE86 commented on GitHub (Sep 14, 2024):

明白了。 要想都输出。必须将每个LLM都放到一个分组并输出。

@AAEE86 commented on GitHub (Sep 14, 2024): 明白了。 要想都输出。必须将每个LLM都放到一个分组并输出。
Author
Owner

@crazywoola commented on GitHub (Sep 14, 2024):

明白了。 要想都输出。必须将每个LLM都放到一个分组并输出。

No need to do this, actually an answer node is enough.

变量聚合 I think we will change the name in the near future.

@crazywoola commented on GitHub (Sep 14, 2024): > 明白了。 要想都输出。必须将每个LLM都放到一个分组并输出。 No need to do this, actually an answer node is enough. `变量聚合` I think we will change the name in the near future.
Author
Owner

@AAEE86 commented on GitHub (Sep 14, 2024):

Ok. thanks.@crazywoola

@AAEE86 commented on GitHub (Sep 14, 2024): Ok. thanks.@crazywoola
Author
Owner

@seasoncool commented on GitHub (Sep 14, 2024):

将多路分支的变量聚合为一个变量,以实现下游节点统一配置。

变量聚合节点(原变量赋值节点)是工作流程中的一个关键节点,它负责整合不同分支的输出结果,确保无论哪个分支被执行,其结果都能通过一个统一的变量来引用和访问。这在多分支的情况下非常有用,可将不同分支下相同作用的变量映射为一个输出变量,避免下游节点重复定义。

I checked with our team, this seems to be an expected behavior, actually it equals to 'choose 1 from n'. @seasoncool @AAEE86

感谢,还是不太明白怎么使用?还有别的办法能将多个的大模型推理的结果合并一起吗?

@seasoncool commented on GitHub (Sep 14, 2024): > > 将多路分支的变量聚合为一个变量,以实现下游节点统一配置。 > > > 变量聚合节点(原变量赋值节点)是工作流程中的一个关键节点,它负责整合不同分支的输出结果,确保无论哪个分支被执行,其结果都能通过一个统一的变量来引用和访问。这在多分支的情况下非常有用,可将不同分支下相同作用的变量映射为一个输出变量,避免下游节点重复定义。 > > I checked with our team, this seems to be an expected behavior, actually it equals to 'choose 1 from n'. @seasoncool @AAEE86 感谢,还是不太明白怎么使用?还有别的办法能将多个的大模型推理的结果合并一起吗?
Author
Owner

@crazywoola commented on GitHub (Sep 14, 2024):

QQ_1726321654580

@crazywoola commented on GitHub (Sep 14, 2024): ![QQ_1726321654580](https://github.com/user-attachments/assets/06b937c9-52cd-401a-8622-147ceebc7d80)
Author
Owner

@AAEE86 commented on GitHub (Sep 14, 2024):

In fact, you can create three variables directly in END to output the result of the LLM.

@AAEE86 commented on GitHub (Sep 14, 2024): In fact, you can create three variables directly in END to output the result of the LLM.
Author
Owner

@seasoncool commented on GitHub (Sep 14, 2024):

In fact, you can create three variables directly in END to output the result of the LLM.

I tried the method you suggested, outputting three variables at the endpoint, but in the end, only the value of the first one is displayed.

@seasoncool commented on GitHub (Sep 14, 2024): > In fact, you can create three variables directly in END to output the result of the LLM. I tried the method you suggested, outputting three variables at the endpoint, but in the end, only the value of the first one is displayed.
Author
Owner

@seasoncool commented on GitHub (Sep 14, 2024):

QQ_1726321654580

Could you show how the code inside the template conversion is written? I would like to learn from it. Thank you.

@seasoncool commented on GitHub (Sep 14, 2024): > ![QQ_1726321654580](https://private-user-images.githubusercontent.com/100913391/367518865-06b937c9-52cd-401a-8622-147ceebc7d80.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjYzMjQwMzcsIm5iZiI6MTcyNjMyMzczNywicGF0aCI6Ii8xMDA5MTMzOTEvMzY3NTE4ODY1LTA2YjkzN2M5LTUyY2QtNDAxYS04NjIyLTE0N2NlZWJjN2Q4MC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwOTE0JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDkxNFQxNDIyMTdaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1kMzc4ODhiNjQyMTBmN2NkYWRkOTZhNzc0ZmE4N2YzYWFkZjY1YTM3ZWRiYjczZTI3MzhkMDAyOTUwMjkxMzgzJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.aEVnFxgkMLy7jwmzdXb1n8M4JSPVr_x3txVEzsRFueg) Could you show how the code inside the template conversion is written? I would like to learn from it. Thank you.
Author
Owner

@AAEE86 commented on GitHub (Sep 14, 2024):

屏幕截图 2024-09-14 225134
Are you sure your settings are correct?

@AAEE86 commented on GitHub (Sep 14, 2024): ![屏幕截图 2024-09-14 225134](https://github.com/user-attachments/assets/41bebe48-92e8-4cf4-9270-100cdc9109a0) Are you sure your settings are correct?
Author
Owner

@AAEE86 commented on GitHub (Sep 14, 2024):

QQ_1726321654580

Could you show how the code inside the template conversion is written? I would like to learn from it. Thank you.

屏幕截图 2024-09-14 225501

A simple example. You can view the official documentation to understand Jinja template syntax.

@AAEE86 commented on GitHub (Sep 14, 2024): > > ![QQ_1726321654580](https://private-user-images.githubusercontent.com/100913391/367518865-06b937c9-52cd-401a-8622-147ceebc7d80.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjYzMjQwMzcsIm5iZiI6MTcyNjMyMzczNywicGF0aCI6Ii8xMDA5MTMzOTEvMzY3NTE4ODY1LTA2YjkzN2M5LTUyY2QtNDAxYS04NjIyLTE0N2NlZWJjN2Q4MC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwOTE0JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDkxNFQxNDIyMTdaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1kMzc4ODhiNjQyMTBmN2NkYWRkOTZhNzc0ZmE4N2YzYWFkZjY1YTM3ZWRiYjczZTI3MzhkMDAyOTUwMjkxMzgzJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.aEVnFxgkMLy7jwmzdXb1n8M4JSPVr_x3txVEzsRFueg) > > Could you show how the code inside the template conversion is written? I would like to learn from it. Thank you. ![屏幕截图 2024-09-14 225501](https://github.com/user-attachments/assets/ad4439f5-3b6d-4a25-b2ca-73f200e6a987) A simple example. You can view the official documentation to understand Jinja template syntax.
Author
Owner

@seasoncool commented on GitHub (Sep 14, 2024):

thanks a lot ... I will learn from that.

@seasoncool commented on GitHub (Sep 14, 2024): thanks a lot ... I will learn from that.
Author
Owner

@seasoncool commented on GitHub (Sep 14, 2024):

屏幕截图 2024-09-14 225134 Are you sure your settings are correct?

You're right. All three of my output variables are named "text," so the last one is likely overwriting the previous results, which makes it look like there's only one result. Thank you for the image that helped me understand.

@seasoncool commented on GitHub (Sep 14, 2024): > ![屏幕截图 2024-09-14 225134](https://private-user-images.githubusercontent.com/33052466/367522950-41bebe48-92e8-4cf4-9270-100cdc9109a0.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjYzMjU4OTIsIm5iZiI6MTcyNjMyNTU5MiwicGF0aCI6Ii8zMzA1MjQ2Ni8zNjc1MjI5NTAtNDFiZWJlNDgtOTJlOC00Y2Y0LTkyNzAtMTAwY2RjOTEwOWEwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTE0VDE0NTMxMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTUxMDk2YjJkOTdkM2UwYTI2MjE1ZTFiZDJkYzZkYzA0OTQ3MDY1MTI4YWVlMDlhMDZkNGM5MDc3ZTk4OTFlYjMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.ftMow9YJZbFatlpHHwaWmvX_IrP61lyYC3LzAz1Lj3E) Are you sure your settings are correct? You're right. All three of my output variables are named "text," so the last one is likely overwriting the previous results, which makes it look like there's only one result. Thank you for the image that helped me understand.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5619