Subagent (Sub-Agent)
A specialized AI agent invoked by a parent agent to handle a focused part of a larger task—file search, web research, code review, data validation—with its own context window, system prompt, and tool access. Subagents prevent context contamination on the parent, parallelize independent work, and let teams compose complex behaviors from small, testable pieces. Claude Code, OpenAI Swarm, and most production agent frameworks now treat subagents as a first-class primitive.
Example
A coding agent is asked to ship a feature. Instead of holding the whole task in one context window, it spawns three subagents in parallel: a 'codebase explorer' that maps relevant files, a 'test author' that drafts tests against the spec, and a 'reviewer' that checks the proposed diff against the project's style guide. Each subagent returns a short structured result; the parent agent integrates them and produces the PR. Total wall-clock time drops from 18 minutes to 6, and the parent never sees the 40,000 tokens of intermediate exploration.
Frequently asked questions
- When should I use a subagent instead of just calling a tool?
- Use a tool when the task is one well-defined action (read this file, query this endpoint). Use a subagent when the task itself requires reasoning, planning, or its own multi-step loop (search the codebase for everything related to billing, then synthesize a summary). Subagents earn their cost when (1) the task benefits from a clean context window, (2) you want parallelism, or (3) you want a specialized system prompt that would clutter the parent.
- Do subagents cost more than doing the work inline?
- Per call, yes—each subagent invocation pays its own input-token tax. But they often reduce total cost on long tasks because the parent's context stays small. A parent that re-reads 50K tokens of intermediate exploration on every turn pays that tax repeatedly; offloading exploration to a subagent that returns a 500-token summary is usually cheaper end-to-end, especially with prompt caching on the parent.