Codex 的封装:GPT-6.1 Sol 子代理调度与跨设备部署

根代理默认直接完成,按级别、积分权重和 Astra 闸门派发 Luna、Sol 与 Astra 子代理,构建可迁移的 Codex 工作流

第 07 篇发布于 更新于

返回博客

Codex 的封装:GPT-6.1 Sol 版

用途: 为 Codex 配置可迁移的模型分工、派发规则与验收流程

当前基线: 2026-10-13,Codex CLI 0.162.1(Windows standalone),根代理 gpt-6.1-sol / medium

首次发布: 2026-09-02;历次部署与复核记录见附录

配套复盘: 《Codex 调度策略一个月复盘》

我对 Codex 的封装落在三处:用配置固定角色,用指令约束派发,用证据决定任务是否完成。正文只写现行规范;旧版本的实验过程和撤回过的结论放在附录。

2026-10-13 这一版按一个月的会话记录和 CLI 0.162.1 重写:

  • 根代理默认自己完成任务。以前的规则要求所有代码改动都交给 Sol 实现者,结果修一条启动报错、写一份报告、回复一句"允许"都会派出子代理。
  • 派发按级别和积分权重计预算;Astra 只在闸门下使用一次。
  • 角色改为按职责命名(implementer、qa、reviewer、astra_reviewer、recon)。实现和 QA 用 gpt-6-sol,常规审查用 gpt-6.1-sol;两者互为预授权的后备模型。
  • implementer、qa、reviewer 的角色文件不固定模型,model 和 effort 都由每次派发给出;按原因升档:没尽力就提 effort,能力不够就换更强的角色。
  • 针对模型能力波动:满载或断流时按降级阶梯处理;界面类任务设可见检查点和返工上限;长任务写进度行;无关任务开新线程。
  • 根代理默认 effort 从 xhigh 降到 medium:对照实验里读代码、写说明的任务耗时减半,引用没有出错;难题在会话内用 /model 切到 xhigh。
  • 本机继续以完全权限运行会话,文中如实写明只读角色只由指令约束。

目标与分工

1.1 默认由根代理直接完成

Codex 文档对子代理的触发写得很直接:可以在提示里明确要求派发,"Codex can also delegate when applicable project or skill instructions request it";同时 "Subagent workflows consume more tokens than comparable single-agent runs because each subagent does its own model and tool work"。Subagents

旧版 AGENTS.md 恰好就是那条"项目指令要求委派"的来源。它规定任何生产或测试代码改动都必须交给 Sol 实现者,根代理不得自己改。旧版文章没有写这条规则的理由;我推断是当时根代理用 Astra,而 Astra 比 Sol 贵得多。现在根代理用 gpt-6.1-sol,按本机 token 构成折算只有实现者(gpt-6-sol)的约 0.6 倍,委派不再换来更便宜的模型,只多出一份上下文和一轮协调。

2026-09-27 之后的 21 个根任务里有 17 个派了子代理。按触发派发的那条用户消息逐条核对,其中有一次 commit & push(派出 Astra 审查;8 条 commit & push 消息(分布在 7 个任务里)中只有这一条触发派发)、修一条 pnpm dev 启动报错(派出实现者)、手机调试中的一句回复(派出 Astra 审查)、生成一份 HTML 报告(派出侦察和实现)、回复"允许"(派出实现者或 QA)。统计口径和完整数据见配套复盘。

现行规则把根代理直接完成设为默认,只有四种理由可以派发:可并行的独立工作、根代理不该装进上下文的大块内容、下文触发条件要求的独立验证、用户明确要求。以下任务不派发:git 操作、运行或重跑命令、问答与解释、文档与报告、配置修改、根代理能直接操作的浏览器或设备、约三个文件以内且不在高风险区域的明显修复。

1.2 角色与模型

角色(agent_type)模型后备模型默认 effort允许 effort权重用途
根代理gpt-6.1-sol会话内 /model 切换medium难题用 /model 切到 xhigh-协调、直接完成小任务、最终验收
recongpt-6-luna(固定)无mediumlow、medium、high、max0.08窄范围搜索、盘点、代码路径、日志归纳
implementergpt-6-solgpt-6.1-solxhighhigh、xhigh、max1.6委派的生产与测试代码改动
qagpt-6-solgpt-6.1-solhighmedium、high、xhigh1.6长时或并行的构建测试、浏览器与设备证据
reviewergpt-6.1-solgpt-6-solhighhigh、xhigh1对具体 diff 的独立只读审查
astra_reviewergpt-6-astra(固定)无high(固定)high8只用于 Astra 闸门

模型选择综合了官方说明和本机实测。官方子代理页写 "For most tasks in Codex, start with gpt-6.1-sol",Luna 用于 "fast, narrowly scoped agents";模型页称 GPT-6.1 Sol "offers near-Astra performance for complex work at a lower cost"。Subagents、Models 但官方没有给出速度。本机 9-27 以后的数据里,输入 10 万到 20 万 token、输出 300 到 1500 token 的响应,gpt-6.1-sol(根代理,xhigh)中位延迟 33 秒、约 18 tok/s,gpt-6-sol(子代理)13 秒、约 43 tok/s;这组对比里 6.1 Sol 全是根代理、6 Sol 全是子代理,而同一模型做根代理本身就慢约 1.3 倍(Astra 的根代理与子代理之比),扣除这一点后 6.1 Sol 每次响应约慢 2 倍(原始比较 2.6 倍),上下文越长差距越大;同一时刻、都作为根会话的对照实验里是 1.8 倍(见 1.6)。说它是模型特性,依据是它连续 5 天稳定在 18 到 28 tok/s,外部实测也在 15 到 26 tok/s。因此实现和 QA 这类长工具循环用 gpt-6-sol,审查用 gpt-6.1-sol:审查输出短、质量更要紧,而且审查者和实现者跑在不同模型上,某一个模型满载时另一个往往照常工作。

权重来自定价页的 Standard 速度积分单价(每百万 token):

模型输入缓存输入输出
gpt-6-astra250251,250
gpt-6.1-sol502.5250
gpt-6-sol505250
gpt-6-luna2.50.2512.5

权重按本机实际的 token 构成折算:子代理的输入约 98% 命中缓存,缓存输入的单价差距(Astra 是 GPT-6.1 Sol 的 10 倍、Luna 是 0.1 倍)主导了总价。按 E3 实现者的 token 构成计算,以 gpt-6.1-sol 为 1,Luna 约 0.08,gpt-6-sol 约 1.6,Astra 约 8;只看输入和输出单价会得到 0.05 和 5,低估 Astra。同一原因,gpt-6.1-sol 处理同样的 token 量比 gpt-6-sol 便宜约 38%;本文让实现和 QA 用 gpt-6-sol,是用这部分积分换速度。定价页同时提醒积分单价不直接决定订阅内的额度,实际消耗以用量面板为准。Pricing

effort 档位是本机选择。官方给的起点更低:显式设置时 Luna 从 high、Astra 从 low 起步,high 适合审查和安全类代理。实现者默认 xhigh 的理由是:小改动已经留给根代理,真正委派出去的实现都是较大的改动。effort 会改变输出长度:本机 gpt-6-sol 用 high 时平均输出比 xhigh 少约 46%、平均延迟低约 25%。这一点没有做过质量对照,返工率和用量要继续记录。

1.3 级别与预算

级别用途预算(Sol 当量派发)
L0 Direct不派发清单内的任务,根代理能独立完成的任务0
L1 Bounded一个委派实现或一次独立检查2
L2 Standard一个实现加一次独立审查或 QA4
L3 Complex跨模块或高风险工作;最低可用 Astra 的级别14
L4 Exceptional大型迁移、全面审计;须用户在本任务中明确批准20

每次 spawn_agent 都按模型权重计入预算,失败后重派也算。预算覆盖整个用户任务,跨轮次和 goal 续跑都累计。给已有线程分配新工作的 followup_task 按角色权重另计一次;同一交付物上的修复追加,每次派发含两次,第三次起另计。Fast 让权重乘 2.5,Ultrafast 乘 8(订阅额度倍率;用购买积分时是 2 和 6);effort 改变 token 数,不改变权重。L2 及以上在第一次派发前报告一次账本:级别、每个派发的角色、模型、effort、权重和理由、加权合计。

这套结构移植自我在 Claude Code 侧的 dispatch-policy:权重是官方价格比,预算是上限不是目标,到限即停并报告未完成的部分。《成本优先的 Subagent 与 Workflow 调度实践》

1.4 审查、QA 与 Astra 闸门

默认验证由根代理完成:检查委派的 diff,自己跑针对性检查。架构、安全、权限、并发、数据完整性、公共契约、迁移或跨模块的 diff 才加 reviewer;需要长时或并行的测试套件、浏览器、模拟器或设备证据,或用户要求独立 QA 时才加 qa。

审查采用对抗式写法:审查者拿到原始需求、约束、实际 diff 和已有证据,任务是驳倒改动;第二轮审查开新线程,不对第一位审查者追加。

