deepagents 0.3.5__tar.gz → 0.3.7__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.5 → deepagents-0.3.7}/PKG-INFO +52 -39
- {deepagents-0.3.5 → deepagents-0.3.7}/README.md +49 -36
- {deepagents-0.3.5 → deepagents-0.3.7}/deepagents/backends/filesystem.py +148 -22
- {deepagents-0.3.5 → deepagents-0.3.7}/deepagents/backends/sandbox.py +1 -1
- {deepagents-0.3.5 → deepagents-0.3.7}/deepagents/backends/store.py +85 -0
- {deepagents-0.3.5 → deepagents-0.3.7}/deepagents/backends/utils.py +2 -3
- {deepagents-0.3.5 → deepagents-0.3.7}/deepagents/graph.py +63 -12
- {deepagents-0.3.5 → deepagents-0.3.7}/deepagents/middleware/__init__.py +3 -1
- deepagents-0.3.7/deepagents/middleware/_utils.py +23 -0
- {deepagents-0.3.5 → deepagents-0.3.7}/deepagents/middleware/filesystem.py +223 -92
- {deepagents-0.3.5 → deepagents-0.3.7}/deepagents/middleware/memory.py +17 -15
- {deepagents-0.3.5 → deepagents-0.3.7}/deepagents/middleware/skills.py +10 -9
- {deepagents-0.3.5 → deepagents-0.3.7}/deepagents/middleware/subagents.py +100 -33
- deepagents-0.3.7/deepagents/middleware/summarization.py +758 -0
- {deepagents-0.3.5 → deepagents-0.3.7}/deepagents.egg-info/PKG-INFO +52 -39
- {deepagents-0.3.5 → deepagents-0.3.7}/deepagents.egg-info/SOURCES.txt +3 -1
- {deepagents-0.3.5 → deepagents-0.3.7}/deepagents.egg-info/requires.txt +1 -1
- {deepagents-0.3.5 → deepagents-0.3.7}/pyproject.toml +9 -3
- {deepagents-0.3.5 → deepagents-0.3.7}/deepagents/__init__.py +0 -0
- {deepagents-0.3.5 → deepagents-0.3.7}/deepagents/backends/__init__.py +0 -0
- {deepagents-0.3.5 → deepagents-0.3.7}/deepagents/backends/composite.py +0 -0
- {deepagents-0.3.5 → deepagents-0.3.7}/deepagents/backends/protocol.py +0 -0
- {deepagents-0.3.5 → deepagents-0.3.7}/deepagents/backends/state.py +0 -0
- {deepagents-0.3.5 → deepagents-0.3.7}/deepagents/middleware/patch_tool_calls.py +0 -0
- {deepagents-0.3.5 → deepagents-0.3.7}/deepagents.egg-info/dependency_links.txt +0 -0
- {deepagents-0.3.5 → deepagents-0.3.7}/deepagents.egg-info/top_level.txt +0 -0
- {deepagents-0.3.5 → deepagents-0.3.7}/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.7
|
|
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://docs.langchain.com/oss/python/langchain/overview).
|
|
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://docs.langchain.com/oss/python/integrations/providers/overview).
|
|
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,8 @@ class CompiledSubAgent(TypedDict):
|
|
|
231
236
|
runnable: Runnable
|
|
232
237
|
```
|
|
233
238
|
|
|
234
|
-
|
|
239
|
+
**`SubAgent` fields:**
|
|
240
|
+
|
|
235
241
|
- **name**: This is the name of the subagent, and how the main agent will call the subagent
|
|
236
242
|
- **description**: This is the description of the subagent that is shown to the main agent
|
|
237
243
|
- **system_prompt**: This is the system prompt used for the subagent
|
|
@@ -241,11 +247,12 @@ class CompiledSubAgent(TypedDict):
|
|
|
241
247
|
- **interrupt_on** A custom interrupt config that specifies human-in-the-loop interactions for your tools.
|
|
242
248
|
|
|
243
249
|
**CompiledSubAgent fields:**
|
|
250
|
+
|
|
244
251
|
- **name**: This is the name of the subagent, and how the main agent will call the subagent
|
|
245
252
|
- **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
|
|
253
|
+
- **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
254
|
|
|
248
|
-
#### Using SubAgent
|
|
255
|
+
#### Using `SubAgent`
|
|
249
256
|
|
|
250
257
|
```python
|
|
251
258
|
import os
|
|
@@ -284,9 +291,9 @@ agent = create_deep_agent(
|
|
|
284
291
|
)
|
|
285
292
|
```
|
|
286
293
|
|
|
287
|
-
#### Using
|
|
294
|
+
#### Using `CompiledSubAgent`
|
|
288
295
|
|
|
289
|
-
For
|
|
296
|
+
For complex workflows, use a pre-built LangGraph graph:
|
|
290
297
|
|
|
291
298
|
```python
|
|
292
299
|
# Create a custom agent graph
|
|
@@ -296,7 +303,7 @@ custom_graph = create_agent(
|
|
|
296
303
|
prompt="You are a specialized agent for data analysis..."
|
|
297
304
|
)
|
|
298
305
|
|
|
299
|
-
# Use it as a
|
|
306
|
+
# Use it as a compiled subagent
|
|
300
307
|
custom_subagent = CompiledSubAgent(
|
|
301
308
|
name="data-analyzer",
|
|
302
309
|
description="Specialized agent for complex data analysis tasks",
|
|
@@ -314,7 +321,10 @@ agent = create_deep_agent(
|
|
|
314
321
|
```
|
|
315
322
|
|
|
316
323
|
### `interrupt_on`
|
|
317
|
-
|
|
324
|
+
|
|
325
|
+
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.
|
|
326
|
+
|
|
327
|
+
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
328
|
|
|
319
329
|
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
330
|
|
|
@@ -342,6 +352,7 @@ agent = create_deep_agent(
|
|
|
342
352
|
## Deep Agents Middleware
|
|
343
353
|
|
|
344
354
|
Deep Agents are built with a modular middleware architecture. As a reminder, Deep Agents have access to:
|
|
355
|
+
|
|
345
356
|
- A planning tool
|
|
346
357
|
- A filesystem for storing context and long-term memories
|
|
347
358
|
- The ability to spawn subagents
|
|
@@ -350,11 +361,11 @@ Each of these features is implemented as separate middleware. When you create a
|
|
|
350
361
|
|
|
351
362
|
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
363
|
|
|
353
|
-
### TodoListMiddleware
|
|
364
|
+
### `TodoListMiddleware`
|
|
354
365
|
|
|
355
|
-
Planning is integral to solving complex problems. If you
|
|
366
|
+
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
367
|
|
|
357
|
-
|
|
368
|
+
`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
369
|
|
|
359
370
|
```python
|
|
360
371
|
from langchain.agents import create_agent
|
|
@@ -373,14 +384,15 @@ agent = create_agent(
|
|
|
373
384
|
)
|
|
374
385
|
```
|
|
375
386
|
|
|
376
|
-
### FilesystemMiddleware
|
|
387
|
+
### `FilesystemMiddleware`
|
|
388
|
+
|
|
389
|
+
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.
|
|
390
|
+
`FilesystemMiddleware` provides four tools to your agent to interact with both short-term and long-term memory:
|
|
377
391
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
-
|
|
381
|
-
-
|
|
382
|
-
- **write_file**: Write a new file to your filesystem
|
|
383
|
-
- **edit_file**: Edit an existing file in your filesystem
|
|
392
|
+
- `ls`: List the files in your filesystem
|
|
393
|
+
- `read_file`: Read an entire file, or a certain number of lines from a file
|
|
394
|
+
- `write_file`: Write a new file to your filesystem
|
|
395
|
+
- `edit_file`: Edit an existing file in your filesystem
|
|
384
396
|
|
|
385
397
|
```python
|
|
386
398
|
from langchain.agents import create_agent
|
|
@@ -404,9 +416,9 @@ agent = create_agent(
|
|
|
404
416
|
)
|
|
405
417
|
```
|
|
406
418
|
|
|
407
|
-
### SubAgentMiddleware
|
|
419
|
+
### `SubAgentMiddleware`
|
|
408
420
|
|
|
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.
|
|
421
|
+
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
422
|
|
|
411
423
|
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
424
|
|
|
@@ -446,14 +458,16 @@ For more complex use cases, you can also provide your own pre-built LangGraph gr
|
|
|
446
458
|
|
|
447
459
|
```python
|
|
448
460
|
# Create a custom LangGraph graph
|
|
461
|
+
# Important: Your state must include a 'messages' key
|
|
449
462
|
def create_weather_graph():
|
|
450
463
|
workflow = StateGraph(...)
|
|
451
464
|
# Build your custom graph
|
|
465
|
+
# Make sure your state schema includes 'messages'
|
|
452
466
|
return workflow.compile()
|
|
453
467
|
|
|
454
468
|
weather_graph = create_weather_graph()
|
|
455
469
|
|
|
456
|
-
# Wrap it in a CompiledSubAgent
|
|
470
|
+
# Wrap it in a `CompiledSubAgent`
|
|
457
471
|
weather_subagent = CompiledSubAgent(
|
|
458
472
|
name="weather",
|
|
459
473
|
description="This subagent can get weather in cities.",
|
|
@@ -474,13 +488,12 @@ agent = create_agent(
|
|
|
474
488
|
|
|
475
489
|
## Sync vs Async
|
|
476
490
|
|
|
477
|
-
Prior versions of deepagents separated sync and async agent factories.
|
|
491
|
+
Prior versions of deepagents separated sync and async agent factories.
|
|
478
492
|
|
|
479
493
|
`async_create_deep_agent` has been folded in to `create_deep_agent`.
|
|
480
494
|
|
|
481
495
|
**You should use `create_deep_agent` as the factory for both sync and async agents**
|
|
482
496
|
|
|
483
|
-
|
|
484
497
|
## MCP
|
|
485
498
|
|
|
486
499
|
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://docs.langchain.com/oss/python/langchain/overview).
|
|
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://docs.langchain.com/oss/python/integrations/providers/overview).
|
|
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,8 @@ class CompiledSubAgent(TypedDict):
|
|
|
212
217
|
runnable: Runnable
|
|
213
218
|
```
|
|
214
219
|
|
|
215
|
-
|
|
220
|
+
**`SubAgent` fields:**
|
|
221
|
+
|
|
216
222
|
- **name**: This is the name of the subagent, and how the main agent will call the subagent
|
|
217
223
|
- **description**: This is the description of the subagent that is shown to the main agent
|
|
218
224
|
- **system_prompt**: This is the system prompt used for the subagent
|
|
@@ -222,11 +228,12 @@ class CompiledSubAgent(TypedDict):
|
|
|
222
228
|
- **interrupt_on** A custom interrupt config that specifies human-in-the-loop interactions for your tools.
|
|
223
229
|
|
|
224
230
|
**CompiledSubAgent fields:**
|
|
231
|
+
|
|
225
232
|
- **name**: This is the name of the subagent, and how the main agent will call the subagent
|
|
226
233
|
- **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
|
|
234
|
+
- **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
235
|
|
|
229
|
-
#### Using SubAgent
|
|
236
|
+
#### Using `SubAgent`
|
|
230
237
|
|
|
231
238
|
```python
|
|
232
239
|
import os
|
|
@@ -265,9 +272,9 @@ agent = create_deep_agent(
|
|
|
265
272
|
)
|
|
266
273
|
```
|
|
267
274
|
|
|
268
|
-
#### Using
|
|
275
|
+
#### Using `CompiledSubAgent`
|
|
269
276
|
|
|
270
|
-
For
|
|
277
|
+
For complex workflows, use a pre-built LangGraph graph:
|
|
271
278
|
|
|
272
279
|
```python
|
|
273
280
|
# Create a custom agent graph
|
|
@@ -277,7 +284,7 @@ custom_graph = create_agent(
|
|
|
277
284
|
prompt="You are a specialized agent for data analysis..."
|
|
278
285
|
)
|
|
279
286
|
|
|
280
|
-
# Use it as a
|
|
287
|
+
# Use it as a compiled subagent
|
|
281
288
|
custom_subagent = CompiledSubAgent(
|
|
282
289
|
name="data-analyzer",
|
|
283
290
|
description="Specialized agent for complex data analysis tasks",
|
|
@@ -295,7 +302,10 @@ agent = create_deep_agent(
|
|
|
295
302
|
```
|
|
296
303
|
|
|
297
304
|
### `interrupt_on`
|
|
298
|
-
|
|
305
|
+
|
|
306
|
+
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.
|
|
307
|
+
|
|
308
|
+
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
309
|
|
|
300
310
|
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
311
|
|
|
@@ -323,6 +333,7 @@ agent = create_deep_agent(
|
|
|
323
333
|
## Deep Agents Middleware
|
|
324
334
|
|
|
325
335
|
Deep Agents are built with a modular middleware architecture. As a reminder, Deep Agents have access to:
|
|
336
|
+
|
|
326
337
|
- A planning tool
|
|
327
338
|
- A filesystem for storing context and long-term memories
|
|
328
339
|
- The ability to spawn subagents
|
|
@@ -331,11 +342,11 @@ Each of these features is implemented as separate middleware. When you create a
|
|
|
331
342
|
|
|
332
343
|
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
344
|
|
|
334
|
-
### TodoListMiddleware
|
|
345
|
+
### `TodoListMiddleware`
|
|
335
346
|
|
|
336
|
-
Planning is integral to solving complex problems. If you
|
|
347
|
+
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
348
|
|
|
338
|
-
|
|
349
|
+
`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
350
|
|
|
340
351
|
```python
|
|
341
352
|
from langchain.agents import create_agent
|
|
@@ -354,14 +365,15 @@ agent = create_agent(
|
|
|
354
365
|
)
|
|
355
366
|
```
|
|
356
367
|
|
|
357
|
-
### FilesystemMiddleware
|
|
368
|
+
### `FilesystemMiddleware`
|
|
369
|
+
|
|
370
|
+
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.
|
|
371
|
+
`FilesystemMiddleware` provides four tools to your agent to interact with both short-term and long-term memory:
|
|
358
372
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
-
|
|
362
|
-
-
|
|
363
|
-
- **write_file**: Write a new file to your filesystem
|
|
364
|
-
- **edit_file**: Edit an existing file in your filesystem
|
|
373
|
+
- `ls`: List the files in your filesystem
|
|
374
|
+
- `read_file`: Read an entire file, or a certain number of lines from a file
|
|
375
|
+
- `write_file`: Write a new file to your filesystem
|
|
376
|
+
- `edit_file`: Edit an existing file in your filesystem
|
|
365
377
|
|
|
366
378
|
```python
|
|
367
379
|
from langchain.agents import create_agent
|
|
@@ -385,9 +397,9 @@ agent = create_agent(
|
|
|
385
397
|
)
|
|
386
398
|
```
|
|
387
399
|
|
|
388
|
-
### SubAgentMiddleware
|
|
400
|
+
### `SubAgentMiddleware`
|
|
389
401
|
|
|
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.
|
|
402
|
+
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
403
|
|
|
392
404
|
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
405
|
|
|
@@ -427,14 +439,16 @@ For more complex use cases, you can also provide your own pre-built LangGraph gr
|
|
|
427
439
|
|
|
428
440
|
```python
|
|
429
441
|
# Create a custom LangGraph graph
|
|
442
|
+
# Important: Your state must include a 'messages' key
|
|
430
443
|
def create_weather_graph():
|
|
431
444
|
workflow = StateGraph(...)
|
|
432
445
|
# Build your custom graph
|
|
446
|
+
# Make sure your state schema includes 'messages'
|
|
433
447
|
return workflow.compile()
|
|
434
448
|
|
|
435
449
|
weather_graph = create_weather_graph()
|
|
436
450
|
|
|
437
|
-
# Wrap it in a CompiledSubAgent
|
|
451
|
+
# Wrap it in a `CompiledSubAgent`
|
|
438
452
|
weather_subagent = CompiledSubAgent(
|
|
439
453
|
name="weather",
|
|
440
454
|
description="This subagent can get weather in cities.",
|
|
@@ -455,13 +469,12 @@ agent = create_agent(
|
|
|
455
469
|
|
|
456
470
|
## Sync vs Async
|
|
457
471
|
|
|
458
|
-
Prior versions of deepagents separated sync and async agent factories.
|
|
472
|
+
Prior versions of deepagents separated sync and async agent factories.
|
|
459
473
|
|
|
460
474
|
`async_create_deep_agent` has been folded in to `create_deep_agent`.
|
|
461
475
|
|
|
462
476
|
**You should use `create_deep_agent` as the factory for both sync and async agents**
|
|
463
477
|
|
|
464
|
-
|
|
465
478
|
## MCP
|
|
466
479
|
|
|
467
480
|
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).
|