[PR #23313] feat: add reasoning format processing to LLMNode for <think> tag handling #30236

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

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

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

Fixes https://github.com/langgenius/dify/issues/21896
Related: https://github.com/langgenius/dify/pull/21897, https://github.com/langgenius/dify/issues/13419

This PR continues work from #21897

To maintain compatibility, the current feature was implemented solely by modifying the backend and frontend of the main Dify repository.

Once this PR is merged, I’ll proceed with the planned updates to dify-plugin-sdks and dify-official-plugins: emit reasoning_content directly and remove manual wrapping

Changes:

Reasoning Format Configuration: Added reasoning_format parameter with 'tagged' and 'separated' options

  • tagged mode: Keeps <think> tags in output text (legacy compatibility)
  • separated mode: Extracts reasoning content to reasoning_content field, removes tags from output

Backward Compatibility: Default behavior remains unchanged, ensuring existing workflows continue to work

Frontend - UI Configuration: Added reasoning format configuration panel to LLM node

  • Toggle switch to enable/disable reasoning tag separation
  • Internationalization support using auto-generated i18n keys
  • Maintains existing thinking panel display during streaming

Streaming Behavior:

  • During streaming: Both modes send full text with tags to frontend, ensuring real-time thinking panel display
  • After completion: separated mode provides clean text to downstream nodes while tagged mode keeps original format
  • Reasoning content: Available as separate field for workflow variables in both modes (empty string in tagged mode, extracted content in separated mode)

Note

This PR’s scope is only backend + frontend updates in the main Dify repo—no SDK/plugin changes yet, in order to preserve the existing streaming thinking-panel experience. After this lands:

  • I’ll update dify-plugin-sdks repo to emit reasoning_content in streaming deltas.
  • I’ll update each official plugin repo to remove manual <think> wrapping and rely on the new field.

By taking this phased approach, I aim to develop the feature without any side effects.

Screenshots

Before After (tagged - switch off) After (separated - switch on)
pr_before_0
pr_before_1
pr_dify_off_00
pr_dify_reasonig_content
pr_dify_on
pr_dify_reasonig_content

ps.
I noticed that I had unintentionally re-added the _fetch_model_schema method from my local branch.
It had already been removed by another contributor in the upstream refactor on July 31 (#23203), so I’ve removed it again in the last commit.
Apologies for the mix-up!

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/23313 **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 <!-- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. --> Fixes https://github.com/langgenius/dify/issues/21896 Related: https://github.com/langgenius/dify/pull/21897, https://github.com/langgenius/dify/issues/13419 This PR continues work from [#21897](https://github.com/langgenius/dify/pull/21897) To maintain compatibility, the current feature was implemented solely by modifying the backend and frontend of the main Dify repository. Once this PR is merged, I’ll proceed with the planned updates to dify-plugin-sdks and dify-official-plugins: emit reasoning_content directly and remove manual <think> wrapping Changes: **Reasoning Format Configuration**: Added `reasoning_format` parameter with `'tagged'` and `'separated'` options - `tagged` mode: Keeps `<think>` tags in output text (legacy compatibility) - `separated` mode: Extracts reasoning content to `reasoning_content` field, removes tags from output **Backward Compatibility**: Default behavior remains unchanged, ensuring existing workflows continue to work **Frontend - UI Configuration**: Added reasoning format configuration panel to LLM node - Toggle switch to enable/disable reasoning tag separation - Internationalization support using auto-generated i18n keys - Maintains existing thinking panel display during streaming **Streaming Behavior**: - **During streaming**: Both modes send full text with <think> tags to frontend, ensuring real-time thinking panel display - **After completion**: `separated` mode provides clean text to downstream nodes while `tagged` mode keeps original format - **Reasoning content**: Available as separate field for workflow variables in both modes (empty string in `tagged` mode, extracted content in `separated` mode) ### Note This PR’s scope is only backend + frontend updates in the main Dify repo—no SDK/plugin changes yet, in order to preserve the existing streaming thinking-panel experience. After this lands: - I’ll update **dify-plugin-sdks repo** to emit `reasoning_content` in streaming deltas. - I’ll update each **official plugin repo** to remove manual `<think>` wrapping and rely on the new field. By taking this phased approach, I aim to develop the feature without any side effects. ## Screenshots | Before | After (tagged - switch off) | After (separated - switch on) | |:---------------:|:------------------------:|:---------------------------:| |<img width="300" alt="pr_before_0" src="https://github.com/user-attachments/assets/13e00e0e-7b44-4c0e-a2bc-dccf905bc670" /><br/><img width="300" alt="pr_before_1" src="https://github.com/user-attachments/assets/65a360d3-ad23-4dcc-a034-aa7a0d44abda" />|<img width="300" alt="pr_dify_off_00" src="https://github.com/user-attachments/assets/3c27d869-1b2f-42fd-95cf-54a8770111fa" /><br/><img width="300" alt="pr_dify_reasonig_content" src="https://github.com/user-attachments/assets/7a65d3aa-30dc-4ea0-90d0-b143f1c0fae7" />| <img width="300" alt="pr_dify_on" src="https://github.com/user-attachments/assets/cbf0b7c5-ce67-4229-b715-a18ba69b359a" /> <br/><img width="300" alt="pr_dify_reasonig_content" src="https://github.com/user-attachments/assets/7a65d3aa-30dc-4ea0-90d0-b143f1c0fae7" /> | ps. I noticed that I had unintentionally re-added the `_fetch_model_schema` method from my local branch. It had already been removed by another contributor in the upstream refactor on July 31 ([#23203](https://github.com/langgenius/dify/pull/23203)), so I’ve removed it again in the last commit. Apologies for the mix-up! ## 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:47:06 -05:00
yindo closed this issue 2026-02-21 20:47:06 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#30236