Skip to content

[Bug]:结构化输出有问题,报No structured output in message metadata. Key '_structured_output' not found. #1699

Closed

Description

@mytu-lub

@PostMapping(value = "/structured")
@operation(summary = "Agent 结构化输出",
description = "让 Agent 输出结构化的 TaskAnalysis 对象(title/priority/estimatedHours)")
public TaskAnalysis structured(@RequestParam String userMsg) {
log.info("收到结构化分析请求: {}", userMsg);
// 步骤 1: 构建专门用于任务分析的 Agent
ReActAgent agent = ReActAgent.builder()
.name("taskAnalyzer")
.sysPrompt("你是一个任务分析专家。请分析用户的任务描述,提取关键信息并结构化输出为 TaskAnalysis 对象。")
.model(notStreamModel)
.build();

    // 步骤 2: 构建用户消息
    Msg msg = new UserMessage(userMsg);
    // 步骤 3: 调用 Agent 并传入目标类型
    Msg response = agent.call(msg, TaskAnalysis.class).block();
    log.info("Agent 结构化分析结果: {}", JacksonUtils.toJson(response));
    // 步骤 4: 从响应中提取结构化数据
    TaskAnalysis taskAnalysis = response.getStructuredData(TaskAnalysis.class);
    return taskAnalysis;
}
public class TaskAnalysis {
    /**
     * 任务标题
     */
    public String title;
    /**
     * 任务优先级:high/medium/low
     */
    public String priority;
    /**
     * 预估工时(小时)
     */
    public int estimatedHours;
}

Activity

  1. added
    bug
    on Jun 10, 2026
  2. mytu-lub commented on Jun 10, 2026

    @mytu-lub
    Author
    Image
  3. added
    area/core/agent
    on Jun 11, 2026
  4. beyond0630 commented on Jun 24, 2026

    @beyond0630

    me too,

  5. qingtianbuyu commented on Jun 28, 2026

    @qingtianbuyu

    是不是用了flash 模型?

  6. qy8502 commented on Jul 1, 2026

    @qy8502

    模型能力有限未能正确输出结构化数据,这可以理解,不过能否自动重试,等到getStructuredData才报错,还需要自己编写重试逻辑。

  7. qingtianbuyu commented on Jul 1, 2026

    @qingtianbuyu

    我遇到过,临时建议以下解决方案

    1. 换更强的模型 + 提示词中声明结构化json示例但是需要去掉 json 这个包裹
    2. 我在 2.0.0-RC4 版本中发现GenerateOptions 没有设置 params.setResponseFormat(responseFormat); 导致模型恢复没有给出具体结构,
  8. beyond0630 commented on Jul 2, 2026

    @beyond0630

    @qingtianbuyu 设置了 responseFormat 也还有问题

    Image
  9. qingtianbuyu commented on Jul 2, 2026

    @qingtianbuyu

    @beyond0630 这个是版本的问题,你设置了参数没生生效是因为agentscope java 源码里 DashScopeToolsHelper.applyOptions 少了下面的处理,得等官方修复。不过你可以把提示词贴出来看看,因为提示词的json示例给的对,只要不是flash 模型应该能推理出里

    ResponseFormat responseFormat = getOption(options, defaultOptions, GenerateOptions::getResponseFormat);
    if (responseFormat != null) {
    params.setResponseFormat(responseFormat);
    }

  10. beyond0630 commented on Jul 3, 2026

    @beyond0630

    与 V1 对比, V2 少了输出的结构信息
    Image

  11. qlprimer commented on Jul 9, 2026

    @qlprimer

    我也触发了这个BUG,从studio中看输出内容看返回的metadata中根本没有返回_structured_output结构。还好在content中返回了相应提取的json字符串,我不得不使用JSON.parseObject 兜底转化。

  12. moved this from Backlog to In progress in AgentScope Javaon Oct 10, 2026
  13. added a commit that references this issue on Oct 10, 2026
    8eb9115
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/core/agentbug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions