委派与子 Agent

delegate_task 工具允许 AI 将子任务交给独立的子 Agent 执行。子 Agent 拥有隔离的上下文和执行环境,完成后将结果汇报给父 Agent。


什么是委派

当主 Agent 面对复杂任务时,可以将子任务委派给子 Agent:


两种委派模式

同步委派(默认)

父 Agent 发出委派后等待子 Agent 完成:

后台委派

设置 background=true 时,父 Agent 立即获得一个委派 ID 并继续工作:


两种角色

角色说明能力
leaf(默认)专注的执行者不能再委派、不能调用 clarify/memory/send_message
orchestrator编排者保留 delegate_task,可以继续拆分子任务

Orchestrator 角色受以下配置限制:


批量并行委派

delegate_task 支持批量模式:传入 tasks: [...] 列表,每个任务获得独立的子 Agent 并发执行。

并发数量受 delegation.max_concurrent_children 限制(默认 3)。


Actor 继承

子 Agent 的 Actor 身份继承自父 Agent:

这确保了多层委派下数据归属的一致性。


执行预算

子 Agent 共享父 Agent 的迭代预算(max_iterations):


配置项

配置默认值说明
delegation.max_concurrent_children3最大并发子 Agent 数
delegation.max_spawn_depth2最大委派深度
delegation.child_timeout_seconds—子 Agent 超时时间
delegation.orchestrator_enabledtrue是否允许 orchestrator 角色
delegation.subagent_auto_approve—子 Agent 是否自动批准操作
delegation.inherit_mcp_toolsets—子 Agent 是否继承 MCP 工具

注意事项


相关文档