[Badcase] Agent with Qwen3 will unexpectedly add a <think> wrapper #39

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

Originally created by @miracoco on GitHub (May 21, 2025).

Environment

  • Dify: 1.4.0
  • Qwen3
  • Plugins:

Model Configuration:

  • Enable structured output
  • Enable streaming function calling

Description

When I developing a agent workflow, I found that the agent will output a nested thinking content. I had starting to figure out causation.

I download the agent plugin and logged the LLM generated content

Image

Image

In the response, there is double <think><think>.

Then, I downloaded the dify-official-plugins repo and dump the original response from LLM. The LLM's output is includes only 1 <think> tag.

>>>>>>>>>>>>>>>>>>
data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"role":"assistant","content":""},"logprobs":null,"finish_reason":null}]}
data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"reasoning_content":"","tool_calls":[]}}]}
data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"reasoning_content":"","tool_calls":[]}}]}
data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"reasoning_content":"<","tool_calls":[]}}]}
data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"reasoning_content":"th","tool_calls":[]}}]}
data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"reasoning_content":"in","tool_calls":[]}}]}
data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"reasoning_content":"k","tool_calls":[]}}]}
data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"reasoning_content":">\n","tool_calls":[]}}]}
data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"reasoning_content":"好","tool_calls":[]}}]}
data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"reasoning_content":"的","tool_calls":[]}}]}
data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"reasoning_content":",","tool_calls":[]}}]}
data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"reasoning_content":"用户","tool_calls":[]}}]}
data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"reasoning_content":"输","tool_calls":[]}}]}
data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"reasoning_content":"入了","tool_calls":[]}}]}

// below is ignored for this issue

Finally, I notice the call _wrap_thinking_by_reasoning_content

Image

It will add an additional <think> within the content, even the LLM was also provided a <think>.

What I did

Comment the think manipulation procedure

Image

After that, the redundant <think> was got rid.

Expectation

I think _wrap_thinking_by_reasoning_content is helpful for most models with adding a clear <think>, but Qwen3 is a exception. So, I think there should have some check to decide whether enable the auto think completion.

Originally created by @miracoco on GitHub (May 21, 2025). ## Environment - Dify: 1.4.0 - Qwen3 - Plugins: - OpenAI-API-compatible - [MCP Agent](https://marketplace.dify.ai/plugins/junjiem/mcp_see_agent) **Model Configuration:** - Enable `structured output` - Enable `streaming function calling` ## Description When I developing a agent workflow, I found that the agent will output a nested thinking content. I had starting to figure out causation. I download the agent plugin and logged the LLM generated content ![Image](https://github.com/user-attachments/assets/11ddf288-25f6-4a69-9ed1-8888aebb2a50) ![Image](https://github.com/user-attachments/assets/361d9b32-aeeb-45ab-bd4f-891153b86550) In the response, there is double `<think><think>`. Then, I downloaded the `dify-official-plugins` repo and dump the original response from LLM. The LLM's output is includes only 1 `<think>` tag. ``` >>>>>>>>>>>>>>>>>> data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"role":"assistant","content":""},"logprobs":null,"finish_reason":null}]} data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"reasoning_content":"","tool_calls":[]}}]} data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"reasoning_content":"","tool_calls":[]}}]} data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"reasoning_content":"<","tool_calls":[]}}]} data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"reasoning_content":"th","tool_calls":[]}}]} data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"reasoning_content":"in","tool_calls":[]}}]} data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"reasoning_content":"k","tool_calls":[]}}]} data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"reasoning_content":">\n","tool_calls":[]}}]} data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"reasoning_content":"好","tool_calls":[]}}]} data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"reasoning_content":"的","tool_calls":[]}}]} data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"reasoning_content":",","tool_calls":[]}}]} data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"reasoning_content":"用户","tool_calls":[]}}]} data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"reasoning_content":"输","tool_calls":[]}}]} data: {"id":"chatcmpl-710dbc359e904cccb0a3638535b3bf34","object":"chat.completion.chunk","created":1747806451,"model":"Qwen/Qwen3-32B-AWQ","choices":[{"index":0,"delta":{"reasoning_content":"入了","tool_calls":[]}}]} // below is ignored for this issue ``` Finally, I notice the call `_wrap_thinking_by_reasoning_content` ![Image](https://github.com/user-attachments/assets/d8aacf5d-bbdd-40f6-9e5c-e4ca8e678b42) It will add an additional `<think>` within the content, even the LLM was also provided a `<think>`. ## What I did Comment the think manipulation procedure ![Image](https://github.com/user-attachments/assets/12a705f8-952a-4219-9d60-a30d848ca935) After that, the redundant `<think>` was got rid. ## Expectation I think `_wrap_thinking_by_reasoning_content` is helpful for most models with adding a clear `<think>`, but Qwen3 is a exception. So, I think there should have some check to decide whether enable the auto think completion.
yindo added the bug label 2026-02-15 21:15:24 -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#39