Dynamic Subagents · LangChain · 2026

Dynamic Subagents

An interactive walkthrough of LangChain's new Dynamic Subagents for Deep Agents, presented by Colin. The core move: when orchestrating subagents in the agent's own reasoning gets unreliable at scale, let the agent write code to spawn and coordinate them instead — for reliable coverage, real control flow, and six repeatable workflow patterns.

0 / 6 sections
1
The Orchestration Gap
Subagents give context isolation — but the main agent orchestrating them in its head breaks at scale

Deep Agents already have subagents, and they're great. Their main gift is context isolation: each subagent runs in its own context window, does a piece of the work, and hands back just the results — so the main agent's context stays clean. That's still true here.

So why do we need anything more? Because normally the main agent orchestrates its subagents itself. It calls the subagent tool (the task tool), looks at what comes back, decides what to call next, and repeats until it thinks it's done. That's totally fine for a handful of calls — but all of that orchestration lives in the agent's own reasoning and context. The moment the task gets big or repetitive, it becomes unreliable: the agent loses track, skips things, decides it's done early, and sometimes takes a bad trajectory.

The book example: summarize every page in a book, one subagent per page. With plain tool-calling you're relying on the main agent to fire the subagent tool a few hundred times in a row without losing the plot.
Demo — pick a task size; watch in-head coverage collapse
Items actually completed — orchestrating in the agent's head
Pick a size. A handful of calls is fine — but the bigger the task, the more the agent loses the plot.
What breaks when the main agent orchestrates all its subagents in its own reasoning as the task gets large?
2
Move the Orchestration Into Code
The agent writes a loop — orchestration leaves its head and becomes a few lines of code

Dynamic subagents let the agent spawn and coordinate subagents programmatically by writing code. Back to the book: instead of firing the subagent tool a few hundred times in a row, the agent just writes a loop — a few lines that spin up one subagent per page and collect the results. The orchestration moves out of the agent's head and into code.

That's the whole idea: when the orchestration logic is easier and more reliable to express in code than to have the agent generate it turn by turn, let it write code. Two payoffs stand out:

Reliable coveragea loop runs for every item — all 500, not just 75 Real control flowloops · branching · retries · parallelism

Completeness stops depending on the agent's discretion, and it stops being a prompt-engineering problem you have to keep tuning.

Demo — summarize every page of a book · in-head vs in-code
🧠 In the agent's head
calls the task tool page by page, tracking it all in its reasoning
— / 12
⌨️ In code (a loop)
for page in pages: await task(...) — a few lines
— / 12
Same job, both ways. Watch the in-head column skip pages while the loop covers all 12.
Why does moving orchestration into code improve coverage?
3
How It Works: The Code Interpreter Middleware & the task Global
A sandbox + an eval tool + a programmatic task() the agent calls in code

The agent runs its code through the code interpreter middleware — a lightweight in-memory sandbox that gives the agent an eval tool. The agent writes a block of code, hands it to eval, the runtime runs it, and only the final result comes back. That's a big part of how the context stays clean.

The middleware also exposes a task global by default — a programmatic version of the task tool. Spawning a subagent from inside code is just a function call: await task(description, subagentType, responseSchema?). The optional response schema makes the result typed, which is exactly what lets the agent loop or branch on what a subagent returns. And because variables persist across eval calls, the agent can build up state and work iteratively.

The data flow

Demo — hover a node for its role, then run the eval cycle
Hover any node to see its role. Hit run to watch code flow out and a typed result flow back.
Two things to use it: (1) attach the code interpreter middleware to your Deep Agent — it ships the task global by default; (2) trigger it (next section). It's also on by default in Decode, LangChain's terminal coding agent.
What does the task global give the agent that the plain task tool doesn't?
4
Triggering It: The workflow Keyword
The signal that you want the agent to write orchestration code — and how you steer every pattern

Once the middleware is attached, the agent can write code to orchestrate subagents — but it won't always decide to on its own. Putting workflow in your request is the signal that you want it to. So "review every file in this PR" may or may not fan out, while "run workflow to review every file in this PR" explicitly tells the agent to write the orchestration code.

Keep this in mind: it's exactly how you steer every one of the six patterns coming up — the phrasing of the workflow request shapes which pattern emerges.

Demo — toggle the keyword and watch the behavior change
review every file in this PR
🤷 Might fan out — might not
Without the keyword, the agent may orchestrate in code or may just try to do it turn-by-turn in its head. The behavior isn't guaranteed.
What's the point of the workflow keyword in your request?
5
The Six Patterns
Classify & Act · Fan Out & Synthesize · Adversarial Verification · Generate & Filter · Tournament · Loop Until Done

Six patterns show up most often. They emerge naturally from the shape of the task, and you steer toward each with how you phrase the workflow request. (These were originally coined by Anthropic in their work on dynamic workflows — the same shapes appear in dynamic subagents.) Click each to see what it's for and the phrasing that gets you there.

Demo — click a pattern to explore it
Six shapes emerge from the task itself. Click one — and note how each is steered by how you phrase the request.
The through-line: the agent decomposes the task however it sees fit — a read_file here, an eval there, a regular task-tool call for a one-off judgment — and reaches for the task global to fan out. Typed results and persistent variables are what let it chain these steps into multi-stage workflows.
You need a high-confidence security audit — you'd rather miss a few issues than report a false one. Which pattern?
6
Match the Task to a Pattern
Put it together — read the request, pick the pattern it steers toward

You've seen all six. The skill is reading a request and recognizing the shape of the task — the trigger words tell you which pattern the agent will reach for. Try the six below.

Demo — match each task to the right pattern
Loading…
Score: 0 / 6
Getting started, two ways: if you're building with the Deep Agents SDK, import the code interpreter middleware and pass it in when creating your agent (the task global ships with it). Or just reach for Decode, where dynamic subagents are on by default.
What are the two ways to start using dynamic subagents?

🧬 You've got dynamic subagents

Subagents give context isolation, but orchestrating them in the agent's head breaks at scale → move the orchestration into code, where a loop covers every item → the code interpreter middleware runs it and the task global spawns subagents with typed results → trigger it with the workflow keyword → and steer the shape with six patterns: Classify & Act, Fan Out & Synthesize, Adversarial Verification, Generate & Filter, Tournament, and Loop Until Done. Attach the middleware, or reach for Decode. Now go build.

Learning Reference · Dynamic Subagents: How to Run Parallel Agents Reliably in Deep Agents — LangChain

Get new posts in your inbox

No spam — just new posts and learning pages when they ship.

Share X LinkedIn Reddit Hacker News