deepagents 0.3.4__tar.gz → 0.3.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {deepagents-0.3.4 → deepagents-0.3.6}/PKG-INFO +50 -39
- {deepagents-0.3.4 → deepagents-0.3.6}/README.md +47 -36
- {deepagents-0.3.4 → deepagents-0.3.6}/deepagents/backends/utils.py +1 -2
- {deepagents-0.3.4 → deepagents-0.3.6}/deepagents/graph.py +22 -5
- {deepagents-0.3.4 → deepagents-0.3.6}/deepagents/middleware/filesystem.py +98 -32
- {deepagents-0.3.4 → deepagents-0.3.6}/deepagents/middleware/memory.py +0 -1
- {deepagents-0.3.4 → deepagents-0.3.6}/deepagents/middleware/subagents.py +53 -13
- {deepagents-0.3.4 → deepagents-0.3.6}/deepagents.egg-info/PKG-INFO +50 -39
- {deepagents-0.3.4 → deepagents-0.3.6}/deepagents.egg-info/requires.txt +1 -1
- deepagents-0.3.6/pyproject.toml +140 -0
- deepagents-0.3.4/pyproject.toml +0 -100
- {deepagents-0.3.4 → deepagents-0.3.6}/deepagents/__init__.py +0 -0
- {deepagents-0.3.4 → deepagents-0.3.6}/deepagents/backends/__init__.py +0 -0
- {deepagents-0.3.4 → deepagents-0.3.6}/deepagents/backends/composite.py +0 -0
- {deepagents-0.3.4 → deepagents-0.3.6}/deepagents/backends/filesystem.py +0 -0
- {deepagents-0.3.4 → deepagents-0.3.6}/deepagents/backends/protocol.py +0 -0
- {deepagents-0.3.4 → deepagents-0.3.6}/deepagents/backends/sandbox.py +0 -0
- {deepagents-0.3.4 → deepagents-0.3.6}/deepagents/backends/state.py +0 -0
- {deepagents-0.3.4 → deepagents-0.3.6}/deepagents/backends/store.py +0 -0
- {deepagents-0.3.4 → deepagents-0.3.6}/deepagents/middleware/__init__.py +0 -0
- {deepagents-0.3.4 → deepagents-0.3.6}/deepagents/middleware/patch_tool_calls.py +0 -0
- {deepagents-0.3.4 → deepagents-0.3.6}/deepagents/middleware/skills.py +0 -0
- {deepagents-0.3.4 → deepagents-0.3.6}/deepagents.egg-info/SOURCES.txt +0 -0
- {deepagents-0.3.4 → deepagents-0.3.6}/deepagents.egg-info/dependency_links.txt +0 -0
- {deepagents-0.3.4 → deepagents-0.3.6}/deepagents.egg-info/top_level.txt +0 -0
- {deepagents-0.3.4 → deepagents-0.3.6}/setup.cfg +0 -0
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: deepagents
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.6
|
|
4
4
|
Summary: General purpose 'deep agent' with sub-agent spawning, todo list capabilities, and mock file system. Built on LangGraph.
|
|
5
5
|
License: MIT
|
|
6
6
|
Project-URL: Homepage, https://docs.langchain.com/oss/python/deepagents/overview
|
|
7
7
|
Project-URL: Documentation, https://reference.langchain.com/python/deepagents/
|
|
8
8
|
Project-URL: Source, https://github.com/langchain-ai/deepagents
|
|
9
|
-
Project-URL: Twitter, https://x.com/
|
|
9
|
+
Project-URL: Twitter, https://x.com/LangChain
|
|
10
10
|
Project-URL: Slack, https://www.langchain.com/join-community
|
|
11
11
|
Project-URL: Reddit, https://www.reddit.com/r/LangChain/
|
|
12
12
|
Requires-Python: <4.0,>=3.11
|
|
13
13
|
Description-Content-Type: text/markdown
|
|
14
14
|
Requires-Dist: langchain-core<2.0.0,>=1.2.6
|
|
15
|
-
Requires-Dist: langchain<2.0.0,>=1.2.
|
|
15
|
+
Requires-Dist: langchain<2.0.0,>=1.2.4
|
|
16
16
|
Requires-Dist: langchain-anthropic<2.0.0,>=1.3.1
|
|
17
17
|
Requires-Dist: langchain-google-genai<5.0.0,>=4.1.3
|
|
18
18
|
Requires-Dist: wcmatch
|
|
19
19
|
|
|
20
20
|
# 🧠🤖Deep Agents
|
|
21
21
|
|
|
22
|
-
Using an LLM to call tools in a loop is the simplest form of an agent.
|
|
23
|
-
This architecture, however, can yield agents that are “shallow” and fail to plan and act over longer, more complex tasks.
|
|
22
|
+
Using an LLM to call tools in a loop is the simplest form of an agent.
|
|
23
|
+
This architecture, however, can yield agents that are “shallow” and fail to plan and act over longer, more complex tasks.
|
|
24
24
|
|
|
25
25
|
Applications like “Deep Research”, "Manus", and “Claude Code” have gotten around this limitation by implementing a combination of four things:
|
|
26
26
|
a **planning tool**, **sub agents**, access to a **file system**, and a **detailed prompt**.
|
|
@@ -46,7 +46,9 @@ poetry add deepagents
|
|
|
46
46
|
|
|
47
47
|
## Usage
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
> **Note:** `deepagents` requires using a LLM that supports [tool calling](https://python.langchain.com/docs/concepts/tool_calling/).
|
|
50
|
+
|
|
51
|
+
This example uses [Tavily](https://tavily.com/) as an example search provider, but you can substitute any search API (e.g., DuckDuckGo, SerpAPI, Brave Search). To run the example below, you will need to `pip install tavily-python`.
|
|
50
52
|
|
|
51
53
|
Make sure to set `TAVILY_API_KEY` in your environment. You can generate one [here](https://www.tavily.com/).
|
|
52
54
|
|
|
@@ -100,21 +102,22 @@ The agent created with `create_deep_agent` is just a LangGraph graph - so you ca
|
|
|
100
102
|
in the same way you would any LangGraph agent.
|
|
101
103
|
|
|
102
104
|
## Core Capabilities
|
|
105
|
+
|
|
103
106
|
**Planning & Task Decomposition**
|
|
104
107
|
|
|
105
|
-
|
|
108
|
+
Deep Agents include a built-in `write_todos` tool that enables agents to break down complex tasks into discrete steps, track progress, and adapt plans as new information emerges.
|
|
106
109
|
|
|
107
110
|
**Context Management**
|
|
108
111
|
|
|
109
|
-
|
|
112
|
+
File system tools (`ls`, `read_file`, `write_file`, `edit_file`, `glob`, `grep`) allow agents to offload large context to memory, preventing context window overflow and enabling work with variable-length tool results.
|
|
110
113
|
|
|
111
114
|
**Subagent Spawning**
|
|
112
115
|
|
|
113
|
-
|
|
116
|
+
A built-in `task` tool enables agents to spawn specialized subagents for context isolation. This keeps the main agent's context clean while still going deep on specific subtasks.
|
|
114
117
|
|
|
115
118
|
**Long-term Memory**
|
|
116
119
|
|
|
117
|
-
|
|
120
|
+
Extend agents with persistent memory across threads using LangGraph's `BaseStore`. Agents can save and retrieve information from previous conversations.
|
|
118
121
|
|
|
119
122
|
## Customizing Deep Agents
|
|
120
123
|
|
|
@@ -122,19 +125,20 @@ There are several parameters you can pass to `create_deep_agent` to create your
|
|
|
122
125
|
|
|
123
126
|
### `model`
|
|
124
127
|
|
|
125
|
-
By default, `deepagents` uses `
|
|
128
|
+
By default, `deepagents` uses `claude-sonnet-4-5-20250929`. You can customize this by passing any [LangChain model object](https://python.langchain.com/docs/integrations/chat/).
|
|
129
|
+
|
|
130
|
+
> **Tip:** Use the `provider:model` format (e.g., `openai:gpt-5`) to quickly switch between models. See the [reference](https://reference.langchain.com/python/langchain/models/#langchain.chat_models.init_chat_model(model)) for more info.
|
|
126
131
|
|
|
127
132
|
```python
|
|
128
133
|
from langchain.chat_models import init_chat_model
|
|
129
134
|
from deepagents import create_deep_agent
|
|
130
135
|
|
|
131
|
-
model = init_chat_model("openai:gpt-
|
|
132
|
-
agent = create_deep_agent(
|
|
133
|
-
model=model,
|
|
134
|
-
)
|
|
136
|
+
model = init_chat_model(model="openai:gpt-5")
|
|
137
|
+
agent = create_deep_agent(model=model)
|
|
135
138
|
```
|
|
136
139
|
|
|
137
140
|
### `system_prompt`
|
|
141
|
+
|
|
138
142
|
Deep Agents come with a built-in system prompt. This is relatively detailed prompt that is heavily based on and inspired by [attempts](https://github.com/kn1026/cc/blob/main/claudecode.md) to [replicate](https://github.com/asgeirtj/system_prompts_leaks/blob/main/Anthropic/claude-code.md)
|
|
139
143
|
Claude Code's system prompt. It was made more general purpose than Claude Code's system prompt. The default prompt contains detailed instructions for how to use the built-in planning tool, file system tools, and sub agents.
|
|
140
144
|
|
|
@@ -153,7 +157,7 @@ agent = create_deep_agent(
|
|
|
153
157
|
|
|
154
158
|
### `tools`
|
|
155
159
|
|
|
156
|
-
|
|
160
|
+
In addition to custom tools you provide, `deepagents` include built-in tools for planning (`write_todos`), file management (`ls`, `read_file`, `write_file`, `edit_file`, `glob`, `grep`), and subagent spawning (`task`).
|
|
157
161
|
|
|
158
162
|
```python
|
|
159
163
|
import os
|
|
@@ -183,7 +187,8 @@ agent = create_deep_agent(
|
|
|
183
187
|
```
|
|
184
188
|
|
|
185
189
|
### `middleware`
|
|
186
|
-
|
|
190
|
+
|
|
191
|
+
`create_deep_agent` is implemented with middleware that can be customized. You can provide additional middleware to extend functionality, add tools, or implement custom hooks.
|
|
187
192
|
|
|
188
193
|
```python
|
|
189
194
|
from langchain_core.tools import tool
|
|
@@ -231,7 +236,7 @@ class CompiledSubAgent(TypedDict):
|
|
|
231
236
|
runnable: Runnable
|
|
232
237
|
```
|
|
233
238
|
|
|
234
|
-
|
|
239
|
+
**`SubAgent` fields:**
|
|
235
240
|
- **name**: This is the name of the subagent, and how the main agent will call the subagent
|
|
236
241
|
- **description**: This is the description of the subagent that is shown to the main agent
|
|
237
242
|
- **system_prompt**: This is the system prompt used for the subagent
|
|
@@ -243,9 +248,9 @@ class CompiledSubAgent(TypedDict):
|
|
|
243
248
|
**CompiledSubAgent fields:**
|
|
244
249
|
- **name**: This is the name of the subagent, and how the main agent will call the subagent
|
|
245
250
|
- **description**: This is the description of the subagent that is shown to the main agent
|
|
246
|
-
- **runnable**: A pre-built LangGraph graph/agent that will be used as the subagent
|
|
251
|
+
- **runnable**: A pre-built LangGraph graph/agent that will be used as the subagent. **Important:** The runnable's state schema must include a `messages` key. This is required for the subagent to communicate results back to the main agent.
|
|
247
252
|
|
|
248
|
-
#### Using SubAgent
|
|
253
|
+
#### Using `SubAgent`
|
|
249
254
|
|
|
250
255
|
```python
|
|
251
256
|
import os
|
|
@@ -284,9 +289,9 @@ agent = create_deep_agent(
|
|
|
284
289
|
)
|
|
285
290
|
```
|
|
286
291
|
|
|
287
|
-
#### Using
|
|
292
|
+
#### Using `CompiledSubAgent`
|
|
288
293
|
|
|
289
|
-
For
|
|
294
|
+
For complex workflows, use a pre-built LangGraph graph:
|
|
290
295
|
|
|
291
296
|
```python
|
|
292
297
|
# Create a custom agent graph
|
|
@@ -296,7 +301,7 @@ custom_graph = create_agent(
|
|
|
296
301
|
prompt="You are a specialized agent for data analysis..."
|
|
297
302
|
)
|
|
298
303
|
|
|
299
|
-
# Use it as a
|
|
304
|
+
# Use it as a compiled subagent
|
|
300
305
|
custom_subagent = CompiledSubAgent(
|
|
301
306
|
name="data-analyzer",
|
|
302
307
|
description="Specialized agent for complex data analysis tasks",
|
|
@@ -314,7 +319,10 @@ agent = create_deep_agent(
|
|
|
314
319
|
```
|
|
315
320
|
|
|
316
321
|
### `interrupt_on`
|
|
317
|
-
|
|
322
|
+
|
|
323
|
+
The harness can pause agent execution at specified tool calls to allow human approval or modification. This feature is opt-in via the `interrupt_on` parameter.
|
|
324
|
+
|
|
325
|
+
Pass `interrupt_on` to `create_deep_agent` with a mapping of tool names to interrupt configurations. Example: `interrupt_on={"edit_file": True}` pauses before every edit.
|
|
318
326
|
|
|
319
327
|
These tool configs are passed to our prebuilt [HITL middleware](https://docs.langchain.com/oss/python/langchain/middleware#human-in-the-loop) so that the agent pauses execution and waits for feedback from the user before executing configured tools.
|
|
320
328
|
|
|
@@ -342,6 +350,7 @@ agent = create_deep_agent(
|
|
|
342
350
|
## Deep Agents Middleware
|
|
343
351
|
|
|
344
352
|
Deep Agents are built with a modular middleware architecture. As a reminder, Deep Agents have access to:
|
|
353
|
+
|
|
345
354
|
- A planning tool
|
|
346
355
|
- A filesystem for storing context and long-term memories
|
|
347
356
|
- The ability to spawn subagents
|
|
@@ -350,11 +359,11 @@ Each of these features is implemented as separate middleware. When you create a
|
|
|
350
359
|
|
|
351
360
|
Middleware is a composable concept, and you can choose to add as many or as few middleware to an agent depending on your use case. That means that you can also use any of the aforementioned middleware independently!
|
|
352
361
|
|
|
353
|
-
### TodoListMiddleware
|
|
362
|
+
### `TodoListMiddleware`
|
|
354
363
|
|
|
355
|
-
Planning is integral to solving complex problems. If you
|
|
364
|
+
Planning is integral to solving complex problems. If you've used Claude Code recently, you'll notice how it writes out a to-do list before tackling complex, multi-part tasks. You'll also notice how it can adapt and update this to-do list on the fly as more information comes in.
|
|
356
365
|
|
|
357
|
-
|
|
366
|
+
`TodoListMiddleware` provides your agent with a tool specifically for updating this to-do list. Before, and while it executes a multi-part task, the agent is prompted to use the `write_todos` tool to keep track of what it's doing, and what still needs to be done.
|
|
358
367
|
|
|
359
368
|
```python
|
|
360
369
|
from langchain.agents import create_agent
|
|
@@ -373,14 +382,15 @@ agent = create_agent(
|
|
|
373
382
|
)
|
|
374
383
|
```
|
|
375
384
|
|
|
376
|
-
### FilesystemMiddleware
|
|
385
|
+
### `FilesystemMiddleware`
|
|
386
|
+
|
|
387
|
+
Context engineering is one of the main challenges in building effective agents. This can be particularly hard when using tools that can return variable length results (e.g., `web_search`, RAG), as long tool results can quickly fill up your context window.
|
|
388
|
+
`FilesystemMiddleware` provides four tools to your agent to interact with both short-term and long-term memory:
|
|
377
389
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
-
|
|
381
|
-
-
|
|
382
|
-
- **write_file**: Write a new file to your filesystem
|
|
383
|
-
- **edit_file**: Edit an existing file in your filesystem
|
|
390
|
+
- `ls`: List the files in your filesystem
|
|
391
|
+
- `read_file`: Read an entire file, or a certain number of lines from a file
|
|
392
|
+
- `write_file`: Write a new file to your filesystem
|
|
393
|
+
- `edit_file`: Edit an existing file in your filesystem
|
|
384
394
|
|
|
385
395
|
```python
|
|
386
396
|
from langchain.agents import create_agent
|
|
@@ -404,9 +414,9 @@ agent = create_agent(
|
|
|
404
414
|
)
|
|
405
415
|
```
|
|
406
416
|
|
|
407
|
-
### SubAgentMiddleware
|
|
417
|
+
### `SubAgentMiddleware`
|
|
408
418
|
|
|
409
|
-
Handing off tasks to subagents is a great way to isolate context, keeping the context window of the main (supervisor) agent clean while still going deep on a task.
|
|
419
|
+
Handing off tasks to subagents is a great way to isolate context, keeping the context window of the main (supervisor) agent clean while still going deep on a task. `SubAgentMiddleware` allows you to supply subagents through a `task` tool.
|
|
410
420
|
|
|
411
421
|
A subagent is defined with a name, description, system prompt, and tools. You can also provide a subagent with a custom model, or with additional middleware. This can be particularly useful when you want to give the subagent an additional state key to share with the main agent.
|
|
412
422
|
|
|
@@ -446,14 +456,16 @@ For more complex use cases, you can also provide your own pre-built LangGraph gr
|
|
|
446
456
|
|
|
447
457
|
```python
|
|
448
458
|
# Create a custom LangGraph graph
|
|
459
|
+
# Important: Your state must include a 'messages' key
|
|
449
460
|
def create_weather_graph():
|
|
450
461
|
workflow = StateGraph(...)
|
|
451
462
|
# Build your custom graph
|
|
463
|
+
# Make sure your state schema includes 'messages'
|
|
452
464
|
return workflow.compile()
|
|
453
465
|
|
|
454
466
|
weather_graph = create_weather_graph()
|
|
455
467
|
|
|
456
|
-
# Wrap it in a CompiledSubAgent
|
|
468
|
+
# Wrap it in a `CompiledSubAgent`
|
|
457
469
|
weather_subagent = CompiledSubAgent(
|
|
458
470
|
name="weather",
|
|
459
471
|
description="This subagent can get weather in cities.",
|
|
@@ -474,13 +486,12 @@ agent = create_agent(
|
|
|
474
486
|
|
|
475
487
|
## Sync vs Async
|
|
476
488
|
|
|
477
|
-
Prior versions of deepagents separated sync and async agent factories.
|
|
489
|
+
Prior versions of deepagents separated sync and async agent factories.
|
|
478
490
|
|
|
479
491
|
`async_create_deep_agent` has been folded in to `create_deep_agent`.
|
|
480
492
|
|
|
481
493
|
**You should use `create_deep_agent` as the factory for both sync and async agents**
|
|
482
494
|
|
|
483
|
-
|
|
484
495
|
## MCP
|
|
485
496
|
|
|
486
497
|
The `deepagents` library can be ran with MCP tools. This can be achieved by using the [Langchain MCP Adapter library](https://github.com/langchain-ai/langchain-mcp-adapters).
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# 🧠🤖Deep Agents
|
|
2
2
|
|
|
3
|
-
Using an LLM to call tools in a loop is the simplest form of an agent.
|
|
4
|
-
This architecture, however, can yield agents that are “shallow” and fail to plan and act over longer, more complex tasks.
|
|
3
|
+
Using an LLM to call tools in a loop is the simplest form of an agent.
|
|
4
|
+
This architecture, however, can yield agents that are “shallow” and fail to plan and act over longer, more complex tasks.
|
|
5
5
|
|
|
6
6
|
Applications like “Deep Research”, "Manus", and “Claude Code” have gotten around this limitation by implementing a combination of four things:
|
|
7
7
|
a **planning tool**, **sub agents**, access to a **file system**, and a **detailed prompt**.
|
|
@@ -27,7 +27,9 @@ poetry add deepagents
|
|
|
27
27
|
|
|
28
28
|
## Usage
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
> **Note:** `deepagents` requires using a LLM that supports [tool calling](https://python.langchain.com/docs/concepts/tool_calling/).
|
|
31
|
+
|
|
32
|
+
This example uses [Tavily](https://tavily.com/) as an example search provider, but you can substitute any search API (e.g., DuckDuckGo, SerpAPI, Brave Search). To run the example below, you will need to `pip install tavily-python`.
|
|
31
33
|
|
|
32
34
|
Make sure to set `TAVILY_API_KEY` in your environment. You can generate one [here](https://www.tavily.com/).
|
|
33
35
|
|
|
@@ -81,21 +83,22 @@ The agent created with `create_deep_agent` is just a LangGraph graph - so you ca
|
|
|
81
83
|
in the same way you would any LangGraph agent.
|
|
82
84
|
|
|
83
85
|
## Core Capabilities
|
|
86
|
+
|
|
84
87
|
**Planning & Task Decomposition**
|
|
85
88
|
|
|
86
|
-
|
|
89
|
+
Deep Agents include a built-in `write_todos` tool that enables agents to break down complex tasks into discrete steps, track progress, and adapt plans as new information emerges.
|
|
87
90
|
|
|
88
91
|
**Context Management**
|
|
89
92
|
|
|
90
|
-
|
|
93
|
+
File system tools (`ls`, `read_file`, `write_file`, `edit_file`, `glob`, `grep`) allow agents to offload large context to memory, preventing context window overflow and enabling work with variable-length tool results.
|
|
91
94
|
|
|
92
95
|
**Subagent Spawning**
|
|
93
96
|
|
|
94
|
-
|
|
97
|
+
A built-in `task` tool enables agents to spawn specialized subagents for context isolation. This keeps the main agent's context clean while still going deep on specific subtasks.
|
|
95
98
|
|
|
96
99
|
**Long-term Memory**
|
|
97
100
|
|
|
98
|
-
|
|
101
|
+
Extend agents with persistent memory across threads using LangGraph's `BaseStore`. Agents can save and retrieve information from previous conversations.
|
|
99
102
|
|
|
100
103
|
## Customizing Deep Agents
|
|
101
104
|
|
|
@@ -103,19 +106,20 @@ There are several parameters you can pass to `create_deep_agent` to create your
|
|
|
103
106
|
|
|
104
107
|
### `model`
|
|
105
108
|
|
|
106
|
-
By default, `deepagents` uses `
|
|
109
|
+
By default, `deepagents` uses `claude-sonnet-4-5-20250929`. You can customize this by passing any [LangChain model object](https://python.langchain.com/docs/integrations/chat/).
|
|
110
|
+
|
|
111
|
+
> **Tip:** Use the `provider:model` format (e.g., `openai:gpt-5`) to quickly switch between models. See the [reference](https://reference.langchain.com/python/langchain/models/#langchain.chat_models.init_chat_model(model)) for more info.
|
|
107
112
|
|
|
108
113
|
```python
|
|
109
114
|
from langchain.chat_models import init_chat_model
|
|
110
115
|
from deepagents import create_deep_agent
|
|
111
116
|
|
|
112
|
-
model = init_chat_model("openai:gpt-
|
|
113
|
-
agent = create_deep_agent(
|
|
114
|
-
model=model,
|
|
115
|
-
)
|
|
117
|
+
model = init_chat_model(model="openai:gpt-5")
|
|
118
|
+
agent = create_deep_agent(model=model)
|
|
116
119
|
```
|
|
117
120
|
|
|
118
121
|
### `system_prompt`
|
|
122
|
+
|
|
119
123
|
Deep Agents come with a built-in system prompt. This is relatively detailed prompt that is heavily based on and inspired by [attempts](https://github.com/kn1026/cc/blob/main/claudecode.md) to [replicate](https://github.com/asgeirtj/system_prompts_leaks/blob/main/Anthropic/claude-code.md)
|
|
120
124
|
Claude Code's system prompt. It was made more general purpose than Claude Code's system prompt. The default prompt contains detailed instructions for how to use the built-in planning tool, file system tools, and sub agents.
|
|
121
125
|
|
|
@@ -134,7 +138,7 @@ agent = create_deep_agent(
|
|
|
134
138
|
|
|
135
139
|
### `tools`
|
|
136
140
|
|
|
137
|
-
|
|
141
|
+
In addition to custom tools you provide, `deepagents` include built-in tools for planning (`write_todos`), file management (`ls`, `read_file`, `write_file`, `edit_file`, `glob`, `grep`), and subagent spawning (`task`).
|
|
138
142
|
|
|
139
143
|
```python
|
|
140
144
|
import os
|
|
@@ -164,7 +168,8 @@ agent = create_deep_agent(
|
|
|
164
168
|
```
|
|
165
169
|
|
|
166
170
|
### `middleware`
|
|
167
|
-
|
|
171
|
+
|
|
172
|
+
`create_deep_agent` is implemented with middleware that can be customized. You can provide additional middleware to extend functionality, add tools, or implement custom hooks.
|
|
168
173
|
|
|
169
174
|
```python
|
|
170
175
|
from langchain_core.tools import tool
|
|
@@ -212,7 +217,7 @@ class CompiledSubAgent(TypedDict):
|
|
|
212
217
|
runnable: Runnable
|
|
213
218
|
```
|
|
214
219
|
|
|
215
|
-
|
|
220
|
+
**`SubAgent` fields:**
|
|
216
221
|
- **name**: This is the name of the subagent, and how the main agent will call the subagent
|
|
217
222
|
- **description**: This is the description of the subagent that is shown to the main agent
|
|
218
223
|
- **system_prompt**: This is the system prompt used for the subagent
|
|
@@ -224,9 +229,9 @@ class CompiledSubAgent(TypedDict):
|
|
|
224
229
|
**CompiledSubAgent fields:**
|
|
225
230
|
- **name**: This is the name of the subagent, and how the main agent will call the subagent
|
|
226
231
|
- **description**: This is the description of the subagent that is shown to the main agent
|
|
227
|
-
- **runnable**: A pre-built LangGraph graph/agent that will be used as the subagent
|
|
232
|
+
- **runnable**: A pre-built LangGraph graph/agent that will be used as the subagent. **Important:** The runnable's state schema must include a `messages` key. This is required for the subagent to communicate results back to the main agent.
|
|
228
233
|
|
|
229
|
-
#### Using SubAgent
|
|
234
|
+
#### Using `SubAgent`
|
|
230
235
|
|
|
231
236
|
```python
|
|
232
237
|
import os
|
|
@@ -265,9 +270,9 @@ agent = create_deep_agent(
|
|
|
265
270
|
)
|
|
266
271
|
```
|
|
267
272
|
|
|
268
|
-
#### Using
|
|
273
|
+
#### Using `CompiledSubAgent`
|
|
269
274
|
|
|
270
|
-
For
|
|
275
|
+
For complex workflows, use a pre-built LangGraph graph:
|
|
271
276
|
|
|
272
277
|
```python
|
|
273
278
|
# Create a custom agent graph
|
|
@@ -277,7 +282,7 @@ custom_graph = create_agent(
|
|
|
277
282
|
prompt="You are a specialized agent for data analysis..."
|
|
278
283
|
)
|
|
279
284
|
|
|
280
|
-
# Use it as a
|
|
285
|
+
# Use it as a compiled subagent
|
|
281
286
|
custom_subagent = CompiledSubAgent(
|
|
282
287
|
name="data-analyzer",
|
|
283
288
|
description="Specialized agent for complex data analysis tasks",
|
|
@@ -295,7 +300,10 @@ agent = create_deep_agent(
|
|
|
295
300
|
```
|
|
296
301
|
|
|
297
302
|
### `interrupt_on`
|
|
298
|
-
|
|
303
|
+
|
|
304
|
+
The harness can pause agent execution at specified tool calls to allow human approval or modification. This feature is opt-in via the `interrupt_on` parameter.
|
|
305
|
+
|
|
306
|
+
Pass `interrupt_on` to `create_deep_agent` with a mapping of tool names to interrupt configurations. Example: `interrupt_on={"edit_file": True}` pauses before every edit.
|
|
299
307
|
|
|
300
308
|
These tool configs are passed to our prebuilt [HITL middleware](https://docs.langchain.com/oss/python/langchain/middleware#human-in-the-loop) so that the agent pauses execution and waits for feedback from the user before executing configured tools.
|
|
301
309
|
|
|
@@ -323,6 +331,7 @@ agent = create_deep_agent(
|
|
|
323
331
|
## Deep Agents Middleware
|
|
324
332
|
|
|
325
333
|
Deep Agents are built with a modular middleware architecture. As a reminder, Deep Agents have access to:
|
|
334
|
+
|
|
326
335
|
- A planning tool
|
|
327
336
|
- A filesystem for storing context and long-term memories
|
|
328
337
|
- The ability to spawn subagents
|
|
@@ -331,11 +340,11 @@ Each of these features is implemented as separate middleware. When you create a
|
|
|
331
340
|
|
|
332
341
|
Middleware is a composable concept, and you can choose to add as many or as few middleware to an agent depending on your use case. That means that you can also use any of the aforementioned middleware independently!
|
|
333
342
|
|
|
334
|
-
### TodoListMiddleware
|
|
343
|
+
### `TodoListMiddleware`
|
|
335
344
|
|
|
336
|
-
Planning is integral to solving complex problems. If you
|
|
345
|
+
Planning is integral to solving complex problems. If you've used Claude Code recently, you'll notice how it writes out a to-do list before tackling complex, multi-part tasks. You'll also notice how it can adapt and update this to-do list on the fly as more information comes in.
|
|
337
346
|
|
|
338
|
-
|
|
347
|
+
`TodoListMiddleware` provides your agent with a tool specifically for updating this to-do list. Before, and while it executes a multi-part task, the agent is prompted to use the `write_todos` tool to keep track of what it's doing, and what still needs to be done.
|
|
339
348
|
|
|
340
349
|
```python
|
|
341
350
|
from langchain.agents import create_agent
|
|
@@ -354,14 +363,15 @@ agent = create_agent(
|
|
|
354
363
|
)
|
|
355
364
|
```
|
|
356
365
|
|
|
357
|
-
### FilesystemMiddleware
|
|
366
|
+
### `FilesystemMiddleware`
|
|
367
|
+
|
|
368
|
+
Context engineering is one of the main challenges in building effective agents. This can be particularly hard when using tools that can return variable length results (e.g., `web_search`, RAG), as long tool results can quickly fill up your context window.
|
|
369
|
+
`FilesystemMiddleware` provides four tools to your agent to interact with both short-term and long-term memory:
|
|
358
370
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
-
|
|
362
|
-
-
|
|
363
|
-
- **write_file**: Write a new file to your filesystem
|
|
364
|
-
- **edit_file**: Edit an existing file in your filesystem
|
|
371
|
+
- `ls`: List the files in your filesystem
|
|
372
|
+
- `read_file`: Read an entire file, or a certain number of lines from a file
|
|
373
|
+
- `write_file`: Write a new file to your filesystem
|
|
374
|
+
- `edit_file`: Edit an existing file in your filesystem
|
|
365
375
|
|
|
366
376
|
```python
|
|
367
377
|
from langchain.agents import create_agent
|
|
@@ -385,9 +395,9 @@ agent = create_agent(
|
|
|
385
395
|
)
|
|
386
396
|
```
|
|
387
397
|
|
|
388
|
-
### SubAgentMiddleware
|
|
398
|
+
### `SubAgentMiddleware`
|
|
389
399
|
|
|
390
|
-
Handing off tasks to subagents is a great way to isolate context, keeping the context window of the main (supervisor) agent clean while still going deep on a task.
|
|
400
|
+
Handing off tasks to subagents is a great way to isolate context, keeping the context window of the main (supervisor) agent clean while still going deep on a task. `SubAgentMiddleware` allows you to supply subagents through a `task` tool.
|
|
391
401
|
|
|
392
402
|
A subagent is defined with a name, description, system prompt, and tools. You can also provide a subagent with a custom model, or with additional middleware. This can be particularly useful when you want to give the subagent an additional state key to share with the main agent.
|
|
393
403
|
|
|
@@ -427,14 +437,16 @@ For more complex use cases, you can also provide your own pre-built LangGraph gr
|
|
|
427
437
|
|
|
428
438
|
```python
|
|
429
439
|
# Create a custom LangGraph graph
|
|
440
|
+
# Important: Your state must include a 'messages' key
|
|
430
441
|
def create_weather_graph():
|
|
431
442
|
workflow = StateGraph(...)
|
|
432
443
|
# Build your custom graph
|
|
444
|
+
# Make sure your state schema includes 'messages'
|
|
433
445
|
return workflow.compile()
|
|
434
446
|
|
|
435
447
|
weather_graph = create_weather_graph()
|
|
436
448
|
|
|
437
|
-
# Wrap it in a CompiledSubAgent
|
|
449
|
+
# Wrap it in a `CompiledSubAgent`
|
|
438
450
|
weather_subagent = CompiledSubAgent(
|
|
439
451
|
name="weather",
|
|
440
452
|
description="This subagent can get weather in cities.",
|
|
@@ -455,13 +467,12 @@ agent = create_agent(
|
|
|
455
467
|
|
|
456
468
|
## Sync vs Async
|
|
457
469
|
|
|
458
|
-
Prior versions of deepagents separated sync and async agent factories.
|
|
470
|
+
Prior versions of deepagents separated sync and async agent factories.
|
|
459
471
|
|
|
460
472
|
`async_create_deep_agent` has been folded in to `create_deep_agent`.
|
|
461
473
|
|
|
462
474
|
**You should use `create_deep_agent` as the factory for both sync and async agents**
|
|
463
475
|
|
|
464
|
-
|
|
465
476
|
## MCP
|
|
466
477
|
|
|
467
478
|
The `deepagents` library can be ran with MCP tools. This can be achieved by using the [Langchain MCP Adapter library](https://github.com/langchain-ai/langchain-mcp-adapters).
|
|
@@ -12,8 +12,7 @@ from typing import Any, Literal
|
|
|
12
12
|
|
|
13
13
|
import wcmatch.glob as wcglob
|
|
14
14
|
|
|
15
|
-
from deepagents.backends.protocol import FileInfo as _FileInfo
|
|
16
|
-
from deepagents.backends.protocol import GrepMatch as _GrepMatch
|
|
15
|
+
from deepagents.backends.protocol import FileInfo as _FileInfo, GrepMatch as _GrepMatch
|
|
17
16
|
|
|
18
17
|
EMPTY_CONTENT_WARNING = "System reminder: File exists but has empty contents"
|
|
19
18
|
MAX_LINE_LENGTH = 10000
|
|
@@ -62,18 +62,28 @@ def create_deep_agent(
|
|
|
62
62
|
) -> CompiledStateGraph:
|
|
63
63
|
"""Create a deep agent.
|
|
64
64
|
|
|
65
|
+
Deep agents require a LLM that supports tool calling.
|
|
66
|
+
|
|
65
67
|
This agent will by default have access to a tool to write todos (`write_todos`),
|
|
66
68
|
seven file and execution tools: `ls`, `read_file`, `write_file`, `edit_file`, `glob`, `grep`, `execute`,
|
|
67
|
-
and a tool to call subagents.
|
|
69
|
+
and a tool to call subagents (`task`).
|
|
68
70
|
|
|
69
71
|
The `execute` tool allows running shell commands if the backend implements `SandboxBackendProtocol`.
|
|
70
72
|
For non-sandbox backends, the `execute` tool will return an error message.
|
|
71
73
|
|
|
72
74
|
Args:
|
|
73
|
-
model: The model to use.
|
|
75
|
+
model: The model to use.
|
|
76
|
+
|
|
77
|
+
Defaults to `claude-sonnet-4-5-20250929`.
|
|
78
|
+
|
|
79
|
+
Use the `provider:model` format (e.g., `openai:gpt-5`) to quickly switch between models.
|
|
74
80
|
tools: The tools the agent should have access to.
|
|
75
|
-
|
|
76
|
-
|
|
81
|
+
|
|
82
|
+
In addition to custom tools you provide, deep agents include built-in tools for planning,
|
|
83
|
+
file management, and subagent spawning.
|
|
84
|
+
system_prompt: The additional instructions the agent should have.
|
|
85
|
+
|
|
86
|
+
Will go in the system prompt.
|
|
77
87
|
middleware: Additional middleware to apply after standard middleware.
|
|
78
88
|
subagents: The subagents to use.
|
|
79
89
|
|
|
@@ -93,7 +103,10 @@ def create_deep_agent(
|
|
|
93
103
|
to the backend's `root_dir`. Later sources override earlier ones for skills with the
|
|
94
104
|
same name (last one wins).
|
|
95
105
|
memory: Optional list of memory file paths (`AGENTS.md` files) to load
|
|
96
|
-
(e.g., `["/memory/AGENTS.md"]`).
|
|
106
|
+
(e.g., `["/memory/AGENTS.md"]`).
|
|
107
|
+
|
|
108
|
+
Display names are automatically derived from paths.
|
|
109
|
+
|
|
97
110
|
Memory is loaded at agent startup and added into the system prompt.
|
|
98
111
|
response_format: A structured output response format to use for the agent.
|
|
99
112
|
context_schema: The schema of the deep agent.
|
|
@@ -104,6 +117,10 @@ def create_deep_agent(
|
|
|
104
117
|
Pass either a `Backend` instance or a callable factory like `lambda rt: StateBackend(rt)`.
|
|
105
118
|
For execution support, use a backend that implements `SandboxBackendProtocol`.
|
|
106
119
|
interrupt_on: Mapping of tool names to interrupt configs.
|
|
120
|
+
|
|
121
|
+
Pass to pause agent execution at specified tool calls for human approval or modification.
|
|
122
|
+
|
|
123
|
+
Example: `interrupt_on={"edit_file": True}` pauses before every edit.
|
|
107
124
|
debug: Whether to enable debug mode. Passed through to `create_agent`.
|
|
108
125
|
name: The name of the agent. Passed through to `create_agent`.
|
|
109
126
|
cache: The cache to use for the agent. Passed through to `create_agent`.
|