Subagent
A subagent is an agent spawned by another agent to handle a scoped piece of work in its own context window. The parent delegates a task, the subagent works and returns a result, and only that result enters the parent's context rather than everything the subagent read.
The motivation is context economy. Searching a large codebase might read fifty files to find three relevant ones. If that happens in the main context, those fifty files crowd out everything else. If it happens in a subagent, the parent receives only the answer.
The second use is parallelism. Independent pieces of work — reviewing four modules, investigating three hypotheses — can run at the same time rather than sequentially, since none depends on another's output.
What this means in practice
Delegation to subagents is worth requesting explicitly when a task has a wide search phase and a narrow answer. "Find every call site of this function, then propose a migration" benefits; "rename this variable" does not.
A delegation prompt that uses subagents well
Find every place we construct SQL by string concatenation. Delegate the search: have subagents sweep src/ in parallel and return only file:line plus a one-line classification (user input reachable: yes / no / unclear). I don't need the surrounding code. Then, in the main conversation, propose a migration order starting with the user-reachable ones, and stop for my approval before editing anything.
The shape to copy: wide search delegated, only conclusions return, decisions and edits stay in the main thread.
Prompts for the tools this applies to
Related terms
- Context window
The context window is the maximum amount of text a model can consider at once, measured in tokens and covering everything in the request: system prompt, your instructions, the files supplied, prior conversation, and the response being generated..
- Agent loop
The agent loop is the repeating cycle an AI agent runs: decide what to do next, take an action such as reading a file or running a command, observe the result, and repeat.
- Context engineering
Context engineering is the practice of deciding what information an AI model sees for a given task — which files, which conventions, which prior results — and in what form.
- Agent skills
Agent skills are reusable packages of instructions, context, and sometimes code that an agent loads when a task calls for them.