For translation, open lesson in new tab and use Chrome translate
The video and the text below cover the same material, so pick whichever format you prefer. If they ever differ, the text is the most up-to-date version.
The video and the text below cover the same material, so pick whichever format you prefer. If they ever differ, the text is the most up-to-date version.
Long-running agents need coordination. A big task can span many steps, tool calls, files, and intermediate results. Without an explicit way to track the plan and isolate specialized work, the main agent can drift or overload its context.
Deep Agents gives the main agent two coordination tools:
write_todos keeps a visible task list so the main agent can track what is pending, in progress, and complete. It's opt-in, enabled by adding TodoListMiddleware when you build the agent.Planning and delegation solve different problems. Planning keeps the main agent organized. Delegation moves specialized or context-heavy work out of the main agent's context.
A capable model can draft a solid plan for a multi-step job. The hard part is follow-through. As the conversation grows and the agent juggles tool calls and intermediate results, it tends to drift, losing track of what's already done and what's still left.
Deep Agents addresses this with an opt-in write_todos tool: add TodoListMiddleware to the agent's middleware list and the model gets a tool for writing its plan out as a structured to-do list and updating each item's status as it works:
from langchain.agents.middleware import TodoListMiddleware
from deepagents import create_deep_agent
agent = create_deep_agent(
tools=[...],
middleware=[TodoListMiddleware()],
)
pending: not started yetin_progress: being worked on nowcompleted: doneThe list is saved in the agent's state. Across turns, it persists when you use the same thread with a checkpointer, following the thread pattern introduced earlier in the course. On a long task the agent always has an explicit, up-to-date plan to check against instead of trying to hold the whole thing in its head. Think of it as writing the steps on a whiteboard and ticking them off as it goes.
Planning is not delegation. It is the supervisor's task list: a way for the main agent to keep itself organized before, during, and after tool calls.
When a project is too big for one person, we bring in a team.
A few things make this work:
This video is optional. It's a quick visual explanation of subagents if you'd like one before reading on; the section below covers the same ideas.
A subagent is a full agent the main agent can call to do a focused task and report back. It can have its own instructions, tools, skills, model, and isolated context. The team pattern carries straight over.
Subagent-as-tool. Deep Agents exposes subagents through a built-in
tasktool. To the main agent, delegating looks just like calling any other tool. The main agent callstaskwith an assignment and gets a result back, picking which subagent to use from each one's description, the same way it decides to call any other tool.
The video and the text below cover the same material, so pick whichever format you prefer. If they ever differ, the text is the most up-to-date version.
The video and the text below cover the same material, so pick whichever format you prefer. If they ever differ, the text is the most up-to-date version.
This is what makes subagents a context-engineering tool. A subagent does its work without cluttering the main agent's context:
task call is a fresh run with no memory of earlier calls, and the subagent can't carry on a back-and-forth with the main agent (shared state such as the agent filesystem can still pass between them).The payoff: a large, messy subtask gets compressed into a single clean result, as long as the subagent is told to return a concise summary. The main agent's context stays focused on coordination, even as the work piles up behind the scenes.
If you've seen The Devil Wears Prada, this is basically it: Miranda Priestly doesn't want to hear how Andy got something done, just the result. Subagent = Andy Sachs; the subagent does the messy work and hands the main agent only what it needs to know, not tool call noise or irrelevant details.
Miranda also doesn't wait on one assistant at a time: she sends several off at once, each on their own errand. A main agent can do the same, running multiple subagents in parallel, each in its own separate context.
New update: fork mode (experimental). By default, a subagent only sees the task description it's given. Set "mode": "fork" to see the parent's conversation so far and use the parent's system prompt instead.
reviewer = {
"name": "reviewer",
"description": "Review the plan we just discussed.",
"mode": "fork",
}
Use it when the subagent needs context from the conversation that would be hard to write into a task description. The cost is a larger context for the subagent. A forked subagent can't set its own skills (it uses the parent's).
Added in deepagents 0.7.12. The labs don't use it.
New update: fork mode (experimental). By default, a subagent only sees the task description it's given. Set mode: "fork" to see the parent's conversation so far and use the parent's system prompt instead.
const reviewer: SubAgent = {
name: "reviewer",
description: "Review the plan we just discussed.",
mode: "fork",
};
Use it when the subagent needs context from the conversation that would be hard to write into a task description. The cost is a larger context for the subagent. A forked subagent can't set its own skills (it uses the parent's).
The labs don't use it.
Subagents can run in two modes. The choice comes down to one question: does the main agent need the result before it can keep going?
This course uses synchronous subagents in the hands-on lab. Async subagents are useful for production/background workflows where the main agent should stay responsive while longer work continues elsewhere.
Try it yourself: ask it to compare options or brief multiple topics, then watch the subagents run in parallel.
* This demo runs a create_deep_agent orchestrator with three subagents (researcher, analyzer, writer) invoked in parallel through task(), the same subagent-as-tool model described above.
For example, try: "Compare React, Vue, and Svelte for building a new team dashboard."
Watch:
Use a subagent when:
Skip the subagent when:
In this lesson you learned how planning and delegation support long-running agents:
write_todos task list, opt-in via TodoListMiddleware.task tool.Complete the Quiz above, then continue to the next lesson where you'll build a subagent team: a main agent that fans out parallel searches to subagents and synthesizes their results into a weekly newsletter.
Documentation:
Blog:
Go deeper: read the source (optional)
The lesson shows how to use this. To see how it's implemented, start with these files:
middleware/subagents.py: the task tool and how subagents are built and runGo deeper: read the source (optional)
The lesson shows how to use this. To see how it's implemented, start with these files:
middleware/subagents.ts: the task tool and how subagents are built and run