Collaboration Mode 和 Multi-Agent Mode 不是同一个开关。前者定义当前交互工作流及其 Developer Instructions;后者约束是否、何时以及怎样派生子 Agent。两者分别作为 World State section 持久化,避免模式更新必须重建整段基础指令。
Collaboration Mode 是 Turn 工作合同
TurnContext 从当前配置解析 mode、model、reasoning effort 与 mode-specific Developer Instructions。CollaborationModeState 将模型可见合同渲染为带边界片段,并比较当前 Snapshot 与上一份 Snapshot。
def build_collaboration_mode_state(turn):
return CollaborationModeState(
mode=turn.collaboration_mode.kind,
instructions=turn.collaboration_mode.developer_instructions,
)
当模式说明为空或状态不变时不重复发送;从旧模式切换时,新片段明确覆盖旧合同。Review 等 Task 可以派生自己的 TurnContext,并携带父 Turn 的协作说明,而不是修改全局字符串。
Multi-Agent Mode 单独控制代理协作
MultiAgentModeState 依据版本、会话来源和当前允许的协作方式生成说明。初始上下文中还有一条通用 usage hint;源码特意把当前 Multi-Agent Mode 片段放在 hint 之后,使更具体的现行模式能够覆盖通用建议。
def compile_multi_agent_context(turn, session_source):
items = []
if hint := usage_hint(turn, session_source):
items.append(DeveloperMessage(hint))
if mode := render_current_multi_agent_mode(turn):
items.append(mode) # later and more specific
return items
模式提示不是执行权限
和 Permissions 类似,Multi-Agent Mode 指示模型如何规划,真正的 spawn/send/wait 能力由工具注册与 AgentControl 校验。提示允许而工具缺失会造成不可执行计划;工具存在而提示禁止时 Runtime 仍不能把安全寄托在模型自律上。
测试重点是四种边界:初始顺序、无变化去重、模式切换的替换文本、子 Agent/特殊 SessionSource 的差异。
源码与测试锚点
codex-rs/core/src/context/world_state/collaboration_mode.rs。codex-rs/core/src/context/world_state/multi_agent_mode.rs。codex-rs/core/src/session/turn_context.rs:模式冻结。- 对应
*_tests.rs与 snapshot:初始、更新和来源分支。
评论
登录后即可评论