Token usage incorrectly shown in Iteration node #4140

Closed
opened 2026-02-21 18:04:55 -05:00 by yindo · 1 comment
Owner

Originally created by @WeepsDanky on GitHub (Jun 17, 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).
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.10

Cloud or Self Hosted

Cloud

Steps to reproduce

image
In the sidebar preview and operation, if there is an LLM node within the Iteration Node, the tokens used will not be reflected in the Iteration Node.

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @WeepsDanky on GitHub (Jun 17, 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] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.6.10 ### Cloud or Self Hosted Cloud ### Steps to reproduce ![image](https://github.com/langgenius/dify/assets/50621638/3db09318-8f15-41fb-8bc0-fd3394b4e2b7) In the sidebar preview and operation, if there is an LLM node within the Iteration Node, the tokens used will not be reflected in the Iteration Node. ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 18:04:55 -05:00
yindo closed this issue 2026-02-21 18:04:55 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jun 17, 2024):

The issue with token usage not being reflected in the Iteration Node when there is an LLM node within it is due to the _invoke_llm method in the LLMNode class not updating the Iteration Node's token count. The token usage is calculated and returned by the _invoke_llm method, but there is no mechanism to propagate this usage back to the Iteration Node's token count [1].

To address this, you would need to implement a mechanism to update the Iteration Node's token count based on the token usage of its child nodes. This could involve modifying the _invoke_llm method to propagate the token usage back to the parent Iteration Node.

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Jun 17, 2024): <!-- Answer --> The issue with token usage not being reflected in the Iteration Node when there is an LLM node within it is due to the `_invoke_llm` method in the `LLMNode` class not updating the Iteration Node's token count. The token usage is calculated and returned by the `_invoke_llm` method, but there is no mechanism to propagate this usage back to the Iteration Node's token count <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/workflow/nodes/llm/llm_node.py)</sup>. To address this, you would need to implement a mechanism to update the Iteration Node's token count based on the token usage of its child nodes. This could involve modifying the `_invoke_llm` method to propagate the token usage back to the parent Iteration Node. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#4140