ProductsMulti-sourceSelected72°

OpenAI Codex Cookbook 系列:Goals 从 Prompt 到自主目标

Why we picked it

Codex 的 Goals 解决了长任务中反复手动指挥的痛点,做自动化、性能优化或研究复现的开发者可以直接用模板写出更可靠的自主工作流。

OpenAI 发布了 Codex Cookbook 系列中关于 Goals 的深度指南,详细介绍了如何从传统的 prompt 模式(ask→work→result→wait)升级到 Goals 模式(work→check→continue or complete)。

Body

Goals 是线程作用域的持久状态,允许 Codex 在空闲时基于证据自主决定下一步,无需用户每轮重复指令。文章提供了强 Goal 的六要素模板(结果、验证面、约束、边界、迭代策略、阻塞停止条件),并用复现 Deep Hedging 论文的案例展示了如何将不确定的研究任务 Goal 化。

Goals 最适合持久目标、基于证据的终点、路径需多轮探查的场景,如性能优化、flaky 测试调查、依赖迁移等。

Original · shao__meng

OpenAI Codex Cookbook 系列之 Goals 从 "prompt" 到 "goals" · Prompt:ask → work → result → wait(做完即停) · Goal:work → check → continue or complete(做完检查证据,未达成则继续) Goal 的关键是给 Codex 一条可审计的完成线,并允许它在空闲时基于已有证据自主决定下一步,而无需用户每轮重复说"继续"、"再跑一次基准"、"现在查测试"。 生命周期和命令 Goals 是 线程作用域 的持久状态,不是全局 memory,也不是项目级 instructions。 /goal <目标> 设置目标 /goal 查看当前目标 /goal pause 暂停 /goal resume 恢复 /goal clear 清除 可能的停止条件:成功、暂停、清除、被打断、预算耗尽、遇到需用户输入的阻塞。 continuation 是事件驱动的,不是死循环:仅在线程 idle、无队列输入、无 pending 工作、Goal 仍 active 且在预算内时才会触发。Plan-only 的回合不触发 continuation;如果某次 continuation 没有调用任何工具,下一次自动 continuation 会被抑制(防止空转)。 如何写一个"强 Goal"——六个要素 1. Outcome(结果):完成时什么应为真。 2. Verification surface(验证面):用什么证据证明——测试、benchmark、报告、命令输出、产物。 3. Constraints(约束):工作期间不能回退什么。 4. Boundaries(边界):可用的文件、工具、数据、仓库。 5. Iteration policy(迭代策略):每次尝试后如何选择下一步。 6. Blocked stop condition(阻塞停止条件):何时该停下并说明无可行路径,需要什么才能解锁。 推荐模板: /goal <期望终态> verified by <具体证据> while preserving <约束>. Use <允许的输入/工具/边界>. Between iterations, <如何选择下一步最佳行动>. If blocked or no valid paths remain, <报告什么、需要什么才能继续>. 对比示例(性能优化): · 弱:/goal Improve performance · 中:/goal Reduce p95 checkout latency below 120 ms without regressing correctness tests · 强:在上一条基础上加入 benchmark 名、允许动用的服务/fixture 范围、每轮记录变化与下一个实验,以及"基准跑不动时如何报告阻塞"。 Goal 激活后发生了什么变化 1. 目标常驻可见:测试失败、benchmark 改善但未达阈值、研究路径数据缺失,Codex 都不会丢掉原始目标。 2. 可以从 idle 线程自主续跑——但仅在安全边界(无 pending 工作、无用户输入排队)。 3. 完成必须基于证据:不能因为模型"觉得差不多"就标记完成,必须对照文件、测试、日志、benchmark 输出或产物。 研究类 Goal 的范式案例:复现 Deep Hedging 论文 最具启发性的部分,用 Buehler 等人的 Deep Hedging 论文做案例,说明"复现一篇论文"这种充满不确定性的任务该如何 Goal 化。 弱 Goal:/goal Reproduce Buehler et al., "Deep Hedging" —— 没说哪一节、什么算复现、缺失训练状态怎么办。 强 Goal 要求 Codex 产出一份分级证据报告,区分四类状态: · Reproduced mechanics(机理已重建) · Approximate trained results(近似训练结果) · Blocked exact replay(无法精确复现的部分) · Remaining uncertainty(剩余不确定性) 实际执行中,Codex 能重建定价/对冲机理、复现 Heston 参考价、训练 CVaR 对冲策略、重建主直方图与对冲面、复现 BS 交易成本斜率;但原始随机种子、训练路径、TF 计算图、optimizer 状态、checkpoint 全部缺失——因此最诚实的结果只能是"部分近似复现,而非精确神经回放"。 何时不该用 Goal? · 一行编辑、简短解释、小段 code review、单问单答 —— 用普通 prompt。 · 终点模糊("make this better"、未定义终态的 "refactor this")。 · 用 Goal 来掩盖不确定性——如果数据可能缺失、benchmark 可能 flaky、代理证据是否允许,都应在 Goal 中显式说明。 Goal 的最佳适配场景具备三个属性:持久目标 + 基于证据的终点 + 路径可能需要多轮探查。典型用例:性能优化、flaky 测试调查、依赖迁移、需复现的 bug 猎杀、多步重构、benchmark 驱动调优、需产物的研究任务。 Cookbook developers.openai.com/cookbook/examp… Derrick Choi @derrickcchoi My colleagues wrote up a great post on using Goals in Codex. They go through when to use them, what changes when a Goal is active, and how to write Goals that give Codex a clear outcome, constraints and verification criteria. Also how we designed Goals at the architecture level if you’re curious. developers.openai.com/cookbook/examp… 🔗 View Quoted Tweet

Industry Coordinates & Source Verification

This report is categorized under AITOP's "Products" desk, focusing on US frontier AI labs and Silicon Valley technology leaders. Within our cross-regional analytical framework, it directly maps to AI developer toolchains, coding agents, and engineering workflows. Key entities and technical topics under continuous tracking include Codex, Goals, coding assistants, OpenAI.

Source attribution: curated from shao__meng (@shao__meng). Cross-source corroboration: 11 independent sources have covered this development (including Greg Brockman, 小互, AI Engineer), confirming industry-wide signal strength.

Spotted an error in the summary or translation? Tell us