Skip to content

Fix dashscope structured output#1946

Open
Mozhimomo wants to merge 2 commits into
agentscope-ai:mainfrom
Mozhimomo:fix-dashscope-structured-output
Open

Fix dashscope structured output#1946
Mozhimomo wants to merge 2 commits into
agentscope-ai:mainfrom
Mozhimomo:fix-dashscope-structured-output

Conversation

@Mozhimomo

Copy link
Copy Markdown

AgentScope-Java Version

2.0.0-SNAPSHOT

Description

This PR fixes DashScope structured output for calls such as ReActAgent.call(msgs, MyClass.class, ctx).

Previously, DashScopeChatModel advertised native structured-output support, so ReActAgent selected the native response_format path. However, the DashScope formatter did not map GenerateOptions.responseFormat into DashScopeParameters.responseFormat, so the actual DashScope request body did not include response_format. As a result, DashScope could return natural-language text instead of JSON, wrapNativeStructuredResult(...) failed to parse it, and Msg.hasStructuredData() remained false.

Changes made:

  • Set DashScopeChatModel.supportsNativeStructuredOutput() to false, so DashScope structured-output calls use the fallback generate_response tool path.
  • Added GenerateOptions.responseFormat mapping in DashScopeToolsHelper.applyOptions(...), so explicit DashScope response_format options are no longer dropped.
  • Added regression tests for response format mapping and DashScope structured-output routing.
  • Added a developer note documenting the root cause, fix, and verification steps.

How to test:

  • mvn -pl agentscope-core "-Dtest=DashScopeToolsHelperComprehensiveTest,DashScopeChatModelTest" test
  • mvn -pl agentscope-core 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

@Mozhimomo Mozhimomo requested a review from a team June 27, 2026 08:41
@CLAassistant

CLAassistant commented Jun 27, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codecov

codecov Bot commented Jun 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Mozhimomo Mozhimomo force-pushed the fix-dashscope-structured-output branch from 0cf9f78 to 88303bf Compare June 27, 2026 08:56
@itxaiohanglover

Copy link
Copy Markdown
Contributor

Good fix! Setting supportsNativeStructuredOutput to false for DashScope and forwarding ResponseFormat through the tools helper ensures structured output works correctly. The test coverage for the response format forwarding is solid.

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.

3 participants