Skip to content

fix(openai): preserve system role in DeepSeek formatter#2189

Open
dailingtao wants to merge 1 commit into
agentscope-ai:mainfrom
dailingtao:codex/fix-deepseek-system-role
Open

fix(openai): preserve system role in DeepSeek formatter#2189
dailingtao wants to merge 1 commit into
agentscope-ai:mainfrom
dailingtao:codex/fix-deepseek-system-role

Conversation

@dailingtao

Copy link
Copy Markdown

AgentScope-Java Version

2.0.1-SNAPSHOT

Description

Fixes #2168.

DeepSeek's current API supports the system role, but DeepSeekFormatter was rewriting system messages to user. This changed the intended message semantics and made the formatter inconsistent with the API behavior.

This PR:

  • preserves the original system role in DeepSeekFormatter and DeepSeekMultiAgentFormatter output;
  • keeps the existing DeepSeek-specific handling for removing message names and stale reasoning_content;
  • updates formatter tests and Javadocs to describe and verify the corrected behavior.

How to test

mvn -pl agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-openai -am \
  -Dtest=DeepSeekFormatterTest,DeepSeekMultiAgentFormatterTest \
  -Dsurefire.failIfNoSpecifiedTests=false test

mvn -pl agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-openai -am verify
mvn spotless:apply
mvn spotless:check

Checklist

Please check the following items before code is ready to be reviewed.

  • 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

@dailingtao dailingtao requested a review from a team July 14, 2026 05:07
@CLAassistant

CLAassistant commented Jul 14, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@oss-maintainer oss-maintainer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Summary

Correct fix — DeepSeek API actually supports system role, so the previous conversion to user was unnecessary and incorrect.

Findings

  • [Info] DeepSeekFormatter.java:167-180 — Removed the isSystem check and simplified the builder to preserve original role. Clean.
  • [Info] Tests updated to verify system role preservation. Good regression coverage.

Verdict

Minimal, correct fix. LGTM.


Automated review by github-manager

@jujn jujn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/core/model Model providers and formatters labels Jul 14, 2026

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖 AI Review

Clean, focused bug fix for issue #2168. The DeepSeekFormatter was incorrectly rewriting system role messages to user despite DeepSeek's API supporting the system role natively. This PR correctly preserves the original system role while keeping DeepSeek-specific handling (name removal, reasoning_content cleanup) intact.

The fix is minimal and well-scoped: removes the isSystem variable, simplifies early-return conditions, and uses msg.getRole() directly. Both DeepSeekFormatter and DeepSeekMultiAgentFormatter (which delegates via applyDeepSeekFixes()) are fixed with a single change point. Tests and Javadoc are updated consistently.

This is a behavioral change — users who adapted to the old (incorrect) behavior may notice the difference. Consider noting it in the CHANGELOG.

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖 AI Review

Clean, focused bug fix for issue #2168. The DeepSeekFormatter was incorrectly rewriting system role messages to user despite DeepSeek's API supporting the system role natively. This PR correctly preserves the original system role while keeping DeepSeek-specific handling (name removal, reasoning_content cleanup) intact.

The fix is minimal and well-scoped: removes the isSystem variable, simplifies early-return conditions, and uses msg.getRole() directly. Both DeepSeekFormatter and DeepSeekMultiAgentFormatter (which delegates via applyDeepSeekFixes()) are fixed with a single change point. Tests and Javadoc are updated consistently.

This is a behavioral change — users who adapted to the old (incorrect) behavior may notice the difference. Consider noting it in the CHANGELOG.

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

Labels

area/core/model Model providers and formatters bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Why does DeepSeekFormatter convert system messages to user messages?

5 participants