进阶 B · 多 Agent 的分工与成本Advanced B · Multi-Agent Work and Cost.
完整配置内置与自定义角色, 用多路探索、单路实现和独立复核完成一件任务。区分子线程与隔离工作区, 计算全部 agent 的 token。Configure built-in and custom roles for parallel exploration, one implementation owner, and independent review. Separate child threads from isolated workspaces and count every agent's tokens.
一次整理三个独立资料夹, 可以分给三个只读助手;一封私人邮件, 通常一个对话就够。多 Agent 的价值来自可独立推进的工作, 主线程仍负责需求、取舍与最终验收。本附录给需要维护个人工具的读者一套完整配置, 并用一个不会碰真实文件的练习展示分工。Three independent source folders may suit three read-only helpers; one personal email usually needs only one chat. Multi-agent value comes from independent work. The parent still owns requirements, decisions, and acceptance. This appendix provides a complete setup for maintaining a personal tool and a bounded exercise that never touches real files.
— I
先分清三种并行Distinguish Three Kinds of Parallel Work.
任务Task
选什么Choose
关键边界Boundary
同一目标的独立调查、清点、测试Independent investigation, inventory, or tests for one goal
同一主线程下的 subagentsSubagents under one parent
主线程汇总;子线程不自动隔离文件Parent consolidates; files are not automatically isolated
多个方案同时修改代码Several implementations editing code
独立 worktreeSeparate worktrees
隔离检出;仍要集成与验收Isolate checkouts; still integrate and verify
离机运行, 返回远端结果Work that must run away from your computer
独立 Cloud taskSeparate Cloud tasks
核对远端材料、权限与保存位置Verify remote inputs, access, and saved results
本书默认用「多路读、单路写、独立复核」。读文件也有成本, 测试也可能写缓存或共用数据库:给每个调查员不同范围, 给测试独立输出目录, 不让并行任务共享可变测试数据。若拆分后每一步都要等上一位, 保持单 Agent 往往更简单。This book defaults to several readers, one writer, and an independent reviewer. Reads still cost tokens; tests may write caches or share databases. Assign distinct scopes, separate test output directories, and avoid shared mutable fixtures. If every step must wait for the previous one, one agent is often simpler.内置 default 负责通用工作, worker 偏实现与修复, explorer 偏读密集探索。只有反复出现、需要不同工具或判断标准的工作才值得自定义。当前 Codex 默认支持子 Agent;Work 的可用性以及 Ultra 主动委派取决于账号和模型, 截至 2026-10-09。1注 1Note 1OpenAI · Subagents。角色、委派入口、自定义文件与继承规则;截至 2026-10-09。OpenAI · Subagents. Roles, invocation paths, custom files, and inheritance rules; checked 2026-10-09.Built-in default handles general work, worker focuses on implementation, and explorer on read-heavy exploration. Customize repeated work that needs distinct tools or criteria. Current Codex enables subagents by default; Work availability and Ultra's proactive delegation depend on account and model as of 2026-10-09.1注 1Note 1OpenAI · Subagents。角色、委派入口、自定义文件与继承规则;截至 2026-10-09。OpenAI · Subagents. Roles, invocation paths, custom files, and inheritance rules; checked 2026-10-09.
— II
一套能放进项目的配置A Complete Project Configuration.
下载 练习说明、config.toml 与三份角色文件。个人角色目录是 ~/.codex/agents/, 项目角色目录是 .codex/agents/;本例使用后者。已有配置要合并, 不覆盖。信任项目之前先读这些文件。3注 3Note 3OpenAI · Config basics。项目级配置需受信, 同时受上层强制要求约束;截至 2026-10-09。OpenAI · Config basics. Project configuration requires trust and remains constrained by enforced requirements; checked 2026-10-09.Download the exercise guide, config.toml, and three role files. Personal roles live in ~/.codex/agents/, project roles in .codex/agents/; this example uses the latter. Merge existing settings rather than overwriting them. Read the files before trusting the project.3注 3Note 3OpenAI · Config basics。项目级配置需受信, 同时受上层强制要求约束;截至 2026-10-09。OpenAI · Config basics. Project configuration requires trust and remains constrained by enforced requirements; checked 2026-10-09.
这是截至 2026-10-09 的配置快照。enabled 是多 Agent 工具开关;max_concurrent_threads_per_session 限制同时打开的子线程, 不含主线程, schema 要求至少 1, 不写则使用客户端默认。两个 default_subagent_* 为默认模型和力度。interrupt_message 控制中断时是否向模型上下文加入中断消息。前后两个布尔键默认 true。旧 max_threads 是兼容名, 新配置用长键。2注 2Note 2OpenAI · Configuration Reference / config-schema.json。本轮实际读取 JSON schema, 核对 agents 的五个主要键及类型;截至 2026-10-09。OpenAI · Configuration Reference / config-schema.json. The JSON schema was read to check the five principal agents keys and types on 2026-10-09.This is a configuration snapshot as of 2026-10-09. enabled controls multi-agent tools. max_concurrent_threads_per_session caps open child threads, excluding the parent; the schema requires at least 1, and omission uses the client default. The default_subagent_* fields select default model and effort. interrupt_message controls insertion of interruption messages into context. Both booleans default to true. max_threads is a compatibility alias; use the longer key in new files.2注 2Note 2OpenAI · Configuration Reference / config-schema.json。本轮实际读取 JSON schema, 核对 agents 的五个主要键及类型;截至 2026-10-09。OpenAI · Configuration Reference / config-schema.json. The JSON schema was read to check the five principal agents keys and types on 2026-10-09.
name = "repo_explorer"description = "Read-only evidence gathering before a change."model = "gpt-6-luna"model_reasoning_effort = "high"sandbox_mode = "read-only"developer_instructions = """Inspect only the assigned scope. Do not edit or install packages.Return findings, file locations, checks run, and unknowns.Return a short summary, not raw logs."""
name = "implementation_worker"description = "Implement one approved and bounded change."model = "gpt-6.1-sol"model_reasoning_effort = "high"sandbox_mode = "workspace-write"developer_instructions = """Edit only assigned files. Preserve unrelated changes.Do not commit, push, publish, install packages, or rename real files.Run relevant tests. Return changes, commands, exit status, and risks."""
name = "reviewer"description = "Independent read-only acceptance."model = "gpt-6.1-sol"model_reasoning_effort = "high"sandbox_mode = "read-only"developer_instructions = """Review the actual diff against acceptance criteria. Do not edit.Report actionable findings with file locations and reproduction.If none are found, say so and list what remains unverified."""
保存到 .codex/agents/;文件可直接下载Save under .codex/agents/; files are also downloadable
三份完整下载:explorer、worker、reviewer。每份至少有 name、description、developer_instructions;同名会覆盖内置角色, 所以本例不叫 explorer 或 worker。模型是示例选择, 需账号实际支持;没有 Sol 时换可用模型及它支持的力度, 不以升级订阅作为练习前提。Complete downloads: explorer, worker, and reviewer. Each requires name, description, and developer_instructions. Matching a built-in name shadows that role, so these avoid explorer and worker. Models are example choices requiring account access; substitute an available model and supported effort rather than treating an upgrade as a prerequisite.
模型与力度先分别按「显式 spawn 值 → [agents] 默认 → 父线程」解析, 再应用自定义文件。文件显式写的 model / effort 优先。若 spawn 或默认只指定新模型而未指定力度, 用新模型默认力度;但自定义文件只写 model 时会保留此前解析出的力度。因此本例把二者一起写。1注 1Note 1OpenAI · Subagents。角色、委派入口、自定义文件与继承规则;截至 2026-10-09。OpenAI · Subagents. Roles, invocation paths, custom files, and inheritance rules; checked 2026-10-09.权限还要考虑父线程当前轮的运行时覆盖:只读角色文件不是不可突破的权限上限。委派前检查实际权限, prompt 也明确只读。Resolve model and effort from explicit spawn values, then [agents] defaults, then the parent; apply the custom file afterward. Its explicit model or effort wins. A model selected by spawn or defaults without an effort uses that model's default; a custom file setting only model retains the previously resolved effort. The example therefore sets both.1注 1Note 1OpenAI · Subagents。角色、委派入口、自定义文件与继承规则;截至 2026-10-09。OpenAI · Subagents. Roles, invocation paths, custom files, and inheritance rules; checked 2026-10-09. Current parent-turn runtime overrides also affect permissions: a read-only role file is not an immutable access ceiling. Check effective permissions before delegating and explicitly request read-only work.
#MCP 与 skill:按需增加, 不默认全接MCP and Skills: Add Only What Is Needed.
可选追加到某份角色文件;skill 路径必须改成实际绝对路径Optional additions to one role; replace the skill path with its real absolute path
本练习不需要外部工具, 上面是可选配置, 不是必填步骤。mcp_servers 配置工具连接, skills.config 按已安装 SKILL.md 的绝对路径启停。未写的会话设置继承父线程;追加一个 server 并不自动移除其他 server。对已有连接可设置对应 enabled = false, 但还要检查插件带来的工具和服务自身权限。5注 5Note 5OpenAI · Configuration Reference。skills.config、mcp_servers 与模型设置的配置面;截至 2026-10-09。OpenAI · Configuration Reference. Configuration surfaces for skills.config, mcp_servers, and model settings; checked 2026-10-09.本地只读沙箱不会自动撤销远端服务的写入能力。This exercise needs no external tools; these are optional additions. mcp_servers configures connections, and skills.config enables or disables an installed SKILL.md by absolute path. Omitted session settings inherit. Adding one server does not remove others; disable unwanted configured servers individually and also inspect plugin tools and service permissions.5注 5Note 5OpenAI · Configuration Reference。skills.config、mcp_servers 与模型设置的配置面;截至 2026-10-09。OpenAI · Configuration Reference. Configuration surfaces for skills.config, mcp_servers, and model settings; checked 2026-10-09. A local read-only sandbox does not revoke remote-service write access.
— III
四条入口, 各管一件事Four Paths with Different Jobs.
手动指派Explicit request
直接要求派几个 agent, 各查什么、何时等待、回什么摘要。先从这里练。Specify the number of agents, each scope, wait condition, and summary format. Start here.
/agent
CLI 中检查与切换子线程, 不是创建 agent 的命令。当前 codex agents 则浏览共享本地 daemon 上的会话, 两者别混淆。Inspect and switch child threads in the CLI; it is not a spawn command. The separate codex agents command browses sessions on the shared local daemon.
UltraUltra
符合资格的账号和模型可主动委派;其他力度明确提出要求。Ultra 是推理/委派选择, 与 Ultrafast 速度档是两回事。Eligible accounts and models can delegate proactively; at other levels ask explicitly. Ultra is a reasoning/delegation choice, distinct from Ultrafast speed.
AGENTS.md / skill
长期规则或当前触发的 skill 可要求委派。写清适用条件, 不让每个简单任务都启动团队。Durable project guidance or an activated skill can request delegation. Specify when it applies so simple tasks do not launch a team.
练习材料是 collision-key.mjs 和 对应测试:一个纯字符串函数, 当前只去前后空格并转小写。把它们放到新的练习目录, 按 README 放置配置, 运行 node --test collision-key.test.mjs。两条起始测试应通过, 但还没覆盖 Unicode 组合形式。整个练习不需要真实文件、网络、依赖安装或外部账号。The exercise contains collision-key.mjs and its tests: a pure string function that currently trims and lowercases. Put them in a fresh practice directory, follow the README for configuration, and run node --test collision-key.test.mjs. Two starter tests should pass, without covering Unicode composition. No real files, network, dependency installation, or external accounts are needed.
提示词PromptCodex · Subagents
请用多 Agent 完成 <有限任务>。两位 repo_explorer 并行只读查 <实现范围> 和 <测试范围>, 各回文件定位、结论、未知项。等两份结果后, 主线程定方案, 一个 implementation_worker 仅改 <文件清单>。再由 reviewer 对照 <验收条件> 检查实际 diff 并复跑检查。禁止 <动作>。等全部完成, 汇总证据、剩余风险和实际用量, 无法取得用量就写未测。Use subagents for <bounded task>. Two repo_explorer agents inspect <implementation> and <tests> read-only, returning locations, findings, and unknowns. Wait for both, choose a plan, and assign one implementation_worker to <allowed files>. Have reviewer inspect the actual diff against <acceptance criteria> and rerun checks. Prohibit <actions>. Wait for all results and report evidence, remaining risks, and actual usage, or mark usage unmeasured.
请用两位 repo_explorer 只读检查 collision-key.mjs 和 collision-key.test.mjs, 一位查实现, 一位查边界测试。等摘要齐全, 一个 implementation_worker 仅改这两个文件, 增加 NFC 规范化及回归测试。验收:café.txt 与 cafe\u0301.txt 的 key 相同;原空格和大小写测试仍过;空字符串输出空字符串;不同名字仍不同。由 reviewer 独立看 diff 并运行 node --test collision-key.test.mjs。不要安装包、改真实文件名、提交、推送或发数据。返回改动、检查证据和局限, 不要宣称它适用于所有文件系统。Use two repo_explorer agents to inspect collision-key.mjs and collision-key.test.mjs read-only: one implementation, one edge cases. After both summaries, one implementation_worker changes only those files to add NFC normalization and regression tests. Acceptance: café.txt and cafe\u0301.txt have equal keys; whitespace and case tests still pass; empty stays empty; distinct names remain distinct. Have reviewer independently inspect the diff and run node --test collision-key.test.mjs. Do not install packages, rename real files, commit, push, or send data. Return evidence and limitations without claiming universal filesystem behavior.
这里的 cafe\\u0301.txt 表示在测试代码中写 Unicode escape, 或明确使用分解形式的字符, 不是把反斜线字面量当文件名。验收要检查两种实际字符串。参考改法在下载说明里;先自己做, 再比较。第二位 reviewer 即使说通过, 你仍要看测试里是否真的有这两个字符串、命令退出码是否为零。Here cafe\\u0301.txt denotes a Unicode escape in test code, or an explicitly decomposed character, not a literal backslash filename. Verify the two actual strings. A reference change is in the download guide; try first, then compare. Even if the reviewer says it passed, inspect whether both strings are truly tested and the command exited successfully.
— V
把并行的账算在一起Count the Whole Parallel Run.
另有一条本轮真实执行的协作记录:主线程制作小工具章的改名预览器, 再让一个子 Agent 只读复核 HTML、测试与教学说明。它返回两个具体问题:选择含换行的非法文件名后, 旧名单仍能重新导出;IMG_10 排在 IMG_2 前面的字典序没有说清。主线程修正状态清理、补充排序说明和测试, 然后在浏览器重跑。复核者没有修改实现文件。A separate collaboration actually ran during this edition: the parent built the rename previewer, then assigned a child to read-only review of the HTML, tests, and instructions. It returned two concrete issues: after an invalid newline-containing file selection, the old list could still be exported again; and lexical ordering of IMG_10 before IMG_2 was not explained. The parent fixed state clearing, clarified sorting, added a test, and reran browser checks. The reviewer did not edit implementation files.这证明了本次「实现 → 独立复核 → 修正 → 重测」确实发生, 不证明上面的三份角色 TOML 已被客户端发现, 也不证明并行节省了多少时间或 credits。本轮未取得可归因到这次复核的用量数据。读者可以照着复制分工方式, 但不能把不同层次的验证合成一句「多 Agent 全部实测通过」。This verifies an actual implementation → independent review → correction → retest loop. It does not prove discovery of the three TOML roles above, or any time or credit savings. Usage attributable to that review was not measured. Reuse the division of work without collapsing distinct verification levels into a claim that all multi-agent behavior was tested.每位 agent 都会读上下文、调用工具、产生输出。要统计主线程、全部子线程和返工, 不能只看主线程最后一条回复。子线程返回「结论、来源、未决问题」, 原始日志留在自己的记录里, 可以减轻主线程重复读取的负担。成本公式见 长用章。4注 4Note 4OpenAI · Pricing。Standard credits token 费率, 与订阅内含额度分开理解;截至 2026-10-09。OpenAI · Pricing. Standard token credit rates must be distinguished from included subscription usage; checked 2026-10-09.Each agent reads context, calls tools, and produces output. Count the parent, every child, and rework, not merely the final parent response. Returning findings, sources, and unresolved questions while keeping raw logs in child records reduces repeated reading. The formula is in the cost chapter.4注 4Note 4OpenAI · Pricing。Standard credits token 费率, 与订阅内含额度分开理解;截至 2026-10-09。OpenAI · Pricing. Standard token credit rates must be distinguished from included subscription usage; checked 2026-10-09.举一个人为账本, 不当实测:每位 Luna 探索员使用 10,000 未缓存输入、2,000 输出 token, 两位共 0.10 credits;Sol 实现者用 20,000 输入、4,000 输出, 为 2.00;Sol reviewer 用 10,000 输入、2,000 输出, 为 1.00;主线程用 10,000 输入、1,000 输出, 为 0.75。合计 3.85 credits, 均按截至 2026-10-09 的 Standard 费率、无缓存与无额外计费工具计算。它不能推出订阅还剩几次, 也不能证明比单 Agent 便宜或更快。A synthetic ledger, not a measurement: each Luna explorer uses 10,000 uncached input and 2,000 output tokens; two cost 0.10 credits. A Sol implementer uses 20,000 input and 4,000 output, costing 2.00; a Sol reviewer uses 10,000 input and 2,000 output, costing 1.00; the parent uses 10,000 input and 1,000 output, costing 0.75. Total: 3.85 credits at Standard rates as of 2026-10-09, with no cache or separately billed tools. This predicts neither remaining subscription tasks nor savings or speedup against one agent.只有在同一组任务上, 记录相同验收标准下的单 Agent 与多 Agent 总用量、等待、返工, 才能判断值不值得保留。先限定并发和输出, 再考虑更轻模型;不把更多角色等同于更认真。Compare total usage, waiting, and rework on the same tasks with the same acceptance criteria before keeping a multi-agent workflow. Bound concurrency and output first, then consider lighter models. More roles do not by themselves make the work more careful.
分工要减少彼此等待, 验收要回到同一份证据.
Divide work to reduce waiting; reunite it around shared evidence.
SUBAGENTS · BOUNDED WORK
— 讨论Discussion
讨论Discussion.
评论区初始化中…Initializing comments…
01 / 01
没有匹配结果No matches.
换个关键词,或按 Esc 回到页面Try another keyword, or press Esc to return