astra_reviewer 权重为 8。每个用户任务最多一次,只在 L3 及以上,只针对安全、权限、隐私、并发、数据完整性、不可逆迁移、高影响发布、关键架构边界中的一个具体问题,或常规审查者对这类问题给出了不确定结论。它在便宜的证据整理成一个包之后串行运行,不与另一个 Astra 同时运行,也不通过 followup_task 复用。2026-09-27 以来,Astra 根代理加 Astra 审查约占本机估算积分的 57%,这是设闸门的直接原因。

1.5 GPT-6 指南带来的执行约定

官方 GPT-6 指南的提示词建议现在面向整个 GPT-6 家族,以 Astra 为写作对象,要求按模型重新评估。GPT-6 指南本文保留三项执行约定:在授权范围内持续推进;因技能规则停下时指出具体来源;按改动风险完成必要验证,出现新证据才扩大检查。指南里的委派提示词鼓励更多委派,与 1.1 的方向相反,本文不采用。

ultra 会主动委派,模型目录对它的说明是 "Maximum reasoning with automatic task delegation"。会话以 ultra 运行时,规则要求根代理告知用户一次,并照样按派发理由和预算执行。2026-09-14 到 09-26 用过 ultra 的 8 个根任务里出现了 16 次没带角色的派发,但另有 15 次出在没用 ultra 的任务里,数据只说明二者相关。

1.6 应对模型能力波动

过去六周本机的波动有四种形态,统计方法和完整数据见配套复盘:

形态本机证据规律
满载失败35 个失败轮次里 25 个是 Selected model is at capacity,除 gpt-6-luna 外所有在用模型都出现过按天集中出现;10 月的几次只打在 gpt-6.1-sol 上,同一会话里的 gpt-6-sol 和 Astra 照常工作
速度骤降Astra 在 09-12、gpt-6-sol 在 09-30 的日中位速度降到平时的一半按天发生;多数模型按小时只差 1.1 到 1.5 倍,gpt-6-sol 的 2.7 倍也来自 09-30 那一天
额度耗尽周额度在 09-10、09-16、09-29 三次打满来自 Astra 的大量使用;10 月最高 43%
模型间的稳定差距gpt-6.1-sol 每次响应比 gpt-6-sol 慢约 2 倍(扣除根代理与子代理差别后)连续多天稳定,属于模型特性

Codex 的行为:HTTP 和流中断会自动重试,0.161/0.162 起会遵循服务端的重试建议;这些重试失败,或者遇到满载、额度耗尽,整轮就结束,本机观察到的失败里没有一次自动换模型。最长的一次,一个跑了 75 分钟的根代理轮次直接结束。容量问题累计约占 84 小时根代理轮次时间里的 4.4 小时,没有一个任务因此最终卡死;最大的时间损耗来自界面类任务的验收错位:本地测试全过,用户看了却不能用,然后反复返工。

对应的规则(第 6 节原文):

  • 预授权后备: gpt-6-sol 与 gpt-6.1-sol 互为后备。子代理在其中一个上满载或断流时,根代理一句话告知用户,在另一个模型上从最后完成的步骤重派一次;这次后备重派不受级别预算限制,但要记入账本。失败的线程不再用 followup_task 追加。
  • 降级阶梯: 重派仍失败或角色没有后备时,依次改为根代理直接做、缩小或串行任务、停下并报告从哪里续跑;不自建重试循环,后备对之外换到更便宜的模型要用户同意。额度耗尽时停止派发,报告重置时间。
  • 根代理自身失败: 失败的轮次既不能给自己换模型,也说不了话;下一个成功的轮次里,根代理提示用户用 /model 在选择器里换到另一个模型,并从最后一条进度行续跑。
  • 可见检查点与返工上限: 验收取决于外观或手感的任务,做到第一个可运行、可看见的里程碑就停下给截图或运行步骤;同一验收项连续两轮没有可量化的进展(失败用例没有减少),停下给出选项;用户可以对某个任务免除检查点。
  • 进度行与短轮次: 预计超过约 30 分钟的工作先复述目标和验收标准,长步骤前写一行"目标、已完成、待办、下一步、改动文件";轮次越短,失败时损失越少。
  • 一个任务一个线程: gpt-6.1-sol 的延迟随上下文增长,输入 5 万 token 以下中位约 17 秒,25 万以上约 41 秒;无关任务开新线程,先写交接说明。

2026-10-13 的根代理对照实验:同一时刻用四种配置跑同一个只读分析任务(读 6 个源文件,写 600 到 900 字、每句带行号引用的说明,最后列三个风险),四个都是根会话,上下文 4 万到 5.5 万 token。引用准确性由一个独立审查者逐条核对:

配置总耗时(含约 10 秒启动)模型时间输出 token(推理占比)引用核对
gpt-6.1-sol xhigh210 s190 s5,348(36%)47 处,0 错,2 处偏差 1 到 3 行
gpt-6.1-sol medium108 s92 s2,505(4%)43 处,0 错,4 处偏差
gpt-6-sol xhigh134 s107 s6,385(56%)47 处,0 错,2 到 3 处偏差;唯一发现一个未被使用的字段
gpt-6.1-sol xhigh + Fast209 s188 s6,332(40%)45 处,0 错,2 处偏差

四份答案都没有错误引用,差距在样本能分辨的范围以内。这次只有一个任务、各跑一次,能说明的有限:在这种读代码、写说明的任务上,gpt-6.1-sol 把 effort 从 xhigh 降到 medium,耗时减半,引用准确性没有可见损失;Fast 那一组的生成速度高约 20%,但 rollout 里看不出 Fast 是否确实生效,单次对比也分不清这是 Fast 的效果还是随机波动,总耗时没有缩短;gpt-6-sol xhigh 的总耗时比 gpt-6.1-sol xhigh 短约三分之一。据此本机根代理的默认 effort 从 xhigh 改为 medium,难题在会话里用 /model 切回 xhigh;规则要求根代理在 L3 及以上的任务里提醒一次,因推理深度不够而失败时停下请用户切换,不在 medium 上重试(见第 6 节)。换一天重跑,才能把模型特性和当天的波动分开。

不建议的做法:在规则里加重试循环(Codex 已经在重试);依赖 model/rerouted 事件(文档有这个事件,本机一次都没出现);按时段错峰(数据里没有时段规律)。某个模型整天表现差时,最直接的对冲是把当天的工作换到另一个工具,例如 Claude Code。

官方依据与关键事实

