You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+2-135Lines changed: 2 additions & 135 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,145 +7,12 @@ Using an LLM to call tools in a loop is the simplest form of an agent. This arch
7
7
> ![TIP]
8
8
> Looking for the Python version of this package? See [here: hwchase17/deepagents](https://github.com/hwchase17/deepagents)
9
9
10
-
**Acknowledgements**: This project was primarily inspired by Claude Code, and initially was largely an attempt to see what made Claude Code general purpose, and make it even more so.
11
-
12
10
## Installation
13
11
14
12
```bash
15
13
yarn add deepagents
16
14
```
17
15
18
-
## Usage
19
-
20
-
(To run the example below, you will need to install tavily: `yarn add @langchain/tavily`)
21
-
22
-
```typescript
23
-
import { TavilySearch } from"@langchain/tavily";
24
-
import { createDeepAgent } from"deepagents";
25
-
26
-
// Search tool to use to do research
27
-
const internetSearch =newTavilySearch({
28
-
maxResults: 5,
29
-
tavilyApiKey: process.env.TAVILY_API_KEY,
30
-
});
31
-
32
-
// Prompt prefix to steer the agent to be an expert researcher
33
-
const researchInstructions =`You are an expert researcher. Your job is to conduct thorough research, and then write a polished report.
34
-
35
-
You have access to a few tools.
36
-
37
-
## \`internet_search\`
38
-
39
-
Use this to run an internet search for a given query. You can specify the number of results, the topic, and whether raw content should be included.
40
-
`;
41
-
42
-
// Create the agent
43
-
const agent =createDeepAgent({
44
-
tools: [internetSearch],
45
-
instructions: researchInstructions,
46
-
});
47
-
48
-
// Invoke the agent
49
-
const result =awaitagent.invoke({
50
-
messages: [{ role: "user", content: "what is langgraph?" }]
51
-
});
52
-
```
53
-
54
-
See `examples/research-agent.ts` for a more complex example.
55
-
56
-
The agent created with `createDeepAgent` is just a LangGraph graph - so you can interact with it (streaming, human-in-the-loop, memory, studio) in the same way you would any LangGraph agent.
57
-
58
-
## Creating a custom deep agent
59
-
60
-
There are three parameters you can pass to `createDeepAgent` to create your own custom deep agent.
61
-
62
-
### tools (Required)
63
-
64
-
The first argument to `createDeepAgent` is tools. This should be a list of LangChain tools. The agent (and any subagents) will have access to these tools.
65
-
66
-
### instructions (Required)
67
-
68
-
The second argument to `createDeepAgent` is instructions. This will serve as part of the prompt of the deep agent. Note that there is a built in system prompt as well, so this is not the entire prompt the agent will see.
69
-
70
-
### subagents (Optional)
71
-
72
-
A keyword-only argument to `createDeepAgent` is subagents. This can be used to specify any custom subagents this deep agent will have access to. You can read more about why you would want to use subagents [here](https://langchain-ai.github.io/deepagents/subagents/)
73
-
74
-
`subagents` should be a list of objects, where each object follows this schema:
75
-
76
-
```typescript
77
-
interfaceSubAgent {
78
-
name:string;
79
-
description:string;
80
-
prompt:string;
81
-
tools?:string[];
82
-
}
83
-
```
84
-
85
-
-**name**: This is the name of the subagent, and how the main agent will call the subagent
86
-
-**description**: This is the description of the subagent that is shown to the main agent
87
-
-**prompt**: This is the prompt used for the subagent
88
-
-**tools**: This is the list of tools that the subagent has access to. By default will have access to all tools passed in, as well as all built-in tools.
89
-
90
-
To use it looks like:
91
-
92
-
```typescript
93
-
const researchSubAgent = {
94
-
name: "research-agent",
95
-
description: "Used to research more in depth questions",
96
-
prompt: subResearchPrompt,
97
-
};
98
-
99
-
const subagents = [researchSubAgent];
100
-
101
-
const agent =createDeepAgent({
102
-
tools,
103
-
instructions: prompt,
104
-
subagents
105
-
});
106
-
```
107
-
108
-
### model (Optional)
109
-
110
-
By default, `deepagents` will use "claude-sonnet-4-20250514". If you want to use a different model, you can pass a LangChain model object.
111
-
112
-
## Deep Agent Details
113
-
114
-
The below components are built into `deepagents` and helps make it work for deep tasks off-the-shelf.
115
-
116
-
### System Prompt
117
-
118
-
`deepagents` comes with a built-in system prompt. This is relatively detailed prompt that is heavily based on and inspired by attempts to replicate Claude Code's system prompt. It was made more general purpose than Claude Code's system prompt. This contains detailed instructions for how to use the built-in planning tool, file system tools, and sub agents. Note that part of this system prompt can be customized
119
-
120
-
Without this default system prompt - the agent would not be nearly as successful at going as it is. The importance of prompting for creating a "deep" agent cannot be understated.
121
-
122
-
### Planning Tool
123
-
124
-
`deepagents` comes with a built-in planning tool. This planning tool is very simple and is based on ClaudeCode's TodoWrite tool. This tool doesn't actually do anything - it is just a way for the agent to come up with a plan, and then have that in the context to help keep it on track.
125
-
126
-
### File System Tools
127
-
128
-
`deepagents` comes with four built-in file system tools: `ls`, `edit_file`, `read_file`, `write_file`. These do not actually use a file system - rather, they mock out a file system using LangGraph's State object. This means you can easily run many of these agents on the same machine without worrying that they will edit the same underlying files.
129
-
130
-
Right now the "file system" will only be one level deep (no sub directories).
131
-
132
-
These files can be passed in (and also retrieved) by using the `files` key in the LangGraph State object.
133
-
134
-
```typescript
135
-
const agent =createDeepAgent({ ... });
136
-
137
-
const result =awaitagent.invoke({
138
-
messages: [...],
139
-
// Pass in files to the agent using this key
140
-
// files: {"foo.txt": "foo", ...}
141
-
});
142
-
143
-
// Access any files afterwards like this
144
-
result.files;
145
-
```
146
-
147
-
### Sub Agents
148
-
149
-
`deepagents` comes with the built-in ability to call sub agents (based on Claude Code). It has access to a general-purpose subagent at all times - this is a subagent with the same instructions as the main agent and all the tools that is has access to. You can also specify custom sub agents with their own instructions and tools.
16
+
## Learn more
150
17
151
-
Sub agents are useful for "context quarantine" (to help not pollute the overall context of the main agent) as well as custom instructions.
18
+
For more information, check out our docs: [https://docs.langchain.com/labs/deep-agents/overview](https://docs.langchain.com/labs/deep-agents/overview)
0 commit comments