Skip to content

fix(formatter): preserve reasoning_content from ThinkingBlock in DashScopeMessageConverter#1285

Open
uuuyuqi wants to merge 1 commit intoagentscope-ai:mainfrom
uuuyuqi:fix/dashscope-reasoning-content
Open

fix(formatter): preserve reasoning_content from ThinkingBlock in DashScopeMessageConverter#1285
uuuyuqi wants to merge 1 commit intoagentscope-ai:mainfrom
uuuyuqi:fix/dashscope-reasoning-content

Conversation

@uuuyuqi
Copy link
Copy Markdown
Contributor

@uuuyuqi uuuyuqi commented Apr 25, 2026

Description

When Qwen3 and similar models operate in thinking mode, assistant messages contain reasoning_content (chain-of-thought reasoning). AgentScope correctly parses this into ThinkingBlock internally via DashScopeResponseParser.

However, DashScopeMessageConverter did not preserve this reasoning_content when converting internal Msg objects back to DashScopeMessage DTOs for subsequent API calls (i.e., as conversation history). The reasoning context was silently dropped, causing the model to lose its thinking history in multi-turn conversations.

Root Cause

In DashScopeMessageConverter.convertToSimpleContent(), there was no logic to extract ThinkingBlock from the internal Msg and set it as reasoning_content on the outgoing DashScopeMessage.

Fix

For assistant messages, extract the first ThinkingBlock and set its content as reasoning_content on the DashScopeMessage.Builder:

ThinkingBlock thinkingBlock = msg.getFirstContentBlock(ThinkingBlock.class);
if (thinkingBlock != null) {
    String thinking = thinkingBlock.getThinking();
    if (thinking != null && !thinking.isEmpty()) {
        builder.reasoningContent(thinking);
    }
}

Changed files:

  • DashScopeMessageConverter.convertToSimpleContent() — extract and preserve reasoning_content from ThinkingBlock

Close #1284

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

Made with Cursor

…ScopeMessageConverter

When Qwen3 and similar models operate in thinking mode, assistant messages
contain reasoning_content (chain-of-thought reasoning) which is correctly
parsed into ThinkingBlock internally. However, DashScopeMessageConverter
did not write this back to the reasoning_content field when building
DashScopeMessage DTOs for subsequent API calls, causing the model to lose
its reasoning history in multi-turn conversations.

Fix by extracting ThinkingBlock from assistant messages and setting its
content as reasoning_content on the outgoing DashScopeMessage.

Close agentscope-ai#1284

Change-Id: If5c2749e048d46cbbdbed64d7b8a867a52c8d5ea
Co-developed-by: Cursor <noreply@cursor.com>
@uuuyuqi uuuyuqi requested a review from a team April 25, 2026 07:15
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 25, 2026

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...formatter/dashscope/DashScopeMessageConverter.java 80.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] DashScopeMessageConverter does not preserve reasoning_content from ThinkingBlock in assistant messages

1 participant