📐 结构化输出
# 返回结构化结果
默认返回文本。需要 Java 对象时,在 Agent 组件内添加结果类型并覆写:
public record OrderAnswer(String orderId, String status, String explanation) {}
@Override
protected Class<?> structuredOutputType() {
return OrderAnswer.class;
}
执行成功后,response.getSlot().getResponseData() 就是该类型的对象。例如类型定义在 ChatAgentCmp 中,调用端使用 ChatAgentCmp.OrderAnswer 接收。
需要动态 JSON Schema 时,改为覆写 structuredOutputSchema() 返回 Jackson JsonNode,结果也为 JsonNode。这两种方式只选一种。
# 在调用端接收
以上结果类型定义在 ChatAgentCmp 内时,可这样使用:
LiteflowResponse response = flowExecutor.execute2Resp("chatChain", "查询订单 A1001");
if (!response.isSuccess()) {
throw new IllegalStateException("Agent 执行失败", response.getCause());
}
ChatAgentCmp.OrderAnswer answer = response.getSlot().getResponseData();
流式文本用于过程展示,业务侧应使用成功完成后返回的对象。订单是否可退款、金额是否有效等业务判断,仍应由后续业务组件校验。
帮助我们改善此文档 (opens new window)
上次更新: 2026/09/20, 11:49:27



