字节笔记本
2026年2月20日
OpenAI Codex 多智能体配置完全指南
本文介绍 OpenAI Codex 的多智能体配置指南,详细讲解如何创建自定义 subagent 角色、配置模型和推理级别、设置权限和系统提示,以及如何使用 25 个预置的自定义角色。
什么是自定义多智能体角色
OpenAI Codex 在 0.102.0 版本中引入了全新的多智能体配置系统。自定义多智能体角色是用户定义的子代理,专为可重复任务设计。
Codex 原生提供三个内置角色:
| 角色 | 说明 |
|---|---|
| Default agent | 无定义角色,继承父代理的模型和推理能力 |
| Explorer agent | 运行在 5.1-Codex-Mini 上,负责探索任务 |
| Worker agent | 执行计划中的任务、修复或运行测试、重构代码,继承父代理配置 |
自定义角色的优势在于高度可配置,你可以精确控制每个子代理的行为和能力。
可配置选项
每个子代理都具有高度的可配置性:
- 模型和推理级别:如 Codex 5.3 Spark High、Codex 5.1 Mini Medium
- 作用范围:全局或项目级角色
- 系统提示:通过
developer_instructions定义 - 角色描述:控制何时调用该角色
- 权限设置:只读或读写权限
- 功能开关:内存、shell 访问等
- MCP 服务器:用户定义的 MCP 服务器
- ChatGPT 应用:Notion、Linear、Monday 等连接器
- 个性化设置:详细程度和个性风格
隐藏功能:线程数量配置
官方文档提到最多只能启动 6 个并行代理,但实际上你可以配置任意数量的线程。
在全局 config.toml 中配置:
[agents]
max_threads = 12注意:设置过多线程可能导致 429 错误,如遇问题请减少并行线程数。
项目级 vs 全局级配置
配置文件采用层级结构,首先从全局 ~/.codex 目录加载,然后可以在项目级别加载额外配置来补充或覆盖全局设置。
这意味着你可以在单个仓库甚至子文件夹中定义特定的代理角色。例如,在大型 monorepo 中为移动应用定义专门的审查代理:
$HOME/repo/mobile-app/.codex/config.toml
配置步骤
1. 创建 config.toml
在 Codex 文件夹(全局或项目根目录/子文件夹)中添加角色条目:
[agents.security_auditor]
description = "Finds auth, injection, and secrets risks."
config_file = "agents/security_auditor.toml"
[agents.performance]
description = "Optimizes latency, throughput, and resource usage."
config_file = "agents/performance.toml"
[agents.backend_arch]
description = "Designs backend modules, boundaries, and data flow."
config_file = "agents/backend_arch.toml"
[agents.product_analyst]
description = "Turns product goals into clear technical requirements."
config_file = "agents/product_analyst.toml"2. 创建角色定义文件
在 .codex/agents/ 目录中创建角色配置文件:
# .codex/agents/your-role_config.toml
# 模型 / 推理 / 风格
model = "gpt-5.3-codex"
model_reasoning_effort = "high"
model_reasoning_summary = "detailed"
model_verbosity = "high"
personality = "pragmatic"
# 核心行为
developer_instructions = """
You are a senior Product Analyst focused on turning ambiguous product goals into executable, testable technical requirements.
Your job on each task is to:
- Clarify the user goal and business outcome.
- Surface assumptions and unknowns explicitly.
- Define scope boundaries so implementation does not drift.
- Present concrete tradeoffs with recommendations.
- Produce acceptance criteria engineers and QA can execute directly.
Operating rules:
- Do not jump to implementation details before clarifying product intent.
- If requirements are ambiguous, state assumptions and propose 1-2 viable interpretations.
- Prefer concise, decision-ready output over long narrative.
- Call out risks, dependencies, and sequencing constraints early.
- Separate must-have requirements from nice-to-have enhancements.
- Include non-goals to prevent scope creep.
- If data is missing, propose the minimum instrumentation needed to decide.
"""
# 权限 / 沙盒
sandbox_mode = "workspace-write"
[sandbox_workspace_write]
network_access = true
writable_roots = ["/path/to/repo/"]
# 网页搜索模式
web_search = "cached"
# 功能开关
[features]
memory_tool = false
shell_tool = true
# MCP 服务器
[mcp_servers.linear]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-linear"]
env_vars = ["LINEAR_API_KEY"]
enabled = true
required = false
# 应用连接器
[apps.notion]
enabled = true
[apps.monday]
enabled = false大多数情况下,只需设置模型、推理级别和 developer_instructions(角色提示)即可。未定义的值将继承自父代理。
技巧:在子代理中使用 Skills
你可以从子代理调用 skills,也可以从 skills 调用子代理。
前端架构代理示例:
# config.toml
[agents.frontend_arch]
description = "Designs scalable frontend architecture and UX consistency."
config_file = "agents/frontend_arch.toml"
# frontend_arch.toml
model = "gpt-5.3-codex"
model_reasoning_effort = "high"
model_reasoning_summary = "detailed"
developer_instructions = """
- Use the $frontend-design skill for UI/UX work.
- Build with a mobile-first approach
- Build production-grade, responsive interfaces with clear visual direction.
- Prioritize accessibility, performance, and maintainable component structure.
"""使用 Spark 作为子代理
使用 5.3 Codex High 作为编排代理,Spark 作为执行子代理:
[agents.sparky]
config_file = "agents/sparky.toml"
description = """Use for executing implementation tasks from a structured plan."""如何调用代理
调用代理非常简单,使用自然语言即可:
"Use Sparky to implement plan.md. Work in a loop until all tasks are complete."
通过良好的描述,Codex 会根据当前情况自动判断何时使用该代理。如需确保调用特定代理,最好在提示中明确指定。
25 个预置自定义角色
作者提供了 25 个自定义多智能体角色,可直接导入使用:
- security_auditor - 发现认证、注入和密钥风险
- performance - 优化延迟、吞吐量和资源使用
- backend_arch - 设计后端模块、边界和数据流
- product_analyst - 将产品目标转化为清晰的技术需求
- frontend_arch - 设计可扩展的前端架构和 UX 一致性
- sparky - 执行结构化计划中的实现任务
(其余角色可在作者的 GitHub 仓库中获取完整配置)
下一步
本系列第二部分将涵盖:
- 何时使用子代理 vs 在主会话中完成任务
- 使用 Spark 进行并行实现的编排策略
- 如何构建子代理可实际执行的计划文件
- 从自定义角色获得最佳结果的提示模式
总结
OpenAI Codex 的自定义多智能体角色为 AI 辅助开发带来了全新的灵活性。通过精细配置模型、推理级别、权限和系统提示,你可以创建专门化的子代理来处理特定任务,从而大幅提升开发效率。
作者提供的 25 个预置角色是一个很好的起点,你可以根据项目需求进行调整或创建全新的角色。
来源: Twitter/X @LLMJunky 发布时间: 2026年2月19日 作者: Will (am.will)