[PR #228] feat: add reasoning_content field to LLMResultChunkDelta #239

Open
opened 2026-02-15 21:16:23 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langgenius/dify-plugin-sdks/pull/228
Author: @ultramancode
Created: 10/27/2025
Status: 🔄 Open

Base: mainHead: feat/add-reasoning-content-field


📝 Commits (1)

  • 2148efe feat: add reasoning_content field to LLMResultChunkDelta

📊 Changes

1 file changed (+1 additions, -0 deletions)

View changed files

📝 python/dify_plugin/entities/model/llm.py (+1 -0)

📄 Description

Summary

Add optional reasoning_content field to LLMResultChunkDelta for structured streaming of LLM reasoning/thinking processes.

Relates to #227 (issue)
Follow-up to langgenius/dify#23313

Changes

class LLMResultChunkDelta(BaseModel):
    index: int
    message: AssistantPromptMessage
    reasoning_content: str | None = None  # ← NEW
    usage: LLMUsage | None = None
    finish_reason: str | None = None

Why

Currently, plugins merge reasoning into message.content with <think> tags, requiring Main to parse them back out. This adds:

  • A dedicated field for reasoning content
  • Enables cleaner separation between reasoning and final response
  • Eliminates fragile tag-based parsing

Compatibility

  • Backward-compatible: Optional field (default None), no breaking changes for existing plugins.

Next Steps

This is Phase 1(SDK) of a multi-repo rollout:

  • Phase 2 (Plugins): Add defensive pop("_dify_supports_reasoning_content", False) in all LLM plugins to prevent vendor API errors when Main sends capability flags

  • Phase 3 (Main): Read reasoning_content from plugins and use delta.reasoning_content directly if present (with fallback to _split_reasoning()), then send capability flag via model_parameters for plugin optimization.

  • Phase 4 (Plugins): Provider-by-provider opt-in to emit reasoning_content deltas

See #227 for full plan.

  • Add optional reasoning_content field to support direct streaming of LLM reasoning/thinking content, separate from the main message content.

Pull Request Checklist

Thank you for your contribution! Before submitting your PR, please make sure you have completed the following checks:

Compatibility Check

  • I have checked whether this change affects the backward compatibility of the plugin declared in README.md
  • I have checked whether this change affects the forward compatibility of the plugin declared in README.md
  • If this change introduces a breaking change, I have discussed it with the project maintainer and specified the release version in the README.md
  • I have described the compatibility impact and the corresponding version number in the PR description
  • I have checked whether the plugin version is updated in the README.md

Available Checks

  • Code has passed local tests
  • Relevant documentation has been updated (if necessary)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langgenius/dify-plugin-sdks/pull/228 **Author:** [@ultramancode](https://github.com/ultramancode) **Created:** 10/27/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/add-reasoning-content-field` --- ### 📝 Commits (1) - [`2148efe`](https://github.com/langgenius/dify-plugin-sdks/commit/2148efe65f38abcd441a91c54a7ed3ce263f4a6a) feat: add reasoning_content field to LLMResultChunkDelta ### 📊 Changes **1 file changed** (+1 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `python/dify_plugin/entities/model/llm.py` (+1 -0) </details> ### 📄 Description ## Summary Add optional `reasoning_content` field to `LLMResultChunkDelta` for structured streaming of LLM reasoning/thinking processes. **Relates to** #227 (issue) **Follow-up to** langgenius/dify#23313 ## Changes ```python class LLMResultChunkDelta(BaseModel): index: int message: AssistantPromptMessage reasoning_content: str | None = None # ← NEW usage: LLMUsage | None = None finish_reason: str | None = None ``` ## Why Currently, plugins merge reasoning into `message.content` with `<think>` tags, requiring Main to parse them back out. This adds: - A dedicated field for reasoning content - Enables cleaner separation between reasoning and final response - Eliminates fragile tag-based parsing ## Compatibility - [x] **Backward-compatible**: Optional field (default `None`), no breaking changes for existing plugins. ## Next Steps This is **Phase 1(SDK)** of a multi-repo rollout: - Phase 2 (Plugins): Add defensive `pop("_dify_supports_reasoning_content", False)` in all LLM plugins to prevent vendor API errors when Main sends capability flags - Phase 3 (Main): Read `reasoning_content` from plugins and use `delta.reasoning_content` directly if present (with fallback to `_split_reasoning()`), then send capability flag via `model_parameters` for plugin optimization. - Phase 4 (Plugins): Provider-by-provider opt-in to emit `reasoning_content` deltas See #227 for full plan. - Add optional reasoning_content field to support direct streaming of LLM reasoning/thinking content, separate from the main message content. # Pull Request Checklist Thank you for your contribution! Before submitting your PR, please make sure you have completed the following checks: ## Compatibility Check - [x] I have checked whether this change affects the **backward compatibility** of the plugin declared in `README.md` - [x] I have checked whether this change affects the **forward compatibility** of the plugin declared in `README.md` - [x] If this change introduces a breaking change, I have discussed it with the project maintainer and specified the release version in the `README.md` - [x] I have described the compatibility impact and the corresponding version number in the PR description - [x] I have checked whether the plugin version is updated in the `README.md` ## Available Checks - [x] Code has passed local tests - [x] Relevant documentation has been updated (if necessary) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-15 21:16:23 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-plugin-sdks#239