# What Are Subagents? Explained in 4 Minutes

## Executive summary

Deep Agents, LangChain's open-source agent harness, utilizes subagents to manage context overload during complex, long-running tasks. A subagent is a specialized, isolated assistant that handles specific tasks, returning only the final result to the main agent, thereby keeping the main agent's context focused and unpolluted. This mechanism supports parallel, asynchronous, and sandboxed execution, enhancing the reliability and scalability of AI agents.

## Key takeaways

- Context Preservation via Delegation: Subagents receive a task and send back only the final result, ensuring that the messy intermediate steps (searches, dead ends, long documents) remain within the subagent's isolated context window, not the main agent's.
- Parallel and Asynchronous Processing: The Deep Agents harness allows the main agent to dispatch multiple tasks (e.g., 10 companies) to subagents in a single turn, or run them asynchronously in the background, allowing the main agent to continue interaction.
- Specialization and Resource Isolation: Specialist subagents (e.g., a database expert) can be equipped with specific tools (like SQL tools) that are contained within the subagent, keeping the main agent's context leaner.

## Technical details

- Sandbox Execution: Subagents can operate within a sandbox—an isolated environment—allowing them to safely run code and shell commands without affecting the host machine. Files saved to the sandbox are accessible by the main agent or other subagents.
- Context Management Techniques: To keep subagent context lean, the harness supports 'offloading' (saving large tool results to a file and sending only a short preview) and 'summarization' (summarizing older messages when history reaches 85% of the model's limit).
- Model Agnosticism: Because the Deep Agents harness is provider-agnostic, each subagent can be configured to use a different model—for instance, a cheaper, faster model for simple lookups and a stronger model for final synthesis.

## Practical implications

- Build complex, multi-stage AI systems by delegating large research or data processing tasks to specialized subagents.
- Improve the reliability and accuracy of long-running agents by preventing context window saturation and reasoning degradation.
- Implement secure code execution within agents using the sandbox feature.

## Topics

AI Agents, Context Engineering, LangChain, Distributed Computing, Introduction to Deep Agents (free course), Subagents in the Deep Agents docs, Deep Agents on GitHub

Source: https://www.youtube.com/watch?v=AekKS44xBhI
