fix(model): disable native structured output for DashScope (#1852)#1959
Open
zhangliyuangit wants to merge 1 commit into
Open
fix(model): disable native structured output for DashScope (#1852)#1959zhangliyuangit wants to merge 1 commit into
zhangliyuangit wants to merge 1 commit into
Conversation
…e-ai#1852) DashScope's native text-generation protocol (/api/v1/services/aigc/text-generation/generation) only accepts response_format {"type":"json_object"} and does not support {"type":"json_schema"}. The native structured-output path therefore never applied the schema, the model returned natural-language text, parsing failed, and Msg.hasStructuredData() was always false. supportsNativeStructuredOutput() now returns false, routing structured-output calls to the tool-based fallback path (Qwen function-calling), which returns reliable schema-conforming results. supportsNativeStructuredOutputWithTools() stays consistent since it falls back to this method. Added Javadoc explaining why the native path is unsupported on the DashScope native protocol, and a regression test asserting both flags are false. Fixes agentscope-ai#1852 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes structured-output routing for DashScopeChatModel by disabling the native structured-output path (which relies on response_format: json_schema), ensuring ReActAgent uses the tool-based fallback path instead.
Changes:
- Updated
DashScopeChatModel.supportsNativeStructuredOutput()to always returnfalse, with added Javadoc explaining the DashScope protocol limitation. - Added a regression test asserting native structured output (with and without tools) is reported as unsupported.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-dashscope/src/main/java/io/agentscope/extensions/model/dashscope/DashScopeChatModel.java |
Disables native structured output and documents the DashScope response_format limitation. |
agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-dashscope/src/test/java/io/agentscope/extensions/model/dashscope/DashScopeChatModelTest.java |
Adds regression coverage for the structured-output capability flags. |
Comment on lines
+405
to
+409
| * <p>Returning {@code false} routes structured-output calls to the tool-based fallback | ||
| * path ({@code doFallbackStructuredCall}), which uses Qwen function-calling to return | ||
| * reliable, schema-conforming results. This also keeps | ||
| * {@link #supportsNativeStructuredOutputWithTools()} consistent, since it falls back to | ||
| * this method. |
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.
AgentScope-Java Version
main (
2.0.0-SNAPSHOT)Description
Background
When using structured output (
ReActAgent.call(msgs, MyClass.class, ctx)or theJsonNode schema overload) with
DashScopeChatModel, the returnedMsg.hasStructuredData()was alwaysfalseandgetStructuredData(...)returnednothing. The same code works on
OpenAIChatModel.Root cause
DashScopeChatModel.supportsNativeStructuredOutput()returnedtrue, soReActAgenttook the native structured-output path, which relies on
response_formatcarryingthe JSON Schema. But the DashScope native text-generation protocol
(
/api/v1/services/aigc/text-generation/generation) only supportsresponse_format: {"type":"json_object"}and not{"type":"json_schema"}. Theschema was never honored, the model returned natural-language text,
wrapNativeStructuredResultfailed to parse it as JSON (logged a WARN), and noSTRUCTURED_OUTPUTmetadata was attached.Changes
supportsNativeStructuredOutput()now returnsfalse, routing structured-outputcalls to the tool-based fallback path (
doFallbackStructuredCall), which usesQwen function-calling and returns reliable, schema-conforming results.
supportsNativeStructuredOutputWithTools()stays consistent since it falls back tothis method.
DashScope native protocol (and a pointer not to flip it back without proper
json_objectwiring).false.How to test
ReActAgent.call(msgs, SomeClass.class, ctx)on aDashScopeChatModelnow returns aMsgwithhasStructuredData() == trueand the parsed object available viagetStructuredData(...).Unit test:
DashScopeChatModelTest#testNativeStructuredOutputUnsupported.Checklist
mvn spotless:applyDashScopeChatModelTest: 54 passed)🤖 Generated with Claude Code