BrainBank
AI Classroom/SkillClaude Code Deep Dive

AgentTool: Sub-Agent Scheduler

7/31/2026, 8:55:39 PM · updated 7/31/2026, 9:00:46 PM

AI-translated on 7/31/2026, 9:03:43 PM · by Qwen3.6 35B (fast, default)

#claude-code#agenttool#skill#sub-agent#task-scheduling

AgentTool is a controlled task dispatcher in Claude Code, used to create and manage sub-agents to execute sub-tasks when the main thread's workload becomes too large.

AgentTool is the core scheduling component of Claude Code. It encapsulates "task decomposition, sub-agent execution, and lifecycle management" into a formal tool, marking this framework's architectural evolution from a single-threaded code assistant to a multi-task agent system. Through a controlled dispatch mechanism, independent context trimming, and complete workflow binding, it solves issues of parallel processing and main thread context pollution in complex task scenarios.

Core Problems Solved and Tool Positioning

AgentTool is one of the most representative tools in Claude Code. It doesn't solve single-point capabilities like "reading files" or "running commands," but rather:

When the main thread model determines that a task is too large, too complex, or ideally suited for parallelization, how to decompose part of the work for another agent to handle. This is one of the core dividing lines between Claude Code and standard code assistants. Many AI tools rely on a single main thread model running straight through, whereas Claude Code explicitly supports:

  • Research-oriented subtasks
  • Background execution
  • Multi-agent collaboration
  • Local/remote sub-agents

Core Parameters Exposure

tools/AgentTool/AgentTool.tsx exposes its core parameters right from the start:

const baseInputSchema = z.object({
  description: z.string().describe('A short (3-5 word) description of the task'),
  prompt: z.string().describe('The task for the agent to perform'),
  subagent_type: z.string().optional(),
  model: z.enum(['sonnet', 'opus', 'haiku']).optional(),
  run_in_background: z.boolean().optional(),
})

These fields clearly illustrate its positioning:

  • description: a brief title for the subtask
  • prompt: the actual work handed off to the sub-agent
  • subagent_type: selecting a specifically typed agent
  • model: switching models when necessary
  • run_in_background: executing asynchronously in the background In essence, AgentTool is a task dispatcher.

Position in the System Architecture

Within Claude Code's overall tool pool, it is placed at the very front:

export function getAllBaseTools(): Tools {
  return [
    AgentTool,
    TaskOutputTool,
    BashTool,
    ...
  ]
}

This doesn't necessarily mean "most frequently called," but it does indicate that Anthropic views it as a foundational core capability. Because once AgentTool is available, other tools are no longer just "for the main thread to use directly" but can be further invoked by sub-agents. Its position in the system: image.png


Underlying Mechanism and Controlled Dispatch Logic

More Than Just "Spinning Up Another Model"

Looking at the imports in AgentTool.tsx reveals that this tool actually bridges numerous subsystems behind the scenes:

import { enhanceSystemPromptWithEnvDetails, getSystemPrompt } from '../../constants/prompts.js'
import { assembleToolPool } from '../../tools.js'
import { runAgent } from './runAgent.js'
import { registerAsyncAgent } from '../../tasks/LocalAgentTask/LocalAgentTask.js'
import { registerRemoteAgentTask } from '../../tasks/RemoteAgentTask/RemoteAgentTask.js'

This means AgentTool does at least four things:

  1. Regenerates the sub-agent's system prompt
  2. Reassembles a dedicated tool pool
  3. Determines whether it's a local or remote task
  4. Registers the sub-agent within the task system Its true nature is better described as:

Starting a controlled work thread with task context, leveraging Claude Code's runtime framework.

Why Sub-Agents Don't Become "Uncontrolled Forks"

If it simply forked a model blindly, the system would quickly spiral out of control. Claude Code constrains it through several layers of mechanisms:

  • Each sub-agent has its own input schema
  • Each sub-agent reconstructs its own prompt
  • Each sub-agent's tool pool is filtered independently
  • Each sub-agent is registered into the task system, supporting status tracking, output retrieval, cancellation, and notifications Thus, AgentTool is not a "free-form cloning tool," but a controlled dispatcher. The call chain can be examined in more detail: image.png

Task Lifecycle Binding and Tool Collaboration

Tight Coupling with the Task System

Claude Code doesn't let sub-agents run secretly in the background; it treats them as formal tasks:

  • Output is viewable
  • Capable of background execution
  • Can be stopped/cancelled
  • Can be resumed/recovered This is precisely why TaskOutputTool immediately follows AgentTool. They natively function as a pair:
  • AgentTool handles task dispatching
  • TaskOutputTool handles result retrieval

Typical Execution Path

A typical path can be understood as follows:

  1. The main thread identifies that "this problem requires deep investigation into a specific subsystem"
  2. The main thread invokes AgentTool
  3. The sub-agent independently searches, reads files, reasons, and executes
  4. The sub-agent delivers a compressed conclusion
  5. The main thread takes this conclusion to continue advancing Compared to "the main thread executing all searches itself," the greatest advantages are:
  • Reduced main context pollution
  • Easier parallelization
  • Better suited for heavy research and deep-dive troubleshooting tasks

Relationship with Adjacent Tools

image.png

  • Works with TaskOutputTool: reads sub-agent output
  • Works with SendMessageTool: enables mutual communication in multi-agent mode
  • Works with BashTool, Read, and Edit: allows the sub-agent to continue completing tasks independently
  • Works with SkillTool: certain skills are executed within an independent sub-agent

Clarifying Common Misconceptions

🚫 Misconception 1: AgentTool is just multi-turn conversation

No. It is a definitive tool invocation, complete with schema, task lifecycle, and result injection.

🚫 Misconception 2: Sub-agents are identical to the main thread

Also no. A sub-agent's prompt, tool pool, and execution mode can all differ.

🚫 Misunderstanding 3: AgentTool is just a "more advanced prompt"

Not entirely accurate. It's more like "integrating another Agent as a formal runtime object into the system".

Key takeaways

  • AgentTool is not a single-point capability tool, but rather the scheduling hub encapsulating task decomposition, subprocess execution, and lifecycle management within Claude Code.
  • Through independent schemas, prompt restructuring, tool pool isolation, and binding to the Task system, sub-agents are strictly constrained as controlled dispatch targets, rather than autonomous clones.
  • Naturally paired with TaskOutputTool, it forms a standardized workflow of "main thread dispatch → context-isolated processing → result return".
  • The core business value lies in reducing main context pollution and enabling native parallelism, providing architectural-level support for research-oriented and deep investigation tasks.

Learning map

Learning Map

Stage 1 – Foundations

  • Understand the purpose of AgentTool and how it differs from single‑call tools.
  • Read the base input schema (description, prompt, subagent_type, model, run_in_background).

Stage 2 – Integration Basics

  • Learn how AgentTool is positioned in the global tool pool (first entry).
  • Explore the four internal steps it performs: system‑prompt enhancement, tool‑pool pruning, task type selection, and registration with the task system.

Stage 3 – Practical Use

  • Pair AgentTool with TaskOutputTool to retrieve sub‑agent results.
  • Experiment with background execution and model overrides.

Stage 4 – Advanced Patterns

  • Combine AgentTool with SendMessageTool for multi‑Agent communication.
  • Use BashTool, Read/Edit tools inside a sub‑agent for complex workflows.
  • Implement custom subagent_type to specialize agents for research, debugging, or data extraction.

Stage 5 – Production Ready

  • Monitor task lifecycle (status, stop, resume) via the task system UI.
  • Apply best‑practice patterns for error handling and result validation.

Get hands-on — step by step

  1. Open your Claude Code project and locate tools/AgentTool/AgentTool.tsx.
  2. Add a new entry in your workflow script that calls AgentTool with:
    {
      "description": "Search API docs",
      "prompt": "Find the authentication flow for the Anthropic API and summarize it.",
      "subagent_type": "research",
      "model": "sonnet",
      "run_in_background": true
    }
    
  3. Immediately after the AgentTool call, invoke TaskOutputTool with the task ID returned in step 2 to fetch the sub‑agent’s result.
  4. Print the retrieved summary to the console or feed it into the next stage of your main agent.
  5. Test the flow:
    • Run the script.
    • Verify that a background sub‑agent is created (check the task dashboard).
    • Confirm the output matches the expected API documentation summary.
  6. Experiment: change run_in_background to false and observe synchronous execution, then try model": "opus" for a higher‑capacity model.

Top 3 sources

  1. 1
    Anthropic Claude Documentation – Tool Use

    Official guide that explains how Claude tools work, including schema definitions and execution semantics.

    https://docs.anthropic.com/claude/docs/tool-use

  2. 2
    Claude API Reference – Tools Section

    Detailed reference for all built‑in tools, with examples of AgentTool usage and parameters.

    https://docs.anthropic.com/claude/reference/tools

  3. 3
    Anthropic News – Introducing Claude Code

    Announcement blog post describing the multi‑agent capabilities of Claude Code and the role of AgentTool as a task dispatcher.

    https://www.anthropic.com/news/claude-code

Links are AI-suggested — worth a quick sanity check before diving in.