---
title: "What is a subagent in AI agent systems?"
description: "A subagent is an AI agent started by another agent for one subtask, in its own context window, that returns a condensed result. How it works and vs handoffs."
type: "glossary-term"
canonical_url: "https://theaiengineering.com/glossary/subagent"
markdown_url: "https://theaiengineering.com/glossary/subagent.md"
topic: "AI agents"
author: "The AI Engineering Editors"
publisher: "The AI Engineering"
updated: "2026-11-06"
keywords: ["Subagent","sub-agent","subagents"]
citation: "The AI Engineering Editors. \"What is a subagent in AI agent systems?\" The AI Engineering, updated Nov 06, 2026. https://theaiengineering.com/glossary/subagent"
---

# What is a subagent in AI agent systems?

Also called sub-agent, subagents.

> **Definition of Subagent:** 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](https://theaiengineering.com/glossary/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](https://theaiengineering.com/glossary/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](https://theaiengineering.com/glossary/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](https://www.anthropic.com/engineering/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](https://code.claude.com/docs/en/sub-agents) 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](https://learn.chatgpt.com/docs/agent-configuration/subagents) 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](https://theaiengineering.com/glossary/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](https://theaiengineering.com/glossary/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](https://theaiengineering.com/articles/context-engineering) covers subagents alongside compaction and memory as ways to keep a context window small.

## Related terms

- [Multi-agent system](https://theaiengineering.com/glossary/multi-agent-system): A multi-agent system is an AI architecture in which several language-model agents, each with its own prompt, tools, and context, work on parts of a task and pass results to one another.
- [Agent handoff](https://theaiengineering.com/glossary/agent-handoff): An agent handoff is a transfer of control in which one AI agent passes the conversation, and responsibility for the task, to another agent better suited to the next part of the work.
- [Agent orchestration](https://theaiengineering.com/glossary/agent-orchestration): Agent orchestration is the control logic that decides which agent, model call, or tool runs next in an AI system and what each receives, whether written in code or chosen by a model.
- [Context engineering](https://theaiengineering.com/glossary/context-engineering): Context engineering is the practice of selecting, structuring, and pruning all the information placed in an LLM's context window at each step, including instructions, retrieved data, tool results, and memory.
- [Context window](https://theaiengineering.com/glossary/context-window): A context window is the maximum number of tokens a language model can take into account in a single request, including the system prompt, conversation history, tool results, and the generated output.
- [Context rot](https://theaiengineering.com/glossary/context-rot): Context rot is the decline in a language model's accuracy and recall as the number of tokens in its input grows, even when the information a task needs is present in the context.

## Guides that cover subagent

- [What is context engineering? A practical guide for AI agents](https://theaiengineering.com/articles/context-engineering): Context engineering is the practice of choosing what fills an LLM context window. Learn its components, why context rot happens, and how to measure results.
- [What are AI agents? How agents work and when to use one](https://theaiengineering.com/articles/what-are-ai-agents): AI agents are LLM systems that call tools in a loop until a task is done. Learn how the loop works, agents vs agentic AI, examples, failure modes, and limits.
- [AI agent frameworks compared: LangGraph, CrewAI, ADK, and more](https://theaiengineering.com/articles/ai-agent-frameworks): An AI agent frameworks comparison of LangGraph, LangChain, CrewAI, the OpenAI, Claude, and Google SDKs, Pydantic AI, Mastra, and more, by language and license.
- [A2A protocol vs MCP: differences and when to use each](https://theaiengineering.com/articles/a2a-vs-mcp): A2A protocol vs MCP: A2A connects AI agents to other agents, and MCP connects an agent to tools and data. Compare agent cards, tasks, transports, and security.
- [How to build an AI agent: a step-by-step guide in Python](https://theaiengineering.com/articles/how-to-build-an-ai-agent): Learn how to build an AI agent from scratch in Python: when you need one, tool schemas, the agent loop, stop conditions, guardrails, evals, and tracing.
- [Agentic workflows: five patterns and when to use each](https://theaiengineering.com/articles/agentic-workflows): Agentic workflows run LLM and tool calls through steps fixed in code. Learn five patterns, their cost and latency, failure modes, and when to use an agent.
- [Claude Code vs Cursor: how the two coding agents differ](https://theaiengineering.com/articles/claude-code-vs-cursor): Claude Code vs Cursor compared: terminal agent vs AI editor, models, subagents, hooks, rules files, code review, CI use, pricing, and enterprise controls.

Part of the [AI agents](https://theaiengineering.com/topics/ai-agents) topic hub.

## 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: 2026-11-06
- URL: https://theaiengineering.com/glossary/subagent
- Markdown: https://theaiengineering.com/glossary/subagent.md
