What is a subagent in AI agent systems?

Also called sub-agent, subagents

Definition

A subagent is an AI agent that another agent starts for one subtask, running in a separate context window with its own instructions and tools, and returning only a condensed result.

A subagent is an AI agent that a parent agent starts to handle one subtask, such as searching a codebase or researching one subtopic. The subagent runs its own loop in a fresh context window, with its own instructions and tool set, and returns a short result. The parent's context then holds that answer instead of every file, page, and tool result the subagent read. Subagents are the workers in the orchestrator-worker pattern of a multi-agent system.

How a subagent works#

A subagent works like a function call with its own context. The parent writes a task description and calls a tool that starts the subagent. The subagent explores, calls tools, and finishes with a summary or a pointer to a file. Only that summary returns, so the exploration costs tokens once and never enters the parent's context.

Anthropic's multi-agent research system uses this design: a lead agent spawns subagents that search in parallel, each in its own context window, and condenses what they return. Anthropic found that the lead has to give each subagent an objective, an output format, guidance on tools and sources, and clear task boundaries; vague task descriptions led subagents to duplicate each other's work.

Coding agents expose subagents as configuration files:

  • Claude Code defines them as Markdown files with YAML frontmatter in .claude/agents/. Each runs with its own system prompt, tool access, and permissions, and its built-in Explore subagent is read-only.
  • Codex defines custom agents as TOML files in .codex/agents/. Its documentation recommends that subagents return summaries rather than raw intermediate output, which keeps noisy work off the main thread.

Codex's documentation recommends parallel subagents mainly for read-heavy work and warns that agents editing code at the same time can create conflicts.

Subagent vs handoff#

A subagent returns control to its parent, while an agent handoff transfers control to another agent. The parent of a subagent stays responsible for the task and sees only the subagent's result. In a handoff, the receiving agent takes over the conversation, usually with its full history, and the original agent stops acting.

Subagent Handoff
Control after the call Returns to the parent Moves to the receiving agent
Context the agent starts with A fresh window and a task description Usually the whole conversation so far
Output A condensed result for the parent Replies to the user
Typical use Parallel search, isolated exploration Routing a user to a specialist

The OpenAI Agents SDK calls the subagent pattern agents as tools: a manager agent keeps the conversation and calls specialists for bounded subtasks.

When subagents pay off#

Subagents pay off when a subtask needs a lot of reading but only a short answer, or when independent branches can run in parallel. They cost more tokens and add a coordination step. Anthropic measured its multi-agent research runs at about 15 times the tokens of a chat interaction, and a summary can drop a detail the parent needed.

Codex's documentation describes the two problems that moving noisy work off the main thread avoids. Context pollution buries useful information under intermediate output, and context rot degrades performance as the window fills with less relevant detail. When a task fits comfortably in one context window, a single agent is cheaper.

The context engineering guide covers subagents alongside compaction and memory as ways to keep a context window small.

Cite this definition

The AI Engineering Editors. "What is a subagent in AI agent systems?" The AI Engineering, updated Nov 06, 2026. https://theaiengineering.com/glossary/subagent

Title
What is a subagent in AI agent systems?
Author
The AI Engineering Editors
Publisher
The AI Engineering
Updated
View as Markdown

Part of the AI agents hub · Updated