Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(formatter): ensure assistant messages with tool_calls always include content field#1283

Merged
LearningGp merged 2 commits into
agentscope-ai:mainfrom
uuuyuqi:fix/assistant-null-content
Apr 28, 2026
Merged

fix(formatter): ensure assistant messages with tool_calls always include content field#1283
LearningGp merged 2 commits into
agentscope-ai:mainfrom
uuuyuqi:fix/assistant-null-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 may contain reasoning_content + tool_calls but null content. Due to @JsonInclude(NON_NULL) on OpenAIMessage and DashScopeMessage, the null content field was entirely omitted from the JSON request body, causing strict OpenAI-compatible APIs (e.g. vLLM) to reject the request with:

Input error. Field required: input.messages.N.content

Root Cause

In both OpenAIMessageConverter and DashScopeMessageConverter, when an assistant message has tool_calls but no TextBlock, the content field was left as null on the DTO. Jackson's @JsonInclude(NON_NULL) then omitted the field entirely during serialization.

Fix

Explicitly set content to an empty string "" (instead of leaving it null) when an assistant message has tool_calls but no text content. This ensures the content field is always present in the serialized JSON.

Changed files:

  • OpenAIMessageConverter.convertAssistantMessage() — set content="" when hasTextContent is false and tool calls exist
  • DashScopeMessageConverter.convertToSimpleContent() — replace null content with "" for assistant messages with tool calls

Close #1268

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

…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 <[email protected]>
@uuuyuqi uuuyuqi requested a review from a team April 25, 2026 07:13
… 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 <[email protected]>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@jujn
Copy link
Copy Markdown
Contributor

jujn commented Apr 26, 2026

Hi, it seems that issue #1270 should also be associated.

@uuuyuqi
Copy link
Copy Markdown
Contributor Author

uuuyuqi commented Apr 27, 2026

Hi, it seems that issue #1270 should also be associated.

Ah, I haven't searched through the issues yet. Thanks for pointing this out!

Copy link
Copy Markdown
Collaborator

@LearningGp LearningGp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@LearningGp LearningGp merged commit bc027f0 into agentscope-ai:main Apr 28, 2026
5 checks passed
liangxingguang pushed a commit to liangxingguang/agentscope-java that referenced this pull request May 21, 2026
…ude content field (agentscope-ai#1283)

## Description

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)` on `OpenAIMessage` and
`DashScopeMessage`, the `null` content field was entirely omitted from
the JSON request body, causing strict OpenAI-compatible APIs (e.g. vLLM)
to reject the request with:

```
Input error. Field required: input.messages.N.content
```

### Root Cause

In both `OpenAIMessageConverter` and `DashScopeMessageConverter`, when
an assistant message has `tool_calls` but no `TextBlock`, the `content`
field was left as `null` on the DTO. Jackson's `@JsonInclude(NON_NULL)`
then omitted the field entirely during serialization.

### Fix

Explicitly set `content` to an empty string `""` (instead of leaving it
`null`) when an assistant message has `tool_calls` but no text content.
This ensures the `content` field is always present in the serialized
JSON.

**Changed files:**
- `OpenAIMessageConverter.convertAssistantMessage()` — set `content=""`
when `hasTextContent` is false and tool calls exist
- `DashScopeMessageConverter.convertToSimpleContent()` — replace `null`
content with `""` for assistant messages with tool calls

Close agentscope-ai#1268

## Checklist

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

Made with [Cursor](https://cursor.com)
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]:OpenAIMessageConverter produces assistant messages with null content when using vLLM + Qwen3 thinking mode

3 participants