Skip to content

fix(model): disable native structured output for DashScope (#1852)#1959

Open
zhangliyuangit wants to merge 1 commit into
agentscope-ai:mainfrom
zhangliyuangit:fix/1852-dashscope-structured-output
Open

fix(model): disable native structured output for DashScope (#1852)#1959
zhangliyuangit wants to merge 1 commit into
agentscope-ai:mainfrom
zhangliyuangit:fix/1852-dashscope-structured-output

Conversation

@zhangliyuangit

Copy link
Copy Markdown

AgentScope-Java Version

main (2.0.0-SNAPSHOT)

Description

Background

When using structured output (ReActAgent.call(msgs, MyClass.class, ctx) or the
JsonNode schema overload) with DashScopeChatModel, the returned
Msg.hasStructuredData() was always false and getStructuredData(...) returned
nothing. The same code works on OpenAIChatModel.

Root cause

DashScopeChatModel.supportsNativeStructuredOutput() returned true, so ReActAgent
took the native structured-output path, which relies on response_format carrying
the JSON Schema. But the DashScope native text-generation protocol
(/api/v1/services/aigc/text-generation/generation) only supports
response_format: {"type":"json_object"} and not {"type":"json_schema"}. The
schema was never honored, the model returned natural-language text,
wrapNativeStructuredResult failed to parse it as JSON (logged a WARN), and no
STRUCTURED_OUTPUT metadata was attached.

Note: simply wiring response_format through (mirroring the OpenAI channel) does
not fix this — DashScope's native endpoint does not accept json_schema, so it
would be ignored or rejected with HTTP 400.

Changes

  • supportsNativeStructuredOutput() now returns false, routing structured-output
    calls to the tool-based fallback path (doFallbackStructuredCall), which uses
    Qwen function-calling and returns reliable, schema-conforming results.
    supportsNativeStructuredOutputWithTools() stays consistent since it falls back to
    this method.
  • Added Javadoc documenting why native structured output is unsupported on the
    DashScope native protocol (and a pointer not to flip it back without proper
    json_object wiring).
  • Added a regression test asserting both flags are false.

How to test

ReActAgent.call(msgs, SomeClass.class, ctx) on a DashScopeChatModel now returns a
Msg with hasStructuredData() == true and the parsed object available via
getStructuredData(...).

Unit test: DashScopeChatModelTest#testNativeStructuredOutputUnsupported.

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (DashScopeChatModelTest: 54 passed)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

🤖 Generated with Claude Code

…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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 return false, 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.
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.

2 participants