[PR #21766] Expose LLM usage in workflows #29743

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

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

State: closed
Merged: Yes


Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

  • LLM node already had "usage" in its output, and translations were already in place to expose it in the output vars panel. This PR makes it usable by other nodes by adding it to the variable list selector.
  • The same change is applied for the other LLM based nodes: Question Classifier and Parameter Extractor.
  • Parameter Extractor is a special case node, because its output variables can be overridden by the node extraction configuration. For this reason only in that case, the output var is __usage instead of usage (as it was already done for __is_success and __reason) to reduce the possibility that already existing nodes overrides it.
  • Parameter Extractor highlighted a possible issue with tracing tool (Langfuse, Langsmith, Opik) that will now prefer the internal, non-overridable usage property exposed in process_data

This PR will ultimately allow users that want to log the token usages while inside the workflow to get accurate usage values, instead of relying on external sources, plugins that may or may not calculate the correct usage, queries on the DB tables.

Resolves #18036

Screenshots

Before After
LLM Node already returned the info, without allowing other nodes to consume it Now Question classifier returns it too (it was in process data)
data_was_there image
variable_picker_before variable_picker_after
llm_before llm_after
question_classifier_before question_classifier_after
image image

https://github.com/user-attachments/assets/46026312-0d74-4c17-a7fc-8098d5e24021

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/21766 **State:** closed **Merged:** Yes --- > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 2. Ensure there is an associated issue and you have been assigned to it > 3. Use the correct syntax to link this PR: `Fixes #<issue number>`. ## Summary - LLM node already had "usage" in its output, and translations were already in place to expose it in the output vars panel. This PR makes it usable by other nodes by adding it to the variable list selector. - The same change is applied for the other LLM based nodes: Question Classifier and Parameter Extractor. - Parameter Extractor is a special case node, because its output variables can be overridden by the node extraction configuration. For this reason only in that case, the output var is `__usage` instead of `usage` (as it was already done for `__is_success` and `__reason`) to reduce the possibility that already existing nodes overrides it. - Parameter Extractor highlighted a possible issue with tracing tool (Langfuse, Langsmith, Opik) that will now prefer the internal, non-overridable `usage` property exposed in `process_data` This PR will ultimately allow users that want to log the token usages while inside the workflow to get accurate usage values, instead of relying on external sources, plugins that may or may not calculate the correct usage, queries on the DB tables. Resolves #18036 ## Screenshots | Before | After | |--------|-------| | LLM Node already returned the info, without allowing other nodes to consume it | Now Question classifier returns it too (it was in process data) | | ![data_was_there](https://github.com/user-attachments/assets/32f3848b-64ae-4d9e-9dab-9b221b99684e) | ![image](https://github.com/user-attachments/assets/6f68fba0-c119-4d9a-9425-9d633d9dca0f) | | ![variable_picker_before](https://github.com/user-attachments/assets/056c5f3b-3c6f-4f0f-9e72-a59d07f354de) | ![variable_picker_after](https://github.com/user-attachments/assets/d8eb756f-cd01-43ff-8c65-9e8b7ba6a32c) | | ![llm_before](https://github.com/user-attachments/assets/d04b0e89-c80b-4d88-8466-dd27f85c05d5) | ![llm_after](https://github.com/user-attachments/assets/efad7e1d-f490-43be-bfd0-00b18bd589cf) | | ![question_classifier_before](https://github.com/user-attachments/assets/afcb323d-3e55-4fea-9994-b60bbc121f95) | ![question_classifier_after](https://github.com/user-attachments/assets/03e3321f-2e19-47c4-99b2-5005c82040e1) | |![image](https://github.com/user-attachments/assets/043fff3a-bebe-4858-8478-b77d43bf7f1c) | ![image](https://github.com/user-attachments/assets/69a426a7-6f4f-4ccf-986c-029f3cde6cfa) | https://github.com/user-attachments/assets/46026312-0d74-4c17-a7fc-8098d5e24021 ## 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:09 -05:00
yindo closed this issue 2026-02-21 20:46:09 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#29743