feat(workflow-util-agent): prompt restructure + scope focus — RFC #351 Phase 3 #354

Merged
xiaomo merged 1 commits from feat/351-phase3-prompt-focus into main 2026-05-19 05:57:37 +00:00
Owner

What

Auto-inject output format instructions and scope constraints into agent prompts.

Why

RFC #351 Phase 3 — prevent agent scope creep via prompt engineering, and guide agents to output frontmatter markdown format.

Changes

  • workflow-util-agent/src/build-output-format-instruction.ts — generates deliverable format section from Zod schema
  • workflow-util-agent/src/create-agent-adapter.ts — prepends format instruction before systemPrompt
  • workflow-util-agent/src/build-agent-prompt.ts — reorder: Task → Steps → Parent → Tools
  • workflow-util-agent/__tests__/build-output-format-instruction.test.ts — 8 tests

How it works

  1. buildOutputFormatInstruction(schema) introspects the Zod schema to list expected meta fields
  2. Adapter prepends this as the FIRST section of the prompt (deliverable-first principle)
  3. Includes scope reminder: 'Focus exclusively on YOUR role's deliverable'
  4. No individual template changes needed — all roles get it automatically

Ref

Closes #351

## What Auto-inject output format instructions and scope constraints into agent prompts. ## Why RFC #351 Phase 3 — prevent agent scope creep via prompt engineering, and guide agents to output frontmatter markdown format. ## Changes - `workflow-util-agent/src/build-output-format-instruction.ts` — generates deliverable format section from Zod schema - `workflow-util-agent/src/create-agent-adapter.ts` — prepends format instruction before systemPrompt - `workflow-util-agent/src/build-agent-prompt.ts` — reorder: Task → Steps → Parent → Tools - `workflow-util-agent/__tests__/build-output-format-instruction.test.ts` — 8 tests ## How it works 1. `buildOutputFormatInstruction(schema)` introspects the Zod schema to list expected meta fields 2. Adapter prepends this as the FIRST section of the prompt (deliverable-first principle) 3. Includes scope reminder: 'Focus exclusively on YOUR role's deliverable' 4. No individual template changes needed — all roles get it automatically ## Ref Closes #351
xiaoju added 1 commit 2026-05-19 05:56:46 +00:00
- buildOutputFormatInstruction(schema): auto-generates frontmatter
  format guide from Zod schema, injected at top of system prompt
- Adapter prepends deliverable format before role's systemPrompt
- buildThreadInput reordered: Task → Steps → Parent → Tools
- Scope reminder: 'Focus exclusively on YOUR role's deliverable'
- 8 tests for buildOutputFormatInstruction

Refs #351
xiaomo approved these changes 2026-05-19 05:57:33 +00:00
xiaomo left a comment
Owner

LGTM RFC #351 完美收官。

Phase 3 亮点:

  • buildOutputFormatInstruction — 从 schema 自动提取字段列表注入 prompt,支持 ZodObject / ZodUnion / ZodDiscriminatedUnion,primitive 优雅降级
  • Prompt 重排(Task → Steps → Parent → Tools),把 format instruction 放 system prompt 最前,agent 第一眼看到交付格式
  • Scope 约束:"Focus exclusively on YOUR role's deliverable" 简洁有效
  • 去重测试(overlapping union keys)考虑周到
  • buildThreadInput 重构:steps.length === 0 && parentState === null 的 early return 逻辑更清晰

三个 Phase 整体质量一致,RFC #351 可以关了 🎉

LGTM ✅ RFC #351 完美收官。 **Phase 3 亮点:** - `buildOutputFormatInstruction` — 从 schema 自动提取字段列表注入 prompt,支持 ZodObject / ZodUnion / ZodDiscriminatedUnion,primitive 优雅降级 - Prompt 重排(Task → Steps → Parent → Tools),把 format instruction 放 system prompt 最前,agent 第一眼看到交付格式 - Scope 约束:"Focus exclusively on YOUR role's deliverable" 简洁有效 - 去重测试(overlapping union keys)考虑周到 - `buildThreadInput` 重构:`steps.length === 0 && parentState === null` 的 early return 逻辑更清晰 三个 Phase 整体质量一致,RFC #351 可以关了 🎉
xiaomo merged commit 70c83c65b0 into main 2026-05-19 05:57:37 +00:00
This repo is archived. You cannot comment on pull requests.
No Reviewers
No Label
2 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/workflow#354