prompt-optimizer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePrompt Optimizer
提示词优化器
Optimize prompts with evals. Keep every instruction, example, and external context reference causal.
通过评估优化提示词。确保每条指令、示例和外部上下文引用都具备因果关联性。
Load Only What You Need
按需加载内容
| Need | Read |
|---|---|
| New prompt | |
| Existing prompt | |
| Model-family port | |
| Repeated failures | |
| Weak or ambiguous draft | |
| Provenance | |
| 需求 | 阅读内容 |
|---|---|
| 新提示词 | |
| 已有提示词 | |
| 跨模型迁移 | |
| 重复失败问题 | |
| 薄弱或模糊的草稿 | |
| 来源追溯 | |
Step 1: Capture Contract
步骤1:明确约定
Record before editing:
- task type: new, refine, port, or debug
- target model family and snapshot, if known
- prompt surface: ,
system,developer, tool descriptions, examples, schemasuser - layer owners: platform, deployer/persona, retrieved context, user payload
- objective and non-goals
- inputs, tools, and external files available
- required output shape
- success criteria and failure cases
- hard constraints: latency, verbosity, safety, budget, tool use, style
If success criteria or examples are missing, create a small eval set first.
If the bottleneck is model choice, retrieval, tool schema, or missing evals, say so before rewriting.
在编辑前记录以下信息:
- 任务类型:新建、改进、迁移或调试
- 目标模型家族及版本快照(若已知)
- 提示词载体:、
system、developer、工具描述、示例、模式user - 层级负责人:平台、部署者/角色、检索上下文、用户负载
- 目标与非目标
- 可用的输入、工具和外部文件
- 要求的输出格式
- 成功标准与失败案例
- 硬性约束:延迟、冗长性、安全性、预算、工具使用、风格
若缺少成功标准或示例,先创建一个小型评估集。
若瓶颈在于模型选择、检索能力、工具模式或缺失的评估体系,请在重写前说明。
Step 2: Inventory External Context
步骤2:梳理外部上下文
For repo or agent prompts, list stable context by exact path:
| Context type | Examples |
|---|---|
| Agent rules | |
| Specs | |
| Policies | |
| Examples | |
Rules:
- Reference stable files by repo-relative path instead of copying them.
- Paste only excerpts needed for the prompt or eval case.
- Mark whether a file is ,
loaded, orreferenced.out of scope - Avoid vague context pointers such as "read the docs".
对于仓库或Agent提示词,按精确路径列出稳定上下文:
| 上下文类型 | 示例 |
|---|---|
| Agent规则 | |
| 规范 | |
| 政策 | |
| 示例 | |
规则:
- 通过仓库相对路径引用稳定文件,而非复制内容。
- 仅粘贴提示词或评估案例所需的摘录。
- 标记文件状态为(已加载)、
loaded(已引用)或referenced(超出范围)。out of scope - 避免使用“阅读文档”这类模糊的上下文指向。
Step 3: Choose Model Strategy
步骤3:选择模型策略
Read .
references/model-family-notes.md- Known family: optimize for that family.
- Unknown family: write a portable base plus short adapter notes.
- Snapshot changes: rerun evals.
- Cross-family divergence: specialize only the failing layer.
阅读。
references/model-family-notes.md- 已知模型家族:针对该家族进行优化。
- 未知模型家族:编写可移植的基础版本,附加简短适配说明。
- 版本快照变更:重新运行评估。
- 跨家族差异:仅针对失败层级进行定制。
Step 4: Shape Prompt
步骤4:构建提示词结构
Read .
references/core-patterns.md- Put stable policy in or
system.developer - Put task-local facts, retrieved context, and variables in user-facing sections.
- Keep one owner per behavior rule.
- Use headings or tags only to separate content types.
- Put tool policy in prompt text; keep schemas in provider-native tools.
- Keep persona light unless it changes behavior.
- Use the shortest wording that preserves the constraint.
- Cut filler, repeated reminders, dead examples, and rationale that does not affect evals.
阅读。
references/core-patterns.md- 将稳定政策置于或
system层级。developer - 将任务本地事实、检索上下文和变量置于用户可见部分。
- 每个行为规则仅对应一个负责人。
- 仅使用标题或标签区分内容类型。
- 将工具政策写入提示词文本;保持模式为原生工具格式。
- 除非角色会改变行为,否则尽量简化角色设定。
- 使用能保留约束的最短措辞。
- 删除冗余内容、重复提醒、失效示例以及不影响评估的原理说明。
Step 5: Optimize
步骤5:优化迭代
Read for refinements.
references/meta-optimization-loop.md- Baseline the current prompt on the same eval slice.
- Cluster failures by root cause.
- Write concrete edit criticisms.
- Generate two to four candidates:
- minimal-diff repair
- structure-first rewrite
- examples-first or tool-rule variant
- provider adapter when needed
- Compare candidates on the same cases.
- Keep a short optimization log.
- Validate the winner on holdout cases.
- Stop on plateau, oscillation, overfit, excessive cost, or non-prompt bottleneck.
阅读进行改进。
references/meta-optimization-loop.md- 在相同评估切片上建立当前提示词的基准。
- 按根本原因对失败案例进行聚类。
- 撰写具体的编辑改进意见。
- 生成2-4个候选版本:
- 最小差异修复版本
- 结构优先重写版本
- 示例优先或工具规则变体版本
- 必要时提供模型适配版本
- 在相同案例上比较候选版本。
- 保留简短的优化日志。
- 在预留案例上验证最优版本。
- 当出现性能停滞、震荡、过拟合、成本过高或非提示词瓶颈时停止优化。
Step 6: Return Package
步骤6:交付成果包
Return:
TargetSuccess CriteriaExternal ContextOptimized PromptAdapter NotesEval SetOptimization LogResidual Risks
For existing prompts, include a concise diff-style note of the main behavioral changes.
返回以下内容:
目标成功标准外部上下文优化后的提示词适配说明评估集优化日志剩余风险
对于已有提示词,需包含简洁的差异式说明,标注主要行为变更。
Failure Modes
失败模式
- editing before defining the eval target
- mixing policy, examples, and raw context without boundaries
- duplicating rules across layers
- putting durable policy in user payloads
- asking for chain-of-thought
- keeping contradictory legacy instructions
- overfitting to one or two examples
- retaining examples that no longer improve evals
- fixing tool-use failures only in prompt text when tool descriptions or schemas are weak
- adding markup that does not reduce ambiguity
- using persona as a substitute for behavior rules
- 在定义评估目标前就开始编辑
- 无边界地混合政策、示例和原始上下文
- 在多个层级重复规则
- 将持久化政策放入用户负载
- 要求链式思考(chain-of-thought)
- 保留矛盾的遗留指令
- 过度拟合单个或两个示例
- 保留无法提升评估效果的示例
- 当工具描述或模式薄弱时,仅在提示词文本中修复工具使用失败问题
- 添加无法减少歧义的标记
- 用角色设定替代行为规则