fix(formatter): ensure assistant messages with tool_calls always include content field#1283
Open
uuuyuqi wants to merge 2 commits intoagentscope-ai:mainfrom
Open
fix(formatter): ensure assistant messages with tool_calls always include content field#1283uuuyuqi wants to merge 2 commits intoagentscope-ai:mainfrom
uuuyuqi wants to merge 2 commits intoagentscope-ai:mainfrom
Conversation
…ude content field
When Qwen3 and similar models operate in thinking mode, assistant messages
may contain reasoning_content + tool_calls but null content. Due to
@JsonInclude(NON_NULL), the null content field was omitted from the JSON
request, causing strict OpenAI-compatible APIs (e.g. vLLM) to reject the
request with "Field required: input.messages.N.content".
Fix by explicitly setting content to empty string ("") when an assistant
message has tool_calls but no text content, in both OpenAIMessageConverter
and DashScopeMessageConverter.
Close agentscope-ai#1268
Change-Id: I2ac07a81e8681a049c253501ab93856b94836a8e
Co-developed-by: Cursor <noreply@cursor.com>
… and fix missed locations - Move content="" fallback to the top of convertAssistantMessage() so it applies to all assistant messages (not just those with tool_calls) - Fix the same null-content issue in DashScopeMultiAgentFormatter.formatAssistantToolCall() - Update DashScopeTextOnlyGroundTruthTest expected values accordingly Change-Id: Idd54f515a99fe046230bfab4c3c218bce264c255 Co-developed-by: Cursor <noreply@cursor.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When Qwen3 and similar models operate in thinking mode, assistant messages may contain
reasoning_content+tool_callsbutnullcontent. Due to@JsonInclude(NON_NULL)onOpenAIMessageandDashScopeMessage, thenullcontent field was entirely omitted from the JSON request body, causing strict OpenAI-compatible APIs (e.g. vLLM) to reject the request with:Root Cause
In both
OpenAIMessageConverterandDashScopeMessageConverter, when an assistant message hastool_callsbut noTextBlock, thecontentfield was left asnullon the DTO. Jackson's@JsonInclude(NON_NULL)then omitted the field entirely during serialization.Fix
Explicitly set
contentto an empty string""(instead of leaving itnull) when an assistant message hastool_callsbut no text content. This ensures thecontentfield is always present in the serialized JSON.Changed files:
OpenAIMessageConverter.convertAssistantMessage()— setcontent=""whenhasTextContentis false and tool calls existDashScopeMessageConverter.convertToSimpleContent()— replacenullcontent with""for assistant messages with tool callsClose #1268
Checklist
mvn spotless:applymvn test)Made with Cursor