关键配置事实:

  • 官方文档每一页都有 Markdown 版本:在完整路径后加 .md,适合复核时逐字比对。
  • 全局配置在 ~/.codex/config.toml,全局指令在 ~/.codex/AGENTS.md,全局自定义 Agent 在 ~/.codex/agents/*.toml;项目规则在项目根目录的 AGENTS.md,项目专属 Agent 可放在项目的 .codex/agents/*.toml。
  • 独立 Agent TOML 必须包含 name、description 和 developer_instructions;不要把 developer_instructions 写成 instructions。
  • 模型与 effort 的优先级: 角色文件里写了 model 或 model_reasoning_effort 就以文件为准。应用文件之前,Codex 依次取派发值、[agents] 默认值、父代理的值;文件只固定 model 时保留之前解析出的 effort。本文的 implementer、qa、reviewer 不固定模型,recon 和 astra_reviewer 才固定,所以前三个角色的 model 和 effort 都由派发决定,后备模型也靠这一条生效。2026-10-13 的烟测中,recon 按派发值以 low 运行;qa 按派发值在 gpt-6.1-sol 上运行,reviewer 在 gpt-6-sol 上运行。
  • 工具面由模型决定: 模型目录给每个模型标了 multi_agent_version,GPT-6 家族都是 v2。v2 的工具是 spawn_agent(参数 task_name、agent_type、model、reasoning_effort、fork_turns、message)、followup_task、send_message、wait_agent、list_agents、interrupt_agent,子代理按 /root/<task_name> 这样的路径寻址,没有 close_agent。旧版本文把工具差异归因于 CLI 与桌面端,这个解释撤回;派发前仍以当前会话的工具 schema 为准。
  • fork: 0.162.0 删除了部分历史 fork,fork_turns 只剩 none 和 all,不填就复制完整父历史。规则要求每次派发都写 "none"。
  • 线程容量: max_concurrent_threads_per_session 限制同时打开的子代理线程,不含根线程;文档没有说完成的线程何时释放槽位。本机在上限大多为 2 的 09-04 到 09-08(UTC)共有 21 次 spawn_agent 因 agent thread limit reached 失败,另有 4 次 followup_task、2 次 send_message;09-08 上限改为 6 之后,单个根任务最多派出 36 个线程、没有调用过关闭工具,也没有再报错。
  • 权限继承: 父会话带有 /permissions、--yolo 之类的实时权限覆盖时,即使角色文件写了别的 sandbox_mode,子代理也沿用父会话的权限。本机继续以完全权限运行会话,所以 reviewer、astra_reviewer、recon 的 read-only 只是名义上的,只读靠指令约束。config.toml 里的 workspace-write / on-request 只是新会话和 codex exec 的默认值;会话实际权限要看 TUI 的 /status、thread/start 的返回值或 rollout 的 turn_context,codex doctor 只报告配置层的值。
  • 递归委派: v2 的默认提示允许子代理继续派发,没有配置项限制深度。"子代理不得继续委派"只存在于指令里;过去一个月的 377 个子代理线程没有一个继续派发。
  • 指令文件: 每层优先读取 AGENTS.override.md,项目从根目录到工作目录逐层加载,默认合计上限 32 KiB。0.156.0 起全局指令可能在下一次模型请求时刷新,但验收仍以新会话为准。
  • Hooks: PreToolUse 能匹配 spawn_agent(别名 Agent),可以拒绝调用或改写参数;文档同时说明这是 "a useful guardrail, not a complete enforcement boundary",返回 ask 时调用照常执行,hook 修改后要重新信任。E3 的 79 次派发中 78 次用了自定义角色、74 次角色模型档位完全一致,文本规则已经覆盖大部分情况,暂不部署派发 hook。
  • 可观测性: 0.162.0 起 subAgentActivity 的 started 一类记录带解析后的 model 与 effort(rollout 里字段是 reasoning_effort,app-server 里是 reasoningEffort),其他类型为空;rollout 里子线程的 session_meta 有 agent_role、parent_thread_id,turn_context 有模型、effort 和实际权限。

Codex Home 路径

先检查是否设置了 CODEX_HOME。

Windows PowerShell

$env:CODEX_HOME

如果没有输出,默认路径是:

C:\Users\<用户名>\.codex

macOS / Linux

printf '%s\n' "$CODEX_HOME"

如果没有输出,默认路径是:

$HOME/.codex

下文统一用 ~/.codex 表示实际 Codex Home。

最终文件结构

~/.codex/
├── config.toml
├── AGENTS.md
└── agents/
    ├── implementer.toml
    ├── qa.toml
    ├── reviewer.toml
    ├── astra-reviewer.toml
    └── recon.toml

本机另有 ~/.codex/scripts/ 下的复盘脚本(解析 rollout 和 thread-history 数据库,统计派发、速度和失败),属于个人工具,不在部署范围内。

不要把整份部署文档复制到 AGENTS.md。只合并第 6 节的三节规则,并检查实际加载的指令链大小。

全局 config.toml 增量配置

必须保留目标电脑已有的 ~/.codex/config.toml。不要整文件覆盖,不要打印其中的 API key、HTTP header、token、MCP secret 或完整敏感内容。先记录相关键的旧值和是否原本存在,再定点更新根级设置:

model = "gpt-6.1-sol"
model_reasoning_effort = "medium"
model_verbosity = "low"

这三行必须位于 TOML 根级。model_verbosity = "low" 与本机模型目录缓存中每个模型的默认值相同,写出来是为了让迁移后的机器与本机一致。

如果不存在 [agents],加入:

[agents]
enabled = true
max_concurrent_threads_per_session = 6
default_subagent_model = "gpt-6-sol"
default_subagent_reasoning_effort = "high"
interrupt_message = true

如果已经存在 [agents],只合并这五个键,不得创建第二个 [agents] 表;遗留别名 max_threads 记录后删除。6 与官方完整配置示例一致,是容量上限,不是派发目标。default_subagent_* 只在派发没给值、角色文件也没固定时生效,不能替代显式派发。三个角色不再固定模型以后,漏写 model 的派发会落到这里;默认值从 Luna 改为 gpt-6-sol / high,避免漏写时悄悄降到最便宜的模型。

Windows 上把沙箱实现设为 MXC:

[windows]
sandbox = "mxc"

文档现在列出三种实现:mxc(兼容设备上的推荐项,原生进程隔离,不需要管理员配置)、elevated(MXC 不可用时的首选回退)、unelevated(网络隔离较弱)。改之前先在项目目录用 PowerShell 跑一次探针,它不改变已保存的选择:

codex -c windows.sandbox=mxc sandbox --include-managed-config --permission-profile :workspace -- cmd.exe /d /c echo MXC_OK

输出 MXC_OK 且退出码为 0 才改配置。MXC 有两条文档写明的限制:前台命令退出时它启动的子进程也会结束,脱离前台的开发服务器要另行处理;托管网络需要 allow_local_binding = true。在 Git Bash 里运行时,/d、/c 会被改写成路径,请用 PowerShell。MXC 需要 Windows 11 24H2 build 26100.9278 或 25H2 build 26200.9278 及以上。Windows sandbox

其余说明:

  • 除上述三个根键、五个 [agents] 键和 [windows] sandbox 外,保留 provider、MCP、plugin、sandbox、approval、project trust、hook 等全部配置。
  • 本机会话以完全权限运行;sandbox_mode 与 approval_policy 是新会话和 codex exec 的默认值,本文不改动它们。
  • Fast mode 支持 GPT-6.1 Sol、Astra、Sol 和 Luna,消耗订阅额度 2.5 倍、购买积分 2 倍;Ultrafast 只支持 Astra 和 GPT-6.1 Sol,消耗 8 倍额度、6 倍积分,限 Pro $500 与部分企业和教育计划。本文保持 service_tier = "default",不对子代理开启 Ultrafast。Speed
  • -p/--profile <name> 现在叠加 $CODEX_HOME/<name>.config.toml,旧的 [profiles.<name>] 表从 0.134.0 起不再读取。把派发相关键放进一个 profile 文件可以避免改动含凭据的主配置,但桌面端是否读取 profile 文件尚未验证,本文仍按主配置部署。

修改磁盘配置只证明持久值已经写入,不能证明现有任务已经重新加载。

全局 AGENTS.md 规则

把下面三节追加或合并到实际生效的全局指令文件。默认是 ~/.codex/AGENTS.md;若存在有效的 AGENTS.override.md,先报告它的覆盖作用,再在该文件定点合并。已有同名标题时保留用户约定、记录旧内容;遇到相互矛盾的授权边界,指出具体冲突,不整节抹掉。

## Writing Style

- In prose, use precise verbs and limit adverbs and degree words. Do not label emotions, atmosphere, or manner of action; convey them through observable actions, sensory details, and consequences. When removing a modifier, replace any lost information with a specific verb, detail, or consequence.

## Execution and Verification

- Complete authorized work; keep the goal when the user adds corrections.
- Skills cannot override higher-priority instructions or the user's request. Name any blocking file and rule.
- Run required checks; repeat only for changes, failures, or evidenced risks.
- Separate observed results from assumptions; report specific blockers.
- When auditing configuration, parse it and output only explicitly allowlisted non-sensitive fields needed for the task, such as model, reasoning effort, sandbox, approval policy, and agent limits. Never dump full configuration or rely on redaction after output. Treat MCP arguments, environment values, HTTP headers, and process command lines as potentially credential-bearing; report their presence without values unless a specific value is verified safe and needed.
- When acceptance depends on how something looks or feels (UI layout and styling, interaction feel, UX flow, generated images), stop at the first runnable visible milestone, show screenshots or exact run steps, and ask the user to accept or correct it. This checkpoint is part of the task scope and takes precedence over finishing in one turn, unless the user waives it for this task. Continuing the same deliverable after the user accepts it is part of the original work and of the original spawn. Report gate results separately from user acceptance.
- Stop a repair loop after two rounds that make no measurable progress on the same acceptance criterion (the same failing cases or error, or a failing set that did not shrink), or that only change tests, fixtures, or assertions while the user's reported problem stays open. Report the criterion, the evidence, what was tried, and two or three options, then wait for the user.
- For work expected to take more than about 30 minutes, first state the goal in one sentence, the acceptance criteria, and the checkpoint where you will stop and show results. Before a step expected to run longer than about 15 minutes, and at each checkpoint, write a progress line: goal, done, open, next, files touched. Shorter turns lose less work when a turn fails. If the current work no longer serves the stated goal, stop and say so.
- When a block surfaces no approval prompt (a sandbox or permission error, missing credentials, a read-only path, an operating-system dialog), end the turn with the exact action the user must take instead of waiting or working around it.
- When the user starts a task unrelated to the current thread, suggest a new thread and first write a handoff: goal, state, open items, files, verification commands. Long contexts slow every response and add compaction time; keep related follow-ups in the same thread.

## Codex Subagent Dispatch

### Default to direct work

- The root agent is the sole coordinator, integrator, and final acceptance owner. By default it does the work itself.
- Spawn a subagent only when it adds something the root cannot get as cheaply by working directly: independent work that can run in parallel, a large context the root should not load, independent verification required by the triggers below, or an explicit user request. Name that reason for every spawn. Each subagent does its own model and tool work, so delegated work costs more tokens than the same work done once by the root, and delegation buys no cheaper model: the root (`gpt-6.1-sol`) bills at about 0.6 times the implementer (`gpt-6-sol`).
- Do not spawn for: git operations (status, diff, commit, push, or a merge or rebase without conflicts to analyze); running or rerunning a command; questions and explanations the root can answer from a bounded context; documentation, prose, plans, and reports; configuration edits; browser, device, or environment operations the root can drive itself; and small code changes (an evident fix touching about three files or fewer). The root makes these changes and runs the targeted checks itself.
- The no-spawn list yields to the review and QA triggers below: an item that touches a high-risk area (architecture, security, permissions, concurrency, data integrity, public contracts, migrations) or needs a long-running or parallel suite follows those triggers instead.
- An explicit user request to spawn overrides the no-spawn list and sets the level to at least L1 for that spawn.
- A skill, plan, or prompt template that prescribes subagents does not override this section. Follow it only when the task meets a spawn reason above.

### Levels and budget

- Weigh each spawn by its model's Codex credit cost relative to `gpt-6.1-sol` at this machine's observed token mix (about 98% cached input): `gpt-6-luna` 0.08, `gpt-6.1-sol` 1, `gpt-6-sol` 1.6, `gpt-6-astra` 8. Fast multiplies a spawn's weight by 2.5 and Ultrafast by 8 (included-usage rates). Reasoning effort changes a spawn's tokens, not its weight.

| Level | Use for | Budget (Sol-equivalent spawns) |
| --- | --- | --: |
| L0 Direct | Everything in the no-spawn list and any task the root can finish alone | 0 |
| L1 Bounded | One delegated implementation or one independent check | 2 |
| L2 Standard | One implementation plus one independent review or QA | 4 |
| L3 Complex | Cross-module or high-risk work; the lowest level that may use Astra | 14 |
| L4 Exceptional | Large migration or full audit; requires explicit user approval in this task | 20 |

- The budget covers the whole user task, across turns and goal continuations. Every spawn counts, including a respawn after a failure. A `followup_task` that assigns new work counts as a new spawn at the role's weight. Up to two repair follow-ups per spawn, each carrying a concrete finding or failure on the same deliverable, are part of that spawn; count each further one.
- At L2 and above, report once before the first spawn: the level, each planned spawn with its role, model, effort, weight, and reason, and the weighted total. Update the report only when the level or the remaining budget changes.
- At a limit, stop spawning and report the unfinished work. Raise the level only on the user's instruction.
- Run the independent spawns of one phase concurrently. Serialize work that consumes an earlier result, writes the same files, or contends for one mutable runtime resource.

### Roles and spawn contract

| `agent_type` | Model | Fallback | Default effort | Allowed effort | Use |
| --- | --- | --- | --- | --- | --- |
| `recon` | `gpt-6-luna` (pinned) | none | `medium` | `low`, `medium`, `high`, `max` | Narrow search, inventory, code-path mapping, log summaries |
| `implementer` | `gpt-6-sol` | `gpt-6.1-sol` | `xhigh` | `high`, `xhigh`, `max` | Delegated production and test changes |
| `qa` | `gpt-6-sol` | `gpt-6.1-sol` | `high` | `medium`, `high`, `xhigh` | Long or parallel builds and tests; browser, emulator, or device evidence |
| `reviewer` | `gpt-6.1-sol` | `gpt-6-sol` | `high` | `high`, `xhigh` | Independent read-only review of a concrete diff |
| `astra_reviewer` | `gpt-6-astra` (pinned) | none | `high` (pinned) | `high` | The Astra gate only |

- Every spawn sets `agent_type` to one of these five roles, `model` to that role's model (or its fallback under the failure rules below), `reasoning_effort` from its allowed set, and `fork_turns` to `"none"`. The `implementer`, `qa`, and `reviewer` files pin no model, so the spawn's `model` decides; `recon` and `astra_reviewer` pin theirs. An omitted `fork_turns` forks the full parent history. Make the task message self-contained.
- Subagents use GPT-6 family models only (`gpt-6-sol`, `gpt-6.1-sol`, `gpt-6-astra`, `gpt-6-luna`); never GPT-5.x.
- Escalate by cause. If a worker did not try hard enough (skipped files, did not run the check, did not double-check), raise its effort within the role or sharpen the task. If it did not know enough (subtle bug, unfamiliar domain, architecture decision), move to a stronger role. Judge cost per completed task, not per token.
- `ultra` effort adds proactive delegation. If this session runs at `ultra`, tell the user once and still apply the spawn reasons and budgets in this section.
- The root session defaults to `medium` effort. When the session runs below `xhigh`, say once per task, in the first reply on L3 or L4 work (with the ledger report or the L4 approval request when there is one), that `/model` can raise the session effort to `xhigh`. If a root attempt failed because the problem needs deeper reasoning, do not retry at the same effort: stop, say so, and ask the user to switch with `/model`.
- Read the session's callable tool schema before dispatch or lifecycle operations. GPT-6 models expose the v2 tools (`spawn_agent`, `followup_task`, `send_message`, `wait_agent`, `list_agents`, `interrupt_agent`) and address agents by path, such as `/root/<task_name>`. Never invent a missing tool or parameter.
- For `implementer`, `qa`, and `reviewer`, which pin no model, read the resolved model and effort from the spawned agent's `started` activity record. If the model is neither the role's model nor its fallback, stop dependent work and respawn correctly. A spawn that omits `model` resolves to the `[agents]` default `gpt-6-sol` and counts at its weight. If a spawn omitted another required field and the resolved values still match the role, record the deviation and review the output normally.
- If a role's model is unavailable, follow the failure rules below. Never move a task to a cheaper role silently.

### Review and QA triggers

- The root inspects every delegated diff and runs the targeted checks itself. That is the default verification.
- Add `reviewer` for architecture, security, permissions, concurrency, data integrity, public contracts, migrations, or a cross-module diff. Add `qa` only when acceptance needs a long-running or parallel suite, or browser, emulator, or device evidence that the root should not run inline, or when the user asks for independent QA. Do not route every task through every role.
- Give reviewers the original requirements, constraints, the actual diff and necessary context, existing verification evidence, and the assumptions to challenge, and ask them to refute the change rather than confirm it. A second review uses a fresh reviewer thread, not a follow-up to the first.
- Astra gate: `astra_reviewer` weighs 8. Use it at most once per user task, only at L3 or above, and only for a named issue in security, permissions, privacy, concurrency, data integrity, irreversible migration, a high-impact release, or a critical architecture boundary, or after a reviewer reported an uncertain conclusion on such an issue. Run it after the cheaper evidence is consolidated into one packet, never alongside another Astra spawn, and never reuse its thread through `followup_task`.
- Use APPROVE or BLOCK only for a concrete change or release gate. For research, inventory, and design discussion, return confirmed findings, unknowns, and recommendations; an unknown alone does not block the whole task.

### Capacity, stream, and usage-limit failures

- Codex retries HTTP and stream errors and follows server retry advice. When those retries fail, or on an overload or usage-limit error, the turn ends with `Selected model is at capacity` (server overloaded), `stream disconnected`, or `usage_limit_exceeded`; in the failures observed on this machine Codex did not switch models. Treat these as expected states and add no retry loop of your own.
- These failures are not repair findings. Do not send `followup_task` to the failed thread; inspect any partial changes it left, then follow the steps below.
- The user pre-authorized `gpt-6-sol` and `gpt-6.1-sol` as fallbacks for each other (2026-10-13). When a subagent on one of them fails with a capacity or stream error, tell the user in one line (agent path, role, model, error, last completed step) and respawn the same role once on the other model, starting from the last completed step. This first fallback respawn does not count against the level limit; report it in the next ledger update at the new model's weight.
- If that respawn also fails, or the role has no fallback, then in order: do the remaining work directly when it fits direct work and say so; otherwise narrow or serialize it; otherwise stop spawning, report the blocker and the resume point, and wait for the user. Never respawn in a loop. Moving work to a cheaper model outside the pre-authorized pair needs the user's yes.
- On `usage_limit_exceeded`, stop spawning, report the reset time from the error, and wait.
- A failed root turn cannot switch its own model or report anything. On the first successful turn after a root turn failed at capacity, tell the user that `/model` (then choosing `gpt-6-sol` or `gpt-6.1-sol`) switches the session model, and resume from the last progress line.

### Ownership, permissions, and capacity

- Only the root dispatches. Subagents must not delegate further, alter the overall goal, widen scope, stage, commit, push, publish, or modify planning and memory files unless the user explicitly authorizes that exact action. This ban exists only in instructions: the default v2 prompt allows nested spawns and no setting caps depth.
- One write-capable agent owns a file at a time. Parallel writes to the same files belong to separate sessions started with `codex --worktree`, never to parallel spawns.
- Every child inherits the parent's live permission mode. Under full access a role's read-only `sandbox_mode` is not enforced, so read-only roles stay read-only by instruction.
- `max_concurrent_threads_per_session` (currently 6, excluding the root) caps open spawned threads; it is a ceiling, not a staffing target. On `agent thread limit reached`, refresh `list_agents`, reuse a matching thread through `followup_task`, and confirm capacity with a successful spawn before claiming recovery. Do not retry in a loop, downgrade the model, or skip a required review. Change the limit only with user authorization.
- Reuse a thread only for related work whose role, model, effort, file ownership, and retained context fit the task. Preserve reviewer independence.
- Every delegated task states its objective, scope, owned files, acceptance criteria, required verification, forbidden actions, evidence format, and stopping conditions, in proportion to the task.
- A subagent completion is an evidence handoff, not acceptance. The root inspects the diff and verification evidence, resolves blocking findings, and decides acceptance. Root verification focuses on acceptance criteria, high-risk conclusions, and conflicting evidence, and does not repeat a completed check without a new change, failure, or specific concern.
- Preserve user-owned dirty files. Implementers do not stage or commit. The root stages exact task paths and commits only when the user authorizes it and the change forms one coherent theme.

自定义 Agent TOML

旧版五个文件(sol-implementer、sol-reviewer、terra-qa、luna-recon、luna-recon-max)由下面五个文件取代。旧名按模型命名,迁到 GPT-6 后出现了"跑 Sol 的 terra_qa"和"跑 Astra 的 sol_reviewer"。luna-recon-max 删除,需要更深推理时以 recon 加 reasoning_effort = "max" 派发。部署前在本机保留旧文件以便恢复,不把配置备份上传到仓库。

7.1 implementer.toml

路径:~/.codex/agents/implementer.toml

name = "implementer"
description = "Implements a delegated production or test change that is large, context-heavy, or parallel with other work; small fixes stay with the root. Model and effort come from the spawn."
sandbox_mode = "workspace-write"

developer_instructions = """
Implement only the explicitly assigned scope.
Follow all applicable AGENTS.md instructions.
Do not change the task goal, expand scope, add speculative features, or perform unrelated refactoring.
Do not add compatibility layers, fallbacks, abstractions, or defensive guards without direct evidence that they are required.
Do not delegate to another agent.
Do not stage, commit, push, publish, or modify planning and memory files.
Preserve user-owned and unrelated working-tree changes.
Use test-driven development when the repository requires it.
Run targeted verification appropriate to the change.
Return an evidence packet containing changed files, decisions, exact commands, results, failures, and remaining unknowns.
"""

7.2 qa.toml

路径:~/.codex/agents/qa.toml

name = "qa"
description = "Runs long or parallel builds and tests and collects browser, emulator, or device evidence for an assigned behavior. Model and effort come from the spawn."
sandbox_mode = "workspace-write"

developer_instructions = """
Validate only the assigned behavior.
Follow all applicable AGENTS.md instructions.
Do not modify production or test source files.
Workspace-write permission exists only because builds and tests may create generated outputs.
Do not delegate, stage, commit, push, or publish.
Record exact commands, exit codes, observed behavior, screenshots or logs when relevant, and the limits of the evidence.
Separate local engineering evidence from physical-device, production, external-service, or release proof.
Return PASS, FAIL, or BLOCKED for each acceptance criterion; do not claim the whole task is complete.
"""

7.3 reviewer.toml

路径:~/.codex/agents/reviewer.toml

name = "reviewer"
description = "Read-only independent reviewer of a concrete diff for correctness, security, concurrency, and regression risks. Model and effort come from the spawn."
sandbox_mode = "read-only"

developer_instructions = """
Review only the assigned scope and remain read-only.
Follow all applicable AGENTS.md instructions.
Do not edit files, stage, commit, push, publish, or delegate.
Evaluate the original requirements, constraints, actual diff and necessary context, existing verification evidence, and assumptions to challenge. Treat the implementer's explanation as supporting material, not the conclusion to confirm.
Work adversarially: try to refute the change and prove it does not work before accepting it. Recommend BLOCK only with a concrete counterexample, failing input, race, invariant violation, or authoritative source.
Prioritize correctness, security, data integrity, concurrency, behavior regressions, and missing test coverage.
Do not report style-only findings unless they conceal a real defect.
For each finding, provide severity, file and line evidence, impact, reproduction or counterexample, and the smallest defensible remediation.
Distinguish confirmed findings from risks and unverified gaps. When your conclusion on a high-risk point is uncertain, say so explicitly so the root agent can decide whether a stronger review is needed.
For a concrete change or release gate, end with an APPROVE or BLOCK recommendation and tie any blocker to an acceptance criterion.
For research, inventory, or design discussion, return confirmed findings, unknowns, and recommendations without forcing an approval verdict. An unknown alone does not block the whole task.
The root agent retains final acceptance authority.
"""

7.4 astra-reviewer.toml

路径:~/.codex/agents/astra-reviewer.toml

name = "astra_reviewer"
description = "Gated read-only GPT-6 Astra review of one named high-risk issue, used at most once per task."
model = "gpt-6-astra"
model_reasoning_effort = "high"
sandbox_mode = "read-only"

developer_instructions = """
You are the gated Astra review. Review only the named high-risk issue and the evidence packet you receive, and remain read-only.
Follow all applicable AGENTS.md instructions.
Do not edit files, stage, commit, push, publish, or delegate.
Evaluate the original requirements, constraints, actual diff and necessary context, existing verification evidence, earlier review findings, and assumptions to challenge. Treat earlier explanations and reviews as supporting material, not conclusions to confirm.
Work adversarially: try to refute the change and prove it does not work before accepting it. Recommend BLOCK only with a concrete counterexample, failing input, race, invariant violation, or authoritative source.
For each finding, provide severity, file and line evidence, impact, reproduction or counterexample, and the smallest defensible remediation.
Distinguish confirmed findings from risks and unverified gaps, and name what evidence would settle each remaining unknown.
For a concrete change or release gate, end with an APPROVE or BLOCK recommendation and tie any blocker to an acceptance criterion.
The root agent retains final acceptance authority.
"""

7.5 recon.toml

路径:~/.codex/agents/recon.toml

name = "recon"
description = "Read-only agent for narrow searches, code-path mapping, inventory, log summaries, and bounded analysis."
model = "gpt-6-luna"
sandbox_mode = "read-only"

developer_instructions = """
Stay within the assigned question and remain read-only.
Follow all applicable AGENTS.md instructions.
Prefer targeted search and focused file reads over broad repository scans.
Do not repeat exploration already supplied by the root agent.
Do not propose speculative fixes unless explicitly asked.
Do not implement code, make architecture decisions, approve security-sensitive changes, edit, delegate, stage, commit, push, or publish.
Stop and return BLOCKED if the task requires broader context or production-code judgment.
Return concise findings with file and symbol evidence, the smallest counterexample found, and remaining unknowns.
"""

另一台电脑的一键部署 Prompt

使用方式:复制下面的 Prompt,在末尾的"附件"位置依次粘贴第 6 节代码块的全部内容和第 7 节的五个 TOML(保留每个文件的路径标题),然后发送给目标电脑上的 Codex。最好从一个普通项目目录启动,并使用有权写入 Codex Home 的本地权限模式。

请在这台电脑上部署一套 GPT-6.1 Sol 根代理的全局 Codex 子代理配置。只修改当前用户的 Codex Home 配置,不修改任何项目文件,不暂存、不提交、不推送。

目标行为:
1. 根代理使用 gpt-6.1-sol,默认 effort 为 medium(难题由用户用 /model 切到 xhigh),是唯一协调者、整合者和最终验收者,默认自己完成任务。
2. 只在四种理由下派发:可并行的独立工作、根代理不该装进上下文的大块内容、触发条件要求的独立验证、用户明确要求。git 操作、单条命令、文档与报告、配置修改、设备操作和约三个文件以内的明显修复不派发。
3. 派发按级别和积分权重计预算(gpt-6-luna 0.08、gpt-6.1-sol 1、gpt-6-sol 1.6、gpt-6-astra 8),L2 及以上在第一次派发前报告账本。
3a. implementer 和 qa 用 gpt-6-sol,reviewer 用 gpt-6.1-sol,二者互为预授权后备;子代理满载或断流时告知用户并在后备模型上重派一次,再失败则按降级阶梯处理。
4. 每次派发都写 agent_type(recon、implementer、qa、reviewer、astra_reviewer 之一)、对应模型、允许范围内的 reasoning_effort,以及 fork_turns = "none"。
5. 默认验证由根代理检查 diff 并运行针对性检查;高风险或跨模块改动加 reviewer,需要长时、并行或设备证据时加 qa;astra_reviewer 每个任务最多一次,只在 L3 及以上的具体高风险问题上串行使用。
6. 子代理不得继续委派、扩大范围、暂存、提交、推送、发布或修改规划和 memory 文件。
7. 写作使用精确动词,限制副词和程度词;用可观察的动作、细节和后果传达情绪与方式。

执行边界:
- 先使用当前安装的官方 Codex 文档核对自定义 Agent、AGENTS.md、config.toml 和 reasoning effort 的格式。
- 核对目标账号和客户端是否提供 gpt-6.1-sol、gpt-6-sol、gpt-6-astra、gpt-6-luna;文档列出模型不等于当前账号可用。缺少某个模型时报告阻塞,不换成其他模型。
- 运行 codex --version,记录当前版本,不要擅自升级。检查 CODEX_HOME;未设置时使用平台默认的 ~/.codex。
- 解析配置后只输出本次需要的非敏感白名单字段,如模型、effort、sandbox、审批策略和线程上限。不要打印完整 config.toml,也不要先输出再脱敏;MCP args、env、headers 和进程命令行默认只报告是否存在。
- 保留所有现有配置和 AGENTS.md 内容,只做定点合并。记录每个相关键、章节和 Agent 文件部署前的状态,仅在本机保存恢复材料。
- 若存在旧版 sol-implementer、sol-reviewer、terra-qa、luna-recon、luna-recon-max 文件且属于本文旧版,备份后删除;若同名文件属于其他用途,保留并报告冲突。
- 检查实际生效的全局指令文件、项目到工作目录的覆盖链和当前模型选择;AGENTS.override.md 存在时不要只更新被它遮蔽的 AGENTS.md。
- 使用结构化补丁编辑文件,不要用会整体覆盖文件的重定向命令。修改磁盘配置不证明现有任务已重新加载,必须在新进程中核对。未经授权不得提高线程上限。

步骤 A:在 ~/.codex/config.toml 根级定点更新 model = "gpt-6.1-sol"、model_reasoning_effort = "medium"、model_verbosity = "low";确保只有一个 [agents] 表并合并 enabled = true、max_concurrent_threads_per_session = 6、default_subagent_model = "gpt-6-sol"、default_subagent_reasoning_effort = "high"、interrupt_message = true,遗留 max_threads 记录后删除。

步骤 B:仅限 Windows。在 PowerShell 中运行 codex -c windows.sandbox=mxc sandbox --include-managed-config --permission-profile :workspace -- cmd.exe /d /c echo MXC_OK。输出 MXC_OK 且退出码为 0 时把 [windows] sandbox 设为 "mxc";否则保留原值并报告错误。

步骤 C:在实际生效的全局指令文件中合并附件里的 "## Writing Style"、"## Execution and Verification"、"## Codex Subagent Dispatch",各保留一节。

步骤 D:按附件创建五个 Agent 文件,并按上面的规则处理旧版文件。

步骤 E:静态验证。用 TOML 解析器检查主配置和五个 Agent 文件,核对 name、description、model、model_reasoning_effort、sandbox_mode 和 developer_instructions;运行 codex doctor,确认 config.toml parse ok、没有 "is ignored" 提示,Windows 上 sandbox backend 为 mxc;确认三节规则各只有一节;枚举实际加载的指令文件,检查是否超过 project_doc_max_bytes(默认 32768 字节)。

步骤 F:只读烟测。在已知项目目录运行一次 codex exec --sandbox read-only -c approval_policy=never --model gpt-6.1-sol -c model_reasoning_effort=low,要求根代理按用户明确要求派发一个 recon(gpt-6-luna、low、fork_turns none)和一个 qa(gpt-6.1-sol、low、fork_turns none),各自只读取 package.json 或另一个已知文件中的一个已知字段。qa 的子线程模型应为 gpt-6.1-sol,证明不固定模型的角色会采用派发值。完成后从 ~/.codex/sessions 中找到子线程 rollout,读取 session_meta 的 agent_role 与 parent_thread_id、turn_context 的 model、effort 和 sandbox_policy。比较烟测前后的 git status 和 diff。

步骤 G:最终报告。报告 Codex 版本和 Codex Home;修改、创建和删除的文件;合并的键和章节;解析命令与结果;doctor 的配置、沙箱结果;烟测子线程的 agent_role、model、effort、sandbox;恢复材料位置;任何未验证项。确认没有修改、暂存、提交或推送项目文件。任何未完成项都不能写成全部部署成功。

完成前不要提交任何 Git 仓库,也不要更新 memory。

附件:

部署完成后的验证 Prompt

启动一个全新的 Codex 对话后发送:

这是只读配置验收任务,不要修改任何文件,不要派发子代理。

请报告:
1. 当前 Codex 版本和工作目录。
2. 本会话加载了哪些全局和项目 AGENTS.md 指令来源。
3. 是否存在 Writing Style、Execution and Verification、Codex Subagent Dispatch 三节规则,以及 Dispatch 一节里的不派发清单、级别表和角色表。
4. 当前可用的自定义 Agent 名称。
5. 根代理和每个 Agent 的配置值:model、model_reasoning_effort(未固定时写明由派发给出)和 sandbox_mode,并说明覆盖来源。
6. max_concurrent_threads_per_session 的文件值;说明它限制打开的子代理线程,不是同时执行数。
7. 本会话的实际权限模式,并说明在该模式下只读角色是否真正只读。
8. 是否存在 AGENTS.override.md、项目配置覆盖、未知字段、重复 TOML table 或解析错误。

解析配置后只输出上述验收需要的非敏感白名单字段;不要输出密钥、token、HTTP header、MCP secret 或完整 config.toml,也不要先输出再脱敏。将"从配置文件读取到的值"和"运行时实际可观察到的值"分开报告。

只读 recon 烟测 Prompt

把目标文件和字段改成目标项目中确实存在的内容:

这是只读 subagent 烟测,也是派发子代理的明确要求。先确认本会话以只读权限运行;否则停止并报告需要调整的运行设置。

派发且只派发一个子代理:agent_type = "recon",model = "gpt-6-luna",reasoning_effort = "low",fork_turns = "none"。任务:报告 `<目标文件>` 中 `<目标字段或符号>` 的值和行号。

以当前会话工具 schema 为准;缺少字段时报告限制,不虚构参数。不要修改文件,不要运行构建,不要做额外仓库扫描。等待子代理返回,然后报告:agent_type、请求的模型和 effort、可见的解析后模型和 effort(不可见则说明)、文件与行号证据,以及相对于烟测前 git status 和 diff 的变化。

运行后到 ~/.codex/sessions 找到子线程的 rollout,核对 session_meta.agent_role 为 recon、turn_context 的模型为 gpt-6-luna、effort 为 low。2026-10-13 本机按这一步验证通过。

新项目接入 Prompt

全局 Agent 已部署后,每个项目只需要一份准确的项目根目录 AGENTS.md。把下面 Prompt 发给 Codex,并将 <项目路径> 替换为真实路径:

请为 `<项目路径>` 设计并创建或更新项目根目录 AGENTS.md。

执行边界:
- 先只读检查项目结构、构建文件、现有文档、真实测试命令和当前 Git 状态。
- 保留已有 AGENTS.md 内容,只做必要的项目级合并。
- 不复制全局"Codex Subagent Dispatch"全文;写明本项目继承全局调度规范,只写项目特有规则。
- 不修改生产代码或测试代码;不暂存、不提交、不推送。这个任务属于 L0,不派发子代理。
- 不写猜测性的构建命令、模块结构、依赖版本或测试数量。
- 发现信息不确定时列出未知项和可验证证据,不加入 fallback 或宽泛规则。

AGENTS.md 至少应覆盖:
1. 项目简介和真实技术栈。
2. 当前模块或目录结构。
3. 架构边界与禁止事项。
4. 安全、凭据和外部系统约束。
5. 真实可运行的构建、测试、lint 和格式化命令。
6. 针对 UI、移动端、后端、数据库或基础设施的验证要求。
7. Git、脏工作区、暂存、提交和发布纪律。
8. 本项目的高风险区域(决定何时加 reviewer 或 Astra 闸门)和派发例外;没有例外时写明继承全局规则。
9. 指令优先级和适用范围。

完成后:
- 展示 AGENTS.md 的变更摘要。
- 报告使用了哪些来源验证每条关键事实。
- 按目标工作目录检查实际加载的完整指令链,包括 override、嵌套目录指令和合并分隔符,是否超过 project_doc_max_bytes(默认 32768 字节)。
- 给出一个新会话只读验证命令。

日常 Prompt 示例

配置生效后,日常任务不需要重复调度规范。多数请求直接说要做什么即可,根代理会按 L0 自己完成。

小改动或运维操作

修复 `<报错或问题>`,自己改并运行针对性检查,不要派发子代理。完成后 commit & push。

需要委派的实施

实现 `<具体功能>`,遵循已加载的 Codex Subagent Dispatch 和项目 AGENTS.md。先判定级别并在派发前报告账本;实现交给 implementer,根代理检查 diff 和针对性验证。涉及高风险区域时加 reviewer,需要设备或长时测试证据时加 qa。保留用户已有修改,不扩大范围,不提交。

只读审查

只需要 review,不修改任何代码或文档。根代理先自己审查;只有涉及高风险区域时才派发 reviewer,并要求它尝试驳倒改动。按严重性返回有文件和行号依据的 findings;没有发现时说明剩余验证缺口。

深度调查

对 `<问题>` 做证据驱动的深度调查。根代理先锁定具体证据缺口;只有存在可并行、互不依赖的窄问题时才派发 recon,每个都显式写 agent_type、model、reasoning_effort 和 fork_turns = "none"。先给出最小反例、真实执行路径和未解决未知项,不实施修复。

持续实施到完成

/goal 完成 `<结果>`。约束:遵循已加载的 Codex Subagent Dispatch;级别 L<n>,派发前报告账本;只对具体发现做修复和重新验证。验证:`<命令>` 通过;界面类结果在 `<里程碑>` 给我截图确认。检查点:每完成 `<里程碑>` 写一行进度并停下汇报。遇到需要我授权的步骤时停止并报告该步骤。最终报告证据、改动文件、失败的检查、剩余风险和未用预算。不要暂存、提交或推送。

Codex 的 goal 只定义结果、约束和验证,文档里没有轮数上限和授权字段,"停止并报告"是对模型的要求,不是机制保证。Long-running work

验证命令

先用 codex doctor 做零 token 的健康检查:它报告版本、解析后的模型、config.toml 是否解析成功、登录状态、MCP、沙箱后端和审批策略。0.162.1 的 doctor 会对未知键给出 "<key> is ignored" 提示,以这一行为准;codex doctor --strict-config 报参数错误,codex --strict-config doctor 能运行但输出相同,不会让 doctor 失败。要让未知键直接报错,用 codex exec --strict-config 或 codex app-server --strict-config。doctor 只看配置层,看不到会话里的实时权限覆盖。

Windows PowerShell

codex --version
codex doctor
codex features list
codex -c windows.sandbox=mxc sandbox --include-managed-config --permission-profile :workspace -- cmd.exe /d /c echo MXC_OK

在已知项目目录做一次只读派发烟测(会使用模型):

codex exec --strict-config --sandbox read-only -c approval_policy=never --model gpt-6.1-sol -c model_reasoning_effort=low --cd "X:\Projects\my-project" "Read-only role smoke test. This is an explicit request to spawn exactly one subagent: agent_type recon, model gpt-6-luna, reasoning_effort low, fork_turns none. Its task: report the name field in package.json with the line number. Report the agent_type, requested model and effort, and the answer. Do not modify files."

不要加 --ephemeral:它不保存 rollout,之后就无法从子线程的 session_meta 和 turn_context 核对实际角色、模型、effort 与权限。烟测前后各检查一次项目状态:

git -C "X:\Projects\my-project" status --short --branch
git -C "X:\Projects\my-project" diff

macOS / Linux

codex --version
codex doctor
codex features list
codex exec --strict-config --sandbox read-only \
  -c approval_policy=never --model gpt-6.1-sol -c model_reasoning_effort=low \
  --cd "/path/to/project" \
  "Read-only role smoke test. This is an explicit request to spawn exactly one subagent: agent_type recon, model gpt-6-luna, reasoning_effort low, fork_turns none. Its task: report the name field in package.json with the line number. Report the agent_type, requested model and effort, and the answer. Do not modify files."
git -C "/path/to/project" status --short --branch
git -C "/path/to/project" diff

需要证明新进程解析后的 [agents] 值时,启动由验收客户端持有标准输入输出的 codex app-server --listen stdio:// --strict-config,按当前版本 app-server generate-json-schema 的协议初始化,再调用 config/read(带目标 cwd)。0.157.0 起符合条件的交互会话会自动启动并连上共享的后台 app-server,要隔离它就用顶层的 codex --no-daemon(codex exec 没有这个参数)。App Server

常见问题

14.1 Codex 每个需求都派子代理

先检查实际加载的 AGENTS.md 和技能里有没有"必须委派""所有代码交给子代理"这类句子,文档写明这类指令会触发委派。本文第 6 节的规则把直接完成设为默认,并列出不派发的任务。仍然过度派发时:

  • 在提示里写"自己改,不要派发子代理",或给出级别(如"L0")。
  • 检查会话是否以 ultra 运行,ultra 会主动委派;日常任务用默认的 medium,难题用 xhigh。
  • 检查技能或计划模板是否规定了子代理流程;规则写明它们不能覆盖派发规则。

14.2 修改配置后当前对话没有变化

config.toml 与角色文件的改动对新会话生效;全局指令从 0.156.0 起可能在下一次模型请求时刷新,但验收以新会话为准。插件工具、skills 和 hooks 会在运行中的会话内刷新,hooks 修改后要重新信任。

14.3 AGENTS.md 内容被截断

检查实际加载的指令链是否达到默认 32 KiB,是否有 override 遮蔽目标文件。删除重复规则;只有确有必要时才调整 project_doc_max_bytes。

14.4 自定义 Agent 没有出现或没有生效

  • 文件是否位于实际 CODEX_HOME/agents,是否开启了新会话。
  • TOML 是否包含三个必需字段,name 是否唯一。
  • 派发是否写了 agent_type:不写角色时,角色文件里的 developer_instructions 和 sandbox_mode 都不会应用。
  • 用 rollout 的 session_meta.agent_role 确认实际角色,不凭模型的自述判断。

14.5 子代理的实际模型与 effort

先查 0.162.0 起 subAgentActivity 的 started 记录里的解析值,再查子线程 rollout 的 turn_context。两处都没有时,核对角色文件的固定值和派发调用的显式值,把运行时值标为"未直接观测"。

14.6 agent thread limit reached

这个错误表示打开的子代理线程达到上限,不表示同时有同样数量的代理在执行。本机自上限改为 6 后没有再出现。出现时:

  1. 用 list_agents 刷新清单,核对有效上限。
  2. 找角色、模型、effort 和文件所有权匹配的线程,用 followup_task 复用;保持审查独立。
  3. 以一次成功的派发确认容量恢复。
  4. 不要循环重试、降低模型或跳过必需的审查。修改过上限时,在未连接后台 app-server 的新进程中核对有效值。

14.7 模型满载、断流或额度耗尽

HTTP 和流中断会先由 Codex 自动重试;这些重试失败,或者遇到满载、额度耗尽,当前轮次就以 Selected model is at capacity、stream disconnected 或 usage_limit_exceeded 结束。处理顺序:

  1. 子代理失败:根代理告知用户,在预授权的后备模型上从最后完成的步骤重派一次(gpt-6-sol 与 gpt-6.1-sol 互为后备)。
  2. 仍失败或没有后备:改为根代理直接做,或缩小、串行任务,或停下并报告续跑点。
  3. 根代理自己的轮次失败:输入 /model,在选择器里换到 gpt-6-sol 或 gpt-6.1-sol,再让它从最后一条进度行续跑。
  4. 额度耗尽:停止派发,按错误里的重置时间等待,或在用量面板购买积分。

不要循环重试,不要在后备对之外静默换到更便宜的模型。

14.8 界面类任务反复返工

本地测试和门禁通过不等于用户验收。界面、交互手感、生成图片这类任务,让根代理在第一个可运行的里程碑停下给截图或运行步骤;同一验收项连续两轮没有可量化的进展就停下,列出证据、试过的办法和两三个选项。

回滚

按部署前保存的本机恢复材料逐项撤回:

  1. 停止新派发。
  2. 三个根键、五个 [agents] 键、[windows] sandbox 和删除的 max_threads,按部署前记录的存在性和值恢复:原本存在的恢复原值,本次新增的删除。
  3. 恢复全局指令文件中相关章节的原内容,只删除本次新增章节。
  4. 删除本次新建的五个 Agent 文件,恢复被删除的旧版文件。
  5. 部署后这些位置又有其他修改时,先列出差异,不用整份旧备份覆盖后续工作。保留凭据、MCP、plugin、hook 和项目配置。
  6. 按第 13 节验证恢复后的配置与指令加载,报告未恢复项。

安全检查清单

[ ] 已确认真实 CODEX_HOME 并记录 Codex 版本
[ ] 没有打印或复制任何密钥,没有整体覆盖 config.toml
[ ] 已在本机记录相关键、章节与文件的原始状态
[ ] model、model_reasoning_effort、model_verbosity 位于 TOML 根级
[ ] [agents] 只有一个,且没有遗留的 max_threads
[ ] Windows 上 MXC 探针通过后才设置 [windows] sandbox = "mxc"
[ ] Writing Style、Execution and Verification、Codex Subagent Dispatch 各只有一个
[ ] 五个 Agent 文件均包含 developer_instructions;implementer、qa、reviewer 不固定 model 和 effort,recon 固定 model,astra_reviewer 固定 model 和 effort
[ ] [agents] 默认子代理为 gpt-6-sol / high
[ ] 旧版五个角色文件已按归属备份后删除或保留并报告
[ ] codex doctor 显示 config.toml parse ok,没有 "is ignored"
[ ] 只读烟测的子线程 rollout 显示 recon 为 gpt-6-luna、qa 为派发指定的 gpt-6.1-sol,effort 与派发一致
[ ] 烟测前后 git status 与 diff 一致
[ ] 已核对实际指令链、覆盖来源和大小
[ ] 已说明会话实际权限与只读角色的关系
[ ] 没有修改项目代码,没有暂存、提交或推送

部署后的工作流

User request
  ↓
Root (gpt-6.1-sol) classifies the level
  ├─ L0: no-spawn list or a small fix → root does it and runs the targeted check → done
  └─ L1+: report the ledger at L2+, name a reason for each spawn
        ↓
     Optional recon for a specific evidence gap (Luna)
        ↓
     implementer (gpt-6-sol) for a large or isolated change; visible checkpoint first for UI work
        ↓
     Root inspects the diff and runs targeted checks
        ↓
     reviewer (gpt-6.1-sol) for high-risk or cross-module diffs; qa (gpt-6-sol) for long, parallel, or device evidence
        ↓
     On capacity or stream failure: tell the user, respawn once on the fallback model, then the degradation ladder
        ↓
     astra_reviewer once, at L3+, for one named high-risk issue
        ↓
     Exact repair through followup_task; a second review uses a fresh reviewer
        ↓
     Root accepts against the criteria
        ↓
     Commit or push only when explicitly authorized

把第 8 节的 Prompt 连同附件发给目标电脑上的 Codex,即可开始兼容性核对与增量部署。只有配置加载、角色烟测和实际任务验收都有证据时,才把该设备标为部署完成。

自建 API 封装时,哪些能力属于运行时

前文配置的是 Codex 客户端。如果你还维护基于 Responses API 的自建执行器,GPT-6 家族的三个能力需要运行时代码配合:

能力接入位置与限制对执行器的影响
异步工具调用在 function 或 custom tool 定义上设置 async: true;不用于托管内置工具,也不与 Programmatic Tool Calling 混用应用仍负责执行任务,并用原 call_id 回传结果;模型可继续处理独立工作。文档
执行中追加要求Responses WebSocket 的 response.steer接受事件只表示更新入队;它不会撤销已执行操作或取消已启动工具,执行器要继续处理事件和工具结果。文档
保留缓存前缀并调整推理强度在相邻响应之间加入 configuration_update,保持请求级 reasoning.effort 不变;限 standard、single-agent 请求为后续响应调整 effort,不能当成多代理编排的通用配置项。各模型支持的档位不同,以模型页的兼容性说明为准。文档

这些是 API 协议能力,不能写成 config.toml 开关来启用,也不等于 Codex 的本地子代理调度。GPT-6.1 Sol 另外支持 Responses API 的 Multi-agent beta。迁移自建调用链时,工具调用使用 Responses API,并检查旧请求中的 temperature、top_p、top_logprobs 等不支持参数。迁移说明

附录:部署与复核记录

以下记录保留当时的版本、观察与结论,不作为当前运行时证明。被后续证据推翻的结论在原处注明。

A. 2026-09-02 至 09-04:Sol 主线程版

适用范围是 CLI 0.152.1、Sol 主线程:

  • 增量配置 ~/.codex 的 [agents],创建五个角色 TOML,并合并全局调度规则。
  • 新会话加载成功;Luna 烟测在一个 Android 项目里定位到 settings.gradle.kts:1 的 rootProject.name,项目文件没有变化。当时只观察到角色类型和请求的模型、effort。
  • 全局与该项目根指令合计 16,393 字节。
  • 2026-09-04 增加 Writing Style。

当时把 codex --strict-config --version 的成功返回写成"解析成功",这项结论已撤回:版本输出不足以证明配置加载或角色激活。

B. 2026-09-05:离线反例实验(CLI 0.153.4)

用临时、无凭据的 Codex Home 做的实验:

临时配置与命令观察结果能证明什么
未知根键 + codex --strict-config --version退出码 0,仅输出版本不能据此验收配置
未知根键 + codex --strict-config features list退出码 1,提示该子命令不支持 strict-config不能作为替代校验命令
未知根键 + codex --strict-config exec --ephemeral --sandbox read-only,不提供 Prompt退出码 1,报告 unknown configuration fieldexec 启动会读取并校验主配置

2026-10-13 在 0.162.1 上复测:普通 codex doctor 已能对未知键给出 "is ignored" 提示,doctor 可以作为零 token 的第一道检查。

C. 2026-09-08:子代理容量修正(CLI 0.153.4)

旧桌面任务在上限为 2 时连续 7 次新建线程返回 agent thread limit reached,最近两个子代理显示 completed 后仍无法新建,随后通过 followup_task 复用 reviewer 继续工作。上限改为 6 后,新 app-server 进程的 config/read 读到 max_concurrent_threads_per_session = 6。

后续证据:09-09 之后的会话在上限 6 下单个根任务最多派出 36 个线程、没有调用关闭工具,也没有再出现上限错误。"完成的线程不释放槽位"只适用于当时的版本和上限,不再作为现行规则的前提。

D. 2026-09-14:0.154.0 全篇复核

按当天的官方文档 .md 版本,用三个读取器和一个对抗式复核者核对全文,70 条发现中 57 条确认。主要改动:

  • 删除"通常最多同时运行两个子代理",改为独立子代理并行到线程上限、按文件所有权串行写入。
  • 本机 sandbox_mode 从 danger-full-access 改为 workspace-write;[windows] sandbox 从 elevated 改为 unelevated,因为 doctor 报告提权沙箱 provisioning 失败。
  • 清理已移除的 features.js_repl、无对应插件的 plugin 项、temp 目录 trust 条目和一次性 rules;git add、git commit 的放行规则保留。
  • config.toml 里的两把 MCP key 按用户决定保持原样。

当时据 CLI 文档推断桌面会话也有 close_agent,09-28 发现这是把文档接口误当成实际接口;10-13 进一步确认工具面由模型的 multi_agent_version 决定。

E. 2026-09-28:GPT-6 角色配置与本机加载烟测

09-27 用户要求子代理全部使用 GPT-6,角色改为 Astra 根代理、Sol 实现与 QA、Astra 审查、Luna 侦察。09-28 用 0.157.1 启动独立 stdio app-server:config/read 返回 Astra / xhigh、线程上限 6;显式请求只读临时线程后,thread/start 返回 readOnly 与全局和项目两份 AGENTS.md 来源;按 Luna / medium 派发的子任务返回 package.json 中的名称 ds-docs。

F. 2026-10-13:0.162.1 复核与派发策略重写

依据:9 月以来 463 个 rollout 的派发统计(见配套复盘)、0.155.0 到 0.162.1 的发布说明、当天下载的官方文档,以及一轮六路研究加两路对抗核验(72 条发现,54 条进入核验)。

本机变化:

  • 根代理此前已改为 gpt-6.1-sol / xhigh;approval_policy 在 config.toml 中为 on-request,修改时间和原因没有记录。
  • 角色重组为 implementer、qa、reviewer(均为 gpt-6.1-sol)、astra_reviewer(gpt-6-astra / high)、recon(gpt-6-luna);前四个只固定模型。旧文件备份在本机 ~/.codex/backups/dispatch-61sol-20261013/。
  • AGENTS.md 的派发一节重写:直接完成为默认、不派发清单、级别与积分权重、Astra 闸门、agent_type 与 fork_turns = "none" 必填、按原因升档、对抗式审查、v2 工具名、权限继承的实际后果。
  • MXC 探针输出 MXC_OK,[windows] sandbox 从 unelevated 改为 mxc;doctor 显示 sandbox backend 为 mxc、config.toml parse ok。
  • 只读烟测:codex exec 以只读权限派发 recon,子线程 rollout 显示 agent_role = recon、gpt-6-luna、effort low、read-only,项目 git 状态无变化。

文章变化:正文改为现行规范;worktrees 已是稳定功能(0.156.0 起默认开启);daemon 对符合条件的交互会话默认自动启动(0.157.0);Fast 与 Ultrafast 的说明、fork_turns 语义、doctor 行为和工具面成因按 0.162.1 更新。

未验证:PreToolUse hook 在 v2 派发路径上是否触发;gpt-6.1-sol 与 gpt-6-sol、Astra 审查之间的质量差异;新规则下过度派发是否下降,需要再积累一段会话记录。

G. 2026-10-13 第二轮:结果复盘与算力波动

依据:对 09-14 以来 39 个根任务的逐个结果判读、外部事故记录与官方机制核对、本机 8.5 万次模型响应的延迟统计,以及一次根代理对照实验(见 1.6)。数据见配套复盘。

本机变化:

  • implementer、qa 改回 gpt-6-sol,reviewer 保持 gpt-6.1-sol;三个角色文件去掉 model,由派发给出;gpt-6-sol 与 gpt-6.1-sol 由用户预授权互为后备。
  • [agents] 默认子代理从 gpt-6-luna / medium 改为 gpt-6-sol / high。
  • 实现者权重变为 1.6,预算调整为 L1 2、L2 4、L3 14、L4 20。
  • Execution and Verification 增加可见检查点、两轮返工上限、进度行、遇到没有审批提示的阻塞时立即停下、无关任务开新线程;派发一节增加满载、断流和额度耗尽的处理。
  • 旧文件备份在本机 ~/.codex/backups/dispatch-fallback-20261013/;复盘脚本保存在 ~/.codex/scripts/。
  • 按对照实验把根代理默认 effort 从 xhigh 改为 medium;派发一节增加一条:L3 及以上的任务提醒用户可用 /model 切到 xhigh,根代理因推理深度不够而失败时停下请用户切换。改动前的文件备份在本机 ~/.codex/backups/root-medium-20261013/。
  • 烟测:根代理按派发值让 qa 在 gpt-6.1-sol、reviewer 在 gpt-6-sol 上运行,两个子线程都是只读,项目 git 状态无变化;doctor 显示 config.toml parse ok、sandbox backend 为 mxc。

未验证:后备重派在真实满载时的表现;对照实验只有一个任务,需要换一天重跑;gpt-6.1-sol 与 gpt-6-sol 作为实现者的质量差异。