Agent 调用参数与返回
选择独立 subagent 或 fork,控制前后台与已有 worktree 生命周期。
agent 用于委派完整多步骤任务。具体可用类型由 /agents 和配置决定,官方示例中的 test-runner、code-reviewer 等不是所有安装都自带的固定清单。
基本输入
description 和 prompt 必填,前者是简短任务说明,后者应包含独立执行所需信息。subagent_type 省略为 general-purpose,选择 fork 才能继承父对话。
agent(
description="Inspect authentication flow",
prompt="Inspect the authentication implementation and report concrete risks without modifying files.",
subagent_type="general-purpose",
run_in_background=false
)普通 subagent 不携带父历史;fork 默认全历史,fork_turns 可为 all 或正整数字符串,按真实用户轮次计,不把工具回复和纯系统提醒算一轮。
fork 执行限制
fork_tools 仅对 fork 有效,接受精确 canonical tool 名或允许的 MCP 模式,不接受前后空白;空数组拒绝全部工具调用,省略则继承可用执行能力,但 fork 永远不执行 ask_user_question。
限制只改变执行门槛,仍保留父级模型可见声明以复用缓存,不是管理员级沙箱。fork_profile 读取项目 .qwen/fork-profiles/
详细配置与来源校验见Fork。
前后台不是同一默认
顶层普通 agent 默认后台,run_in_background:false 等待内联结果。无头 fork 始终后台;嵌套 agent 前台执行,显式后台会拒绝,因为不能接收后台完成通知。
把无名调用绑定到 caller-owned working_dir 时必须前台:显式 true 拒绝,定义中的 background:true 在顶层拒绝、嵌套时降到前台。命名 teammate 可以并发使用指定树,但移除 worktree 前必须先关闭成员。
isolation:worktree 为显式指定的非 fork 类型创建受管 worktree;working_dir 指向当前仓库已注册的现有 worktree,二者同时存在时后者优先。
完成与继续
后台结果通过后续 completion notification 到达,不要在通知前假定已有答案。list_agents 返回可寻址 task_id,send_message 可给运行、暂停或已完成且保留兼容状态的 agent 继续工作。
恢复不可用时看 resume_blocked_reason,不因旧 task_id 存在就当作仍能继续。结果是待验证的证据,集成修改前仍需核对实际文件和测试。更完整的生命周期见后台 Subagents。