docs/developers/tools/task.md
agent)This document describes the agent tool for Qwen Code.
Use agent to launch a specialized subagent to handle complex, multi-step tasks autonomously. The Agent tool delegates work to specialized agents that can work independently with access to their own set of tools, allowing for parallel task execution and specialized expertise.
agent takes the following arguments:
description (string, required): A short (3-5 word) description of the task for user visibility and tracking purposes.prompt (string, required): The detailed task prompt for the subagent to execute. Should contain comprehensive instructions for autonomous execution.subagent_type (string, optional): The type of specialized agent to use for this task. Defaults to general-purpose if omitted.fork_turns (string, optional): Only valid with subagent_type="fork". Omit it or use all for the full parent conversation, or use a positive integer string such as "3" for the most recent three real user turns. Tool responses and pure system reminders do not count as turns.run_in_background (boolean, optional): Defaults to true for top-level regular agents. Set to false to wait for a regular agent's result inline. Headless forks always run in the background. Nested agents run in the foreground unless run_in_background is explicitly true, which is rejected because nested agents cannot receive background completion notifications. Caller-owned working_dir launches run in the foreground and reject explicit or configured background execution.isolation (string, optional): Set to "worktree" to run an explicitly named, non-fork agent in an isolated git worktree that Qwen Code creates and manages.working_dir (string, optional): Pin an explicitly named, non-fork agent to an existing registered git worktree inside the current repository. The caller owns the worktree lifecycle, so this mode runs in the foreground. If both working_dir and isolation are provided, working_dir takes precedence.agent with Qwen CodeThe Agent tool dynamically loads available subagents from your configuration and delegates tasks to them. Each subagent runs independently and can use its own set of tools, allowing for specialized expertise and parallel execution.
When you use the Agent tool, the subagent will:
Usage:
agent(description="Brief task description", prompt="Detailed task instructions for the subagent", subagent_type="agent_name")
agent(description="Brief task description", prompt="Detailed task instructions for the fork", subagent_type="fork", fork_turns="3")
Set run_in_background=false when the current turn must use the subagent result before continuing.
The available subagents depend on your configuration. Common subagent types might include:
You can view available subagents by using the /agents command in Qwen Code.
The Agent tool provides live updates showing:
You can launch multiple subagents concurrently by calling the Agent tool multiple times in a single message, allowing for parallel task execution and improved efficiency.
Each subagent can be configured with:
Background agents can receive follow-up work after their initial completion:
list_agents to discover the current session's addressable background agents and their task_id values. This includes compatible agents restored after the parent session resumes.send_message with a task_id and follow-up instruction. Running agents receive the message at the next tool-round boundary, paused agents resume with it, and completed agents continue on a resident runtime when available or revive from their retained transcript.If an agent cannot be continued, list_agents returns a resume_blocked_reason. Treat restored or continued agent output as evidence and verify it before integrating changes.
agent examplesagent(
description="Code refactoring",
prompt="Please refactor the authentication module in src/auth/ to use modern async/await patterns instead of callbacks. Ensure all tests still pass and update any related documentation.",
subagent_type="general-purpose"
)
# Launch code review and test execution in parallel
agent(
description="Code review",
prompt="Review the recent changes in the user management module for code quality, security issues, and best practices compliance.",
subagent_type="general-purpose"
)
agent(
description="Run tests",
prompt="Execute the full test suite and analyze any failures. Provide a summary of test coverage and recommendations for improvement.",
subagent_type="test-engineer"
)
agent(
description="Update docs",
prompt="Generate comprehensive API documentation for the newly implemented REST endpoints in the orders module. Include request/response examples and error codes.",
subagent_type="general-purpose"
)
Use the Agent tool when:
Don't use the Agent tool for:
fork_turns when a bounded recent window is sufficient.list_agents and send_message for related follow-up work instead of launching a duplicate agent. Continuation depends on compatible retained state and may be unavailable.Subagents are configured through Qwen Code's agent configuration system. Use the /agents command to:
For more information on configuring subagents, refer to the subagents documentation.