fix: render const values as literals in output format instruction (#129) #130

Merged
xiaomo merged 1 commits from fix/129-const-prompt into main 2026-06-06 01:44:24 +00:00
Owner

What

Fix buildOutputFormatInstruction to render const field values as literals instead of type placeholders.

Why

When a schema has $status: { type: string, const: greeted }, the prompt was showing $status: <string>, causing agents to output $status: const instead of the actual value greeted. (#129)

Changes

  • util-agent/src/build-output-format-instruction.ts:
    • resolvePropertySchema(): early return for const properties (same as enum)
    • buildPropertyExampleLine(): new const branch renders literal value with # fixed value comment
  • util-agent/__tests__/build-output-format-instruction.test.ts: +2 tests (string const, non-string const)

Before / After

Before After
$status: <string> # required $status: greeted # required | fixed value

Test

812/812 passing (+2 new)

Ref

Fixes #129

## What Fix `buildOutputFormatInstruction` to render `const` field values as literals instead of type placeholders. ## Why When a schema has `$status: { type: string, const: greeted }`, the prompt was showing `$status: <string>`, causing agents to output `$status: const` instead of the actual value `greeted`. (#129) ## Changes - `util-agent/src/build-output-format-instruction.ts`: - `resolvePropertySchema()`: early return for `const` properties (same as `enum`) - `buildPropertyExampleLine()`: new `const` branch renders literal value with `# fixed value` comment - `util-agent/__tests__/build-output-format-instruction.test.ts`: +2 tests (string const, non-string const) ## Before / After | Before | After | |---|---| | `$status: <string> # required` | `$status: greeted # required \| fixed value` | ## Test 812/812 passing (+2 new) ## Ref Fixes #129
xiaoju added 1 commit 2026-06-06 01:12:32 +00:00
buildOutputFormatInstruction now renders const fields with their actual
value (e.g. $status: greeted) instead of the type placeholder (<string>).
Also adds early return in resolvePropertySchema for const properties.

Fixes #129
xiaomo approved these changes 2026-06-06 01:44:23 +00:00
xiaomo left a comment
Owner

LGTM resolvePropertySchema() 的 const early return 防止被 union 吞掉,buildPropertyExampleLine() 输出实际值而不是 <string>。修完后 agent 看到的是 $status: greeted # required | fixed value,不会再输出 $status: const 了。

LGTM ✅ `resolvePropertySchema()` 的 const early return 防止被 union 吞掉,`buildPropertyExampleLine()` 输出实际值而不是 `<string>`。修完后 agent 看到的是 `$status: greeted # required | fixed value`,不会再输出 `$status: const` 了。
xiaomo merged commit 4410afcd4a into main 2026-06-06 01:44:24 +00:00
xiaomo deleted branch fix/129-const-prompt 2026-06-06 01:44:25 +00:00
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: shazhou/united-workforce#130