Skip to content

feat: 支持 prompt/SDK 的结构化最终输出 schema #493

@wucm667

Description

@wucm667

What feature would you like to see?

希望 Kimi Code 在非交互 prompt 模式和 SDK 中支持“结构化最终输出 schema”。

当前 kimi -p 已有 --output-format text|stream-json,适合读取文本结果或消费事件流,但它不能约束最终 assistant response 的结构。对于 CI、自动化脚本、评审机器人、批量代码分析等场景,用户通常希望得到可验证的 JSON 对象,而不是再从自然语言里解析。

一个可能的接口方向:

  • CLI:支持类似 kimi -p "..." --output-schema schema.json 的参数,要求最终回答符合 JSON Schema。
  • SDK:在 prompt/turn 选项里支持 outputSchema,让调用方直接传入 JSON Schema 对象。
  • 运行行为:如果模型输出不符合 schema,可以重试、返回结构化 validation error,或在 stream-json 中额外发出验证失败事件。
  • 输出行为:继续保留现有 stream-json 事件流;schema 只约束最终 answer,不影响工具调用事件本身。

Additional information

我基于当前最新 upstream/main 做了代码和 issue/PR 去重检查:

  • 当前 CLI 只暴露 --output-format <format>,可选值为 text / stream-json
  • PromptOutputFormat 类型目前也是 text | stream-json
  • runPromptTurn 直接收集 assistant delta 并输出,没有最终输出 schema 校验层。
  • 搜索过 structured outputoutput schemaresponse_formatfinal output schema,没有找到同主题 issue 或未合并 PR。

这个能力和 Codex SDK/CLI 的 outputSchema / --output-schema 使用场景类似:让 headless agent 更适合作为可靠的程序化组件,而不只是文本生成器。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions