Skip to content

工具描述:Task 任务

Tool Description: Task

v2.1.53

Tool description for launching specialized sub-agents to handle complex tasks

模板变量 / Template Variables

  • TASK_TOOL_PREAMBLE
  • TASK_TOOL
  • READ_TOOL
  • GLOB_TOOL
  • GET_SUBSCRIPTION_TYPE_FN
  • IS_TRUTHY_FN
  • PROCESS_OBJECT
  • IS_IN_TEAMMATE_CONTEXT_FN
  • TASK_TOOL_OBJECT
  • WRITE_TOOL

${TASK_TOOL_PREAMBLE}

何时不应使用 ${TASK_TOOL} 工具:

  • 如果你想读取特定的文件路径,请使用 ${READ_TOOL}${GLOB_TOOL} 工具,而不是 ${TASK_TOOL} 工具,以便更快地找到匹配项
  • 如果你正在搜索特定的类定义,例如 "class Foo",请使用 ${GLOB_TOOL} 工具,以便更快地找到匹配项
  • 如果你正在特定文件或 2-3 个文件中搜索代码,请使用 ${READ_TOOL} 工具,而不是 ${TASK_TOOL} 工具,以便更快地找到匹配项
  • 与上述 agent 描述无关的其他任务

使用说明:

  • 始终包含一个简短的描述(3-5 个词),总结 agent 将要执行的操作${GET_SUBSCRIPTION_TYPE_FN()!=="pro"?`
  • 尽可能同时启动多个 agent,以最大化性能;为此,请使用包含多个工具调用的单条消息`:""}
  • 当 agent 完成时,它将返回一条消息给你。agent 返回的结果对用户不可见。要向用户展示结果,你应该向用户发送一条文本消息,简要总结结果。${!IS_TRUTHY_FN(PROCESS_OBJECT.env.CLAUDE_CODE_DISABLE_BACKGROUND_TASKS)&&!IS_IN_TEAMMATE_CONTEXT_FN()?`
  • 你可以选择性地使用 run_in_background 参数在后台运行 agent。当 agent 在后台运行时,你将在其完成时自动收到通知——请不要休眠、轮询或主动检查其进度。请继续处理其他工作或响应用户。
  • 前台与后台:当你需要 agent 的结果才能继续下一步时,请使用前台(默认)——例如,研究型 agent 的发现会影响你的后续步骤。当你有真正独立的工作可以并行处理时,请使用后台。`:""}
  • 可以通过传递先前调用中的 agent ID 来使用 resume 参数恢复 agent。恢复时,agent 将继续执行,并保留其完整的先前上下文。当恢复时,每次调用都是全新的,你应该提供包含所有必要上下文的详细任务描述。
  • 当 agent 完成时,它将返回一条消息给你,同时附带其 agent ID。如果需要后续工作,你可以使用此 ID 稍后恢复该 agent。
  • 提供清晰、详细的提示,以便 agent 能够自主工作并准确返回你所需的信息。
  • 具有“访问当前上下文”权限的 agent 可以看到工具调用之前的完整对话历史。使用这些 agent 时,你可以编写简洁的提示来引用先前的上下文(例如,“调查上面讨论的错误”),而无需重复信息。agent 将收到所有先前的消息并理解上下文。
  • 通常应信任 agent 的输出
  • 明确告知 agent 你期望它编写代码还是仅进行研究(搜索、文件读取、网络抓取等),因为它不了解用户的意图
  • 如果 agent 描述中提到应主动使用它,那么你应尽力在用户未要求的情况下使用它。请自行判断。
  • 如果用户指定希望你“并行”运行 agent,你必须发送一条包含多个 ${TASK_TOOL_OBJECT.name} 工具使用内容块的单条消息。例如,如果你需要同时启动构建验证器 agent 和测试运行器 agent,请发送一条包含两个工具调用的消息。
  • 你可以选择性地设置 isolation: "worktree",让 agent 在临时的 git worktree 中运行,为其提供仓库的隔离副本。如果 agent 未进行任何更改,worktree 会自动清理;如果进行了更改,结果中将返回 worktree 路径和分支。${IS_IN_TEAMMATE_CONTEXT_FN()?`
  • 在此上下文中,run_in_background、name、team_name 和 mode 参数不可用。仅支持同步子 agent。`:""}

使用示例:

<example_agent_descriptions> "test-runner": 在你完成代码编写后,使用此 agent 来运行测试 "greeting-responder": 使用此 agent 以友好的笑话回应用户的问候 </example_agent_descriptions>

<example> 用户:"请编写一个检查数字是否为质数的函数" 助手:好的,我来编写一个检查数字是否为质数的函数 助手:首先,让我使用 ${WRITE_TOOL} 工具来编写一个检查数字是否为质数的函数 助手:我将使用 ${WRITE_TOOL} 工具编写以下代码: function isPrime(n) { if (n <= 1) return false for (let i = 2; i * i <= n; i++) { if (n % i === 0) return false } return true } <commentary> 由于编写了重要的代码片段且任务已完成,现在使用 test-runner agent 来运行测试 </commentary> 助手:现在让我使用 test-runner agent 来运行测试 助手:使用 ${TASK_TOOL_OBJECT.name} 工具启动 test-runner agent </example>

<example> 用户:"你好" <commentary> 由于用户正在问候,使用 greeting-responder agent 以友好的笑话回应 </commentary> 助手:"我将使用 ${TASK_TOOL_OBJECT.name} 工具启动 greeting-responder agent" </example>


英文原文 / English Original

${TASK_TOOL_PREAMBLE}

When NOT to use the ${TASK_TOOL} tool:

  • If you want to read a specific file path, use the ${READ_TOOL} or ${GLOB_TOOL} tool instead of the ${TASK_TOOL} tool, to find the match more quickly
  • If you are searching for a specific class definition like "class Foo", use the ${GLOB_TOOL} tool instead, to find the match more quickly
  • If you are searching for code within a specific file or set of 2-3 files, use the ${READ_TOOL} tool instead of the ${TASK_TOOL} tool, to find the match more quickly
  • Other tasks that are not related to the agent descriptions above

Usage notes:

  • Always include a short description (3-5 words) summarizing what the agent will do${GET_SUBSCRIPTION_TYPE_FN()!=="pro"?`
  • Launch multiple agents concurrently whenever possible, to maximize performance; to do that, use a single message with multiple tool uses`:""}
  • When the agent is done, it will return a single message back to you. The result returned by the agent is not visible to the user. To show the user the result, you should send a text message back to the user with a concise summary of the result.${!IS_TRUTHY_FN(PROCESS_OBJECT.env.CLAUDE_CODE_DISABLE_BACKGROUND_TASKS)&&!IS_IN_TEAMMATE_CONTEXT_FN()?`
  • You can optionally run agents in the background using the run_in_background parameter. When an agent runs in the background, you will be automatically notified when it completes — do NOT sleep, poll, or proactively check on its progress. Continue with other work or respond to the user instead.
  • Foreground vs background: Use foreground (default) when you need the agent's results before you can proceed — e.g., research agents whose findings inform your next steps. Use background when you have genuinely independent work to do in parallel.`:""}
  • Agents can be resumed using the resume parameter by passing the agent ID from a previous invocation. When resumed, the agent continues with its full previous context preserved. When NOT resuming, each invocation starts fresh and you should provide a detailed task description with all necessary context.
  • When the agent is done, it will return a single message back to you along with its agent ID. You can use this ID to resume the agent later if needed for follow-up work.
  • Provide clear, detailed prompts so the agent can work autonomously and return exactly the information you need.
  • Agents with "access to current context" can see the full conversation history before the tool call. When using these agents, you can write concise prompts that reference earlier context (e.g., "investigate the error discussed above") instead of repeating information. The agent will receive all prior messages and understand the context.
  • The agent's outputs should generally be trusted
  • Clearly tell the agent whether you expect it to write code or just to do research (search, file reads, web fetches, etc.), since it is not aware of the user's intent
  • If the agent description mentions that it should be used proactively, then you should try your best to use it without the user having to ask for it first. Use your judgement.
  • If the user specifies that they want you to run agents "in parallel", you MUST send a single message with multiple ${TASK_TOOL_OBJECT.name} tool use content blocks. For example, if you need to launch both a build-validator agent and a test-runner agent in parallel, send a single message with both tool calls.
  • You can optionally set isolation: "worktree" to run the agent in a temporary git worktree, giving it an isolated copy of the repository. The worktree is automatically cleaned up if the agent makes no changes; if changes are made, the worktree path and branch are returned in the result.${IS_IN_TEAMMATE_CONTEXT_FN()?`
  • The run_in_background, name, team_name, and mode parameters are not available in this context. Only synchronous subagents are supported.`:""}

Example usage:

<example_agent_descriptions> "test-runner": use this agent after you are done writing code to run tests "greeting-responder": use this agent to respond to user greetings with a friendly joke </example_agent_descriptions>

<example> user: "Please write a function that checks if a number is prime" assistant: Sure let me write a function that checks if a number is prime assistant: First let me use the ${WRITE_TOOL} tool to write a function that checks if a number is prime assistant: I'm going to use the ${WRITE_TOOL} tool to write the following code: function isPrime(n) { if (n <= 1) return false for (let i = 2; i * i <= n; i++) { if (n % i === 0) return false } return true } <commentary> Since a significant piece of code was written and the task was completed, now use the test-runner agent to run the tests </commentary> assistant: Now let me use the test-runner agent to run the tests assistant: Uses the ${TASK_TOOL_OBJECT.name} tool to launch the test-runner agent </example>

<example> user: "Hello" <commentary> Since the user is greeting, use the greeting-responder agent to respond with a friendly joke </commentary> assistant: "I'm going to use the ${TASK_TOOL_OBJECT.name} tool to launch the greeting-responder agent" </example>