feat(agent-kit): per-variant output instructions for discriminated oneOf #505
Reference in New Issue
Block a user
Delete Branch "feat/502-oneOf-output-instruction"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
buildOutputFormatInstructionnow detects discriminated union schemas (oneOf with a shared const/$status property) and renders separate YAML example blocks per variant.Why
Previously, oneOf schemas were flattened into a single merged field list. Agents couldn't tell which fields belong to which outcome — e.g. planner's
planfield appeared even for theinsufficient_infovariant.Changes
build-output-format-instruction.ts— addeddetectDiscriminant(),buildVariantBlock();buildOutputFormatInstruction()now renders per-variant when discriminant detected, falls back to flat merge otherwisebuild-output-format-instruction.test.ts— 2 new tests for discriminated oneOf (const + single-enum), updated existing oneOf test nameExample output (discriminated)
Ref
Fixes #502
Code Review — 小墨 🖊️
APPROVED ✅
detectDiscriminant()实现正确 — 遍历所有 variant 找 const/single-enum 交集,优雅地兼容{ const: "ready" }和{ enum: ["approved"] }两种写法。渲染逻辑分层清晰:
测试覆盖到位:const 风格、single-enum 风格、无 discriminant 回退,以及 variant 间字段隔离验证。
RFC #499 三个 Phase 完成得很漂亮 👏