# 子 Agent - Codex 来源: https://developers.openai.ac.cn/codex/subagents Codex 可以通过并行生成专门的代理来运行子代理工作流。 ## 可用性 - 默认启用子代理工作流 - 仅当明确要求时才会生成子代理 - 每个子代理消耗更多 Token ## 管理子代理 - `/agent`: 在活跃线程之间切换 - 可直接要求 Codex 指导、停止或关闭子代理 ## 审批与沙盒控制 - 子代理继承当前的沙盒策略 - 审批请求会显示源线程标签 ## 自定义代理 ### 内置代理 - `default`: 通用后备 - `worker`: 执行型代理(实现和修复) - `explorer`: 以读取为主的代码库探索 ### 创建自定义代理 在 `~/.codex/agents/`(个人)或 `.codex/agents/`(项目级)下添加 TOML 文件。 必需字段: `name`, `description`, `developer_instructions` 可选: `nickname_candidates`, `model`, `model_reasoning_effort`, `sandbox_mode`, `mcp_servers`, `skills.config` ### 全局设置 ``` [agents] max_threads = 6 # 并发代理上限 max_depth = 1 # 嵌套深度 ``` ### 示例: PR 审查 `.codex/agents/pr-explorer.toml`: ``` name = "pr_explorer" description = "Read-only codebase explorer for gathering evidence" model = "gpt-5.3-codex-spark" sandbox_mode = "read-only" developer_instructions = "Stay in exploration mode..." ``` `.codex/agents/reviewer.toml`: ``` name = "reviewer" description = "PR reviewer focused on correctness, security, missing tests" model = "gpt-5.4" model_reasoning_effort = "high" sandbox_mode = "read-only" developer_instructions = "Review code like an owner..." ```