Introduction to Sub Agents
Discover what sub agents are, how the parent-child agent relationship works, and why modern AI tools use them to tackle complex tasks efficiently.
What Are Sub Agents?
Sub agents are specialized AI agents that are spawned by a parent agent to handle specific subtasks autonomously. Think of them as assistants to the assistant - when a primary AI agent encounters a complex problem, it can delegate parts of that problem to child agents that focus on individual pieces.
This pattern is used extensively in modern AI tools like Claude Code CLI, Gemini CLI, and other agentic development environments. Instead of one agent trying to do everything sequentially, work is divided among specialists.
The Parent-Child Agent Relationship
The relationship between a parent agent and its sub agents follows a clear hierarchy:
Parent Agent (main conversation) | |-- Sub Agent A (research task) | |-- Reads files | |-- Searches codebase | |-- Returns findings | |-- Sub Agent B (coding task) | |-- Writes implementation | |-- Runs tests | |-- Returns code changes | |-- Parent aggregates results
The parent agent maintains the overall conversation context and orchestrates the workflow. Each sub agent operates in its own isolated context, focused solely on the task it was given.
Why Sub Agents?
There are several compelling reasons to use sub agents instead of having one agent do everything:
-
Divide Complex Tasks
Large tasks can be broken into smaller, well-defined subtasks. Each sub agent handles one piece, making the overall problem more manageable and the results more reliable.
-
Parallel Execution
Multiple sub agents can run at the same time. While one agent researches the codebase, another can be writing code, and a third can be running tests - dramatically reducing total completion time.
-
Specialized Roles
Each sub agent can be given specific instructions, tools, and constraints tailored to its task. A research agent gets read-only file access while a coding agent gets write access.
-
Context Isolation
Sub agents work within their own context window, preventing information overload. The parent agent does not need to hold every detail - it delegates and receives summaries.
Real Examples from Claude Code
Claude Code CLI uses sub agents extensively. Here are the primary agent types it spawns:
| Agent Type | Purpose | Tools Available |
|---|---|---|
| Explore Agent | Searches and reads files to understand the codebase | Read, Glob, Grep |
| Plan Agent | Analyzes tasks and creates implementation plans | Read, Glob, Grep |
| General-Purpose Agent | Handles coding, testing, and other complex work | Read, Write, Edit, Bash, Glob, Grep |
Sub Agents in Other Tools
The sub agent pattern is not limited to Claude Code. It appears across the AI tool ecosystem:
- Gemini CLI: Uses agent delegation for complex multi-step tasks, spawning specialized workers for research and code generation.
- OpenAI Assistants API: Supports creating multiple assistant instances that can be orchestrated by application code to work on different aspects of a problem.
- LangChain / LangGraph: Provides agent frameworks where parent agents route tasks to specialized sub-agents based on the type of work needed.
- AutoGen (Microsoft): Multi-agent conversation framework where agents can be composed into hierarchies with manager and worker patterns.
- CrewAI: Role-based agent framework where crews of agents collaborate, each with specific roles, goals, and tool access.
Ready to Go Deeper?
Live instructor-led courses from our partners. Affiliate disclosure.
AI & ML Courses - 30% Off
Live instructor-led AI, machine learning, data science, and cloud courses for working professionals. Use code Limited30 at checkout.
EdurekaDataCamp - AI & Data Science
Hands-on Python, machine learning, and AI courses with interactive exercises and real projects.
DataCampedX - Top AI Courses
University-level AI courses from MIT, Harvard, Stanford. Earn certificates that employers recognize.
edX