deepagents 0.0.0-rc
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.
- package/LICENSE +21 -0
- package/README.md +151 -0
- package/dist/graph.d.ts +126 -0
- package/dist/graph.js +62 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +12 -0
- package/dist/model.d.ts +17 -0
- package/dist/model.js +22 -0
- package/dist/prompts.d.ts +31 -0
- package/dist/prompts.js +279 -0
- package/dist/state.d.ts +37 -0
- package/dist/state.js +53 -0
- package/dist/subAgent.d.ts +41 -0
- package/dist/subAgent.js +120 -0
- package/dist/tools.d.ts +144 -0
- package/dist/tools.js +205 -0
- package/dist/types.d.ts +49 -0
- package/dist/types.js +9 -0
- package/package.json +72 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) LangChain, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# 🧠🤖Deep Agents
|
|
2
|
+
|
|
3
|
+
Using an LLM to call tools in a loop is the simplest form of an agent. This architecture, however, can yield agents that are "shallow" and fail to plan and act over longer, more complex tasks. Applications like "Deep Research", "Manus", and "Claude Code" have gotten around this limitation by implementing a combination of four things: a planning tool, sub agents, access to a file system, and a detailed prompt.
|
|
4
|
+
|
|
5
|
+
`deepagents` is a TypeScript package that implements these in a general purpose way so that you can easily create a Deep Agent for your application.
|
|
6
|
+
|
|
7
|
+
> ![TIP]
|
|
8
|
+
> Looking for the Python version of this package? See [here: hwchase17/deepagents](https://github.com/hwchase17/deepagents)
|
|
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
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
yarn add deepagentsjs
|
|
16
|
+
```
|
|
17
|
+
|
|
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 "deepagentsjs";
|
|
25
|
+
|
|
26
|
+
// Search tool to use to do research
|
|
27
|
+
const internetSearch = new TavilySearch({
|
|
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 = await agent.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
|
+
interface SubAgent {
|
|
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 = await agent.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.
|
|
150
|
+
|
|
151
|
+
Sub agents are useful for "context quarantine" (to help not pollute the overall context of the main agent) as well as custom instructions.
|
package/dist/graph.d.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main createDeepAgent function for Deep Agents
|
|
3
|
+
*
|
|
4
|
+
* Main entry point for creating deep agents with TypeScript types for all parameters:
|
|
5
|
+
* tools, instructions, model, subagents, and stateSchema. Combines built-in tools with
|
|
6
|
+
* provided tools, creates task tool using createTaskTool(), and returns createReactAgent
|
|
7
|
+
* with proper configuration. Ensures exact parameter matching and behavior with Python version.
|
|
8
|
+
*/
|
|
9
|
+
import type { CreateDeepAgentParams } from "./types.js";
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
/**
|
|
12
|
+
* Create a Deep Agent with TypeScript types for all parameters.
|
|
13
|
+
* Combines built-in tools with provided tools, creates task tool using createTaskTool(),
|
|
14
|
+
* and returns createReactAgent with proper configuration.
|
|
15
|
+
* Ensures exact parameter matching and behavior with Python version.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createDeepAgent<StateSchema extends z.ZodObject<any, any, any, any, any>>(params?: CreateDeepAgentParams<StateSchema>): import("@langchain/langgraph").CompiledStateGraph<import("@langchain/langgraph").StateType<import("@langchain/langgraph/zod").InteropZodToStateDefinition<z.ZodObject<{
|
|
18
|
+
messages: import("@langchain/langgraph/zod").ReducedZodChannel<z.ZodType<import("@langchain/core/messages").BaseMessage[], z.ZodTypeDef, import("@langchain/core/messages").BaseMessage[]>, import("@langchain/core/utils/types").InteropZodType<import("@langchain/langgraph").Messages>>;
|
|
19
|
+
} & {
|
|
20
|
+
todos: import("@langchain/langgraph/zod").ReducedZodChannel<z.ZodType<import("./types.js").Todo[], z.ZodTypeDef, import("./types.js").Todo[]>, import("@langchain/core/utils/types").InteropZodType<import("./types.js").Todo[] | null | undefined>>;
|
|
21
|
+
files: import("@langchain/langgraph/zod").ReducedZodChannel<z.ZodType<Record<string, string>, z.ZodTypeDef, Record<string, string>>, import("@langchain/core/utils/types").InteropZodType<Record<string, string> | null | undefined>>;
|
|
22
|
+
}, "strip", z.ZodTypeAny, {
|
|
23
|
+
todos: import("./types.js").Todo[];
|
|
24
|
+
files: Record<string, string>;
|
|
25
|
+
messages: import("@langchain/core/messages").BaseMessage[];
|
|
26
|
+
}, {
|
|
27
|
+
todos: import("./types.js").Todo[];
|
|
28
|
+
files: Record<string, string>;
|
|
29
|
+
messages: import("@langchain/core/messages").BaseMessage[];
|
|
30
|
+
}>, {
|
|
31
|
+
messages: import("@langchain/langgraph/zod").ReducedZodChannel<z.ZodType<import("@langchain/core/messages").BaseMessage[], z.ZodTypeDef, import("@langchain/core/messages").BaseMessage[]>, import("@langchain/core/utils/types").InteropZodType<import("@langchain/langgraph").Messages>>;
|
|
32
|
+
todos: import("@langchain/langgraph/zod").ReducedZodChannel<z.ZodType<import("./types.js").Todo[], z.ZodTypeDef, import("./types.js").Todo[]>, import("@langchain/core/utils/types").InteropZodType<import("./types.js").Todo[] | null | undefined>>;
|
|
33
|
+
files: import("@langchain/langgraph/zod").ReducedZodChannel<z.ZodType<Record<string, string>, z.ZodTypeDef, Record<string, string>>, import("@langchain/core/utils/types").InteropZodType<Record<string, string> | null | undefined>>;
|
|
34
|
+
}>> | import("@langchain/langgraph").StateType<import("@langchain/langgraph/zod").InteropZodToStateDefinition<z.ZodObject<{} & {
|
|
35
|
+
[x: string]: any;
|
|
36
|
+
}, "strip", z.ZodTypeAny, {
|
|
37
|
+
[x: string]: any;
|
|
38
|
+
}, {
|
|
39
|
+
[x: string]: any;
|
|
40
|
+
}>, {
|
|
41
|
+
[x: string]: any;
|
|
42
|
+
}>>, import("@langchain/langgraph").UpdateType<import("@langchain/langgraph/zod").InteropZodToStateDefinition<z.ZodObject<{
|
|
43
|
+
messages: import("@langchain/langgraph/zod").ReducedZodChannel<z.ZodType<import("@langchain/core/messages").BaseMessage[], z.ZodTypeDef, import("@langchain/core/messages").BaseMessage[]>, import("@langchain/core/utils/types").InteropZodType<import("@langchain/langgraph").Messages>>;
|
|
44
|
+
} & {
|
|
45
|
+
todos: import("@langchain/langgraph/zod").ReducedZodChannel<z.ZodType<import("./types.js").Todo[], z.ZodTypeDef, import("./types.js").Todo[]>, import("@langchain/core/utils/types").InteropZodType<import("./types.js").Todo[] | null | undefined>>;
|
|
46
|
+
files: import("@langchain/langgraph/zod").ReducedZodChannel<z.ZodType<Record<string, string>, z.ZodTypeDef, Record<string, string>>, import("@langchain/core/utils/types").InteropZodType<Record<string, string> | null | undefined>>;
|
|
47
|
+
}, "strip", z.ZodTypeAny, {
|
|
48
|
+
todos: import("./types.js").Todo[];
|
|
49
|
+
files: Record<string, string>;
|
|
50
|
+
messages: import("@langchain/core/messages").BaseMessage[];
|
|
51
|
+
}, {
|
|
52
|
+
todos: import("./types.js").Todo[];
|
|
53
|
+
files: Record<string, string>;
|
|
54
|
+
messages: import("@langchain/core/messages").BaseMessage[];
|
|
55
|
+
}>, {
|
|
56
|
+
messages: import("@langchain/langgraph/zod").ReducedZodChannel<z.ZodType<import("@langchain/core/messages").BaseMessage[], z.ZodTypeDef, import("@langchain/core/messages").BaseMessage[]>, import("@langchain/core/utils/types").InteropZodType<import("@langchain/langgraph").Messages>>;
|
|
57
|
+
todos: import("@langchain/langgraph/zod").ReducedZodChannel<z.ZodType<import("./types.js").Todo[], z.ZodTypeDef, import("./types.js").Todo[]>, import("@langchain/core/utils/types").InteropZodType<import("./types.js").Todo[] | null | undefined>>;
|
|
58
|
+
files: import("@langchain/langgraph/zod").ReducedZodChannel<z.ZodType<Record<string, string>, z.ZodTypeDef, Record<string, string>>, import("@langchain/core/utils/types").InteropZodType<Record<string, string> | null | undefined>>;
|
|
59
|
+
}>> | import("@langchain/langgraph").UpdateType<import("@langchain/langgraph/zod").InteropZodToStateDefinition<z.ZodObject<{} & {
|
|
60
|
+
[x: string]: any;
|
|
61
|
+
}, "strip", z.ZodTypeAny, {
|
|
62
|
+
[x: string]: any;
|
|
63
|
+
}, {
|
|
64
|
+
[x: string]: any;
|
|
65
|
+
}>, {
|
|
66
|
+
[x: string]: any;
|
|
67
|
+
}>>, any, {
|
|
68
|
+
messages: import("@langchain/langgraph").BinaryOperatorAggregate<import("@langchain/core/messages").BaseMessage[], import("@langchain/langgraph").Messages>;
|
|
69
|
+
} & (import("@langchain/langgraph/zod").InteropZodToStateDefinition<z.ZodObject<{
|
|
70
|
+
messages: import("@langchain/langgraph/zod").ReducedZodChannel<z.ZodType<import("@langchain/core/messages").BaseMessage[], z.ZodTypeDef, import("@langchain/core/messages").BaseMessage[]>, import("@langchain/core/utils/types").InteropZodType<import("@langchain/langgraph").Messages>>;
|
|
71
|
+
} & {
|
|
72
|
+
todos: import("@langchain/langgraph/zod").ReducedZodChannel<z.ZodType<import("./types.js").Todo[], z.ZodTypeDef, import("./types.js").Todo[]>, import("@langchain/core/utils/types").InteropZodType<import("./types.js").Todo[] | null | undefined>>;
|
|
73
|
+
files: import("@langchain/langgraph/zod").ReducedZodChannel<z.ZodType<Record<string, string>, z.ZodTypeDef, Record<string, string>>, import("@langchain/core/utils/types").InteropZodType<Record<string, string> | null | undefined>>;
|
|
74
|
+
}, "strip", z.ZodTypeAny, {
|
|
75
|
+
todos: import("./types.js").Todo[];
|
|
76
|
+
files: Record<string, string>;
|
|
77
|
+
messages: import("@langchain/core/messages").BaseMessage[];
|
|
78
|
+
}, {
|
|
79
|
+
todos: import("./types.js").Todo[];
|
|
80
|
+
files: Record<string, string>;
|
|
81
|
+
messages: import("@langchain/core/messages").BaseMessage[];
|
|
82
|
+
}>, {
|
|
83
|
+
messages: import("@langchain/langgraph/zod").ReducedZodChannel<z.ZodType<import("@langchain/core/messages").BaseMessage[], z.ZodTypeDef, import("@langchain/core/messages").BaseMessage[]>, import("@langchain/core/utils/types").InteropZodType<import("@langchain/langgraph").Messages>>;
|
|
84
|
+
todos: import("@langchain/langgraph/zod").ReducedZodChannel<z.ZodType<import("./types.js").Todo[], z.ZodTypeDef, import("./types.js").Todo[]>, import("@langchain/core/utils/types").InteropZodType<import("./types.js").Todo[] | null | undefined>>;
|
|
85
|
+
files: import("@langchain/langgraph/zod").ReducedZodChannel<z.ZodType<Record<string, string>, z.ZodTypeDef, Record<string, string>>, import("@langchain/core/utils/types").InteropZodType<Record<string, string> | null | undefined>>;
|
|
86
|
+
}> | import("@langchain/langgraph/zod").InteropZodToStateDefinition<z.ZodObject<{} & {
|
|
87
|
+
[x: string]: any;
|
|
88
|
+
}, "strip", z.ZodTypeAny, {
|
|
89
|
+
[x: string]: any;
|
|
90
|
+
}, {
|
|
91
|
+
[x: string]: any;
|
|
92
|
+
}>, {
|
|
93
|
+
[x: string]: any;
|
|
94
|
+
}>), {
|
|
95
|
+
messages: import("@langchain/langgraph").BinaryOperatorAggregate<import("@langchain/core/messages").BaseMessage[], import("@langchain/langgraph").Messages>;
|
|
96
|
+
structuredResponse: {
|
|
97
|
+
(): import("@langchain/langgraph").LastValue<Record<string, any>>;
|
|
98
|
+
(annotation: import("@langchain/langgraph").SingleReducer<Record<string, any>, Record<string, any>>): import("@langchain/langgraph").BinaryOperatorAggregate<Record<string, any>, Record<string, any>>;
|
|
99
|
+
Root: <S extends import("@langchain/langgraph").StateDefinition>(sd: S) => import("@langchain/langgraph").AnnotationRoot<S>;
|
|
100
|
+
};
|
|
101
|
+
} & (import("@langchain/langgraph/zod").InteropZodToStateDefinition<z.ZodObject<{
|
|
102
|
+
messages: import("@langchain/langgraph/zod").ReducedZodChannel<z.ZodType<import("@langchain/core/messages").BaseMessage[], z.ZodTypeDef, import("@langchain/core/messages").BaseMessage[]>, import("@langchain/core/utils/types").InteropZodType<import("@langchain/langgraph").Messages>>;
|
|
103
|
+
} & {
|
|
104
|
+
todos: import("@langchain/langgraph/zod").ReducedZodChannel<z.ZodType<import("./types.js").Todo[], z.ZodTypeDef, import("./types.js").Todo[]>, import("@langchain/core/utils/types").InteropZodType<import("./types.js").Todo[] | null | undefined>>;
|
|
105
|
+
files: import("@langchain/langgraph/zod").ReducedZodChannel<z.ZodType<Record<string, string>, z.ZodTypeDef, Record<string, string>>, import("@langchain/core/utils/types").InteropZodType<Record<string, string> | null | undefined>>;
|
|
106
|
+
}, "strip", z.ZodTypeAny, {
|
|
107
|
+
todos: import("./types.js").Todo[];
|
|
108
|
+
files: Record<string, string>;
|
|
109
|
+
messages: import("@langchain/core/messages").BaseMessage[];
|
|
110
|
+
}, {
|
|
111
|
+
todos: import("./types.js").Todo[];
|
|
112
|
+
files: Record<string, string>;
|
|
113
|
+
messages: import("@langchain/core/messages").BaseMessage[];
|
|
114
|
+
}>, {
|
|
115
|
+
messages: import("@langchain/langgraph/zod").ReducedZodChannel<z.ZodType<import("@langchain/core/messages").BaseMessage[], z.ZodTypeDef, import("@langchain/core/messages").BaseMessage[]>, import("@langchain/core/utils/types").InteropZodType<import("@langchain/langgraph").Messages>>;
|
|
116
|
+
todos: import("@langchain/langgraph/zod").ReducedZodChannel<z.ZodType<import("./types.js").Todo[], z.ZodTypeDef, import("./types.js").Todo[]>, import("@langchain/core/utils/types").InteropZodType<import("./types.js").Todo[] | null | undefined>>;
|
|
117
|
+
files: import("@langchain/langgraph/zod").ReducedZodChannel<z.ZodType<Record<string, string>, z.ZodTypeDef, Record<string, string>>, import("@langchain/core/utils/types").InteropZodType<Record<string, string> | null | undefined>>;
|
|
118
|
+
}> | import("@langchain/langgraph/zod").InteropZodToStateDefinition<z.ZodObject<{} & {
|
|
119
|
+
[x: string]: any;
|
|
120
|
+
}, "strip", z.ZodTypeAny, {
|
|
121
|
+
[x: string]: any;
|
|
122
|
+
}, {
|
|
123
|
+
[x: string]: any;
|
|
124
|
+
}>, {
|
|
125
|
+
[x: string]: any;
|
|
126
|
+
}>), import("@langchain/langgraph").StateDefinition>;
|
package/dist/graph.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main createDeepAgent function for Deep Agents
|
|
3
|
+
*
|
|
4
|
+
* Main entry point for creating deep agents with TypeScript types for all parameters:
|
|
5
|
+
* tools, instructions, model, subagents, and stateSchema. Combines built-in tools with
|
|
6
|
+
* provided tools, creates task tool using createTaskTool(), and returns createReactAgent
|
|
7
|
+
* with proper configuration. Ensures exact parameter matching and behavior with Python version.
|
|
8
|
+
*/
|
|
9
|
+
// import "@langchain/anthropic/zod";
|
|
10
|
+
import { createReactAgent } from "@langchain/langgraph/prebuilt";
|
|
11
|
+
import { createTaskTool } from "./subAgent.js";
|
|
12
|
+
import { getDefaultModel } from "./model.js";
|
|
13
|
+
import { writeTodos, readFile, writeFile, editFile, ls } from "./tools.js";
|
|
14
|
+
import { DeepAgentState } from "./state.js";
|
|
15
|
+
/**
|
|
16
|
+
* Built-in tools that are always available in Deep Agents
|
|
17
|
+
*/
|
|
18
|
+
const BUILTIN_TOOLS = [
|
|
19
|
+
writeTodos,
|
|
20
|
+
readFile,
|
|
21
|
+
writeFile,
|
|
22
|
+
editFile,
|
|
23
|
+
ls,
|
|
24
|
+
];
|
|
25
|
+
/**
|
|
26
|
+
* Create a Deep Agent with TypeScript types for all parameters.
|
|
27
|
+
* Combines built-in tools with provided tools, creates task tool using createTaskTool(),
|
|
28
|
+
* and returns createReactAgent with proper configuration.
|
|
29
|
+
* Ensures exact parameter matching and behavior with Python version.
|
|
30
|
+
*/
|
|
31
|
+
export function createDeepAgent(params = {}) {
|
|
32
|
+
const { tools = [], instructions, model = getDefaultModel(), subagents = [], } = params;
|
|
33
|
+
const stateSchema = params.stateSchema
|
|
34
|
+
? DeepAgentState.extend(params.stateSchema.shape)
|
|
35
|
+
: DeepAgentState;
|
|
36
|
+
// Combine built-in tools with provided tools
|
|
37
|
+
const allTools = [...BUILTIN_TOOLS, ...tools];
|
|
38
|
+
// Create task tool using createTaskTool() if subagents are provided
|
|
39
|
+
if (subagents.length > 0) {
|
|
40
|
+
// Create tools map for task tool creation
|
|
41
|
+
const toolsMap = {};
|
|
42
|
+
for (const tool of allTools) {
|
|
43
|
+
if (tool.name) {
|
|
44
|
+
toolsMap[tool.name] = tool;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const taskTool = createTaskTool({
|
|
48
|
+
subagents,
|
|
49
|
+
tools: toolsMap,
|
|
50
|
+
model,
|
|
51
|
+
stateSchema,
|
|
52
|
+
});
|
|
53
|
+
allTools.push(taskTool);
|
|
54
|
+
}
|
|
55
|
+
// Return createReactAgent with proper configuration
|
|
56
|
+
return createReactAgent({
|
|
57
|
+
llm: model,
|
|
58
|
+
tools: allTools,
|
|
59
|
+
stateSchema,
|
|
60
|
+
messageModifier: instructions,
|
|
61
|
+
});
|
|
62
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep Agents TypeScript Implementation
|
|
3
|
+
*
|
|
4
|
+
* A TypeScript port of the Python Deep Agents library for building controllable AI agents with LangGraph.
|
|
5
|
+
* This implementation maintains 1:1 compatibility with the Python version.
|
|
6
|
+
*/
|
|
7
|
+
export { createDeepAgent } from "./graph.js";
|
|
8
|
+
export { getDefaultModel } from "./model.js";
|
|
9
|
+
export { createTaskTool } from "./subAgent.js";
|
|
10
|
+
export { writeTodos, readFile, writeFile, editFile, ls } from "./tools.js";
|
|
11
|
+
export { DeepAgentState, fileReducer } from "./state.js";
|
|
12
|
+
export { WRITE_TODOS_DESCRIPTION, TASK_DESCRIPTION_PREFIX, TASK_DESCRIPTION_SUFFIX, EDIT_DESCRIPTION, TOOL_DESCRIPTION, } from "./prompts.js";
|
|
13
|
+
export type { SubAgent, Todo, DeepAgentStateType, CreateDeepAgentParams, CreateTaskToolParams, TodoStatus, } from "./types.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep Agents TypeScript Implementation
|
|
3
|
+
*
|
|
4
|
+
* A TypeScript port of the Python Deep Agents library for building controllable AI agents with LangGraph.
|
|
5
|
+
* This implementation maintains 1:1 compatibility with the Python version.
|
|
6
|
+
*/
|
|
7
|
+
export { createDeepAgent } from "./graph.js";
|
|
8
|
+
export { getDefaultModel } from "./model.js";
|
|
9
|
+
export { createTaskTool } from "./subAgent.js";
|
|
10
|
+
export { writeTodos, readFile, writeFile, editFile, ls } from "./tools.js";
|
|
11
|
+
export { DeepAgentState, fileReducer } from "./state.js";
|
|
12
|
+
export { WRITE_TODOS_DESCRIPTION, TASK_DESCRIPTION_PREFIX, TASK_DESCRIPTION_SUFFIX, EDIT_DESCRIPTION, TOOL_DESCRIPTION, } from "./prompts.js";
|
package/dist/model.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model configuration for Deep Agents
|
|
3
|
+
*
|
|
4
|
+
* Default model configuration matching the Python implementation exactly.
|
|
5
|
+
* Returns a ChatAnthropic instance configured with claude-sonnet-4-20250514 and maxTokens: 4096.
|
|
6
|
+
*/
|
|
7
|
+
import { LanguageModelLike } from "./types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Get the default model for Deep Agents
|
|
10
|
+
*
|
|
11
|
+
* Returns a ChatAnthropic instance configured exactly like the Python version:
|
|
12
|
+
* - model: "claude-sonnet-4-20250514"
|
|
13
|
+
* - maxTokens: 4096
|
|
14
|
+
*
|
|
15
|
+
* @returns ChatAnthropic instance with default configuration
|
|
16
|
+
*/
|
|
17
|
+
export declare function getDefaultModel(): LanguageModelLike;
|
package/dist/model.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model configuration for Deep Agents
|
|
3
|
+
*
|
|
4
|
+
* Default model configuration matching the Python implementation exactly.
|
|
5
|
+
* Returns a ChatAnthropic instance configured with claude-sonnet-4-20250514 and maxTokens: 4096.
|
|
6
|
+
*/
|
|
7
|
+
import { ChatAnthropic } from "@langchain/anthropic";
|
|
8
|
+
/**
|
|
9
|
+
* Get the default model for Deep Agents
|
|
10
|
+
*
|
|
11
|
+
* Returns a ChatAnthropic instance configured exactly like the Python version:
|
|
12
|
+
* - model: "claude-sonnet-4-20250514"
|
|
13
|
+
* - maxTokens: 4096
|
|
14
|
+
*
|
|
15
|
+
* @returns ChatAnthropic instance with default configuration
|
|
16
|
+
*/
|
|
17
|
+
export function getDefaultModel() {
|
|
18
|
+
return new ChatAnthropic({
|
|
19
|
+
model: "claude-sonnet-4-20250514",
|
|
20
|
+
maxTokens: 4096,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt constants for Deep Agents
|
|
3
|
+
*
|
|
4
|
+
* All prompt strings ported from Python implementation with exact string content and formatting
|
|
5
|
+
* to ensure 1:1 compatibility with the Python version.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Description for the write_todos tool
|
|
9
|
+
* Ported exactly from Python WRITE_TODOS_DESCRIPTION
|
|
10
|
+
*/
|
|
11
|
+
export declare const WRITE_TODOS_DESCRIPTION = "Use this tool to create and manage a structured task list for your current work session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user. It also helps the user understand the progress of the task and overall progress of their requests.\n\nWhen to Use This Tool\nUse this tool proactively in these scenarios:\n\nComplex multi-step tasks - When a task requires 3 or more distinct steps or actions\nNon-trivial and complex tasks - Tasks that require careful planning or multiple operations\nUser explicitly requests todo list - When the user directly asks you to use the todo list\nUser provides multiple tasks - When users provide a list of things to be done (numbered or comma-separated)\nAfter receiving new instructions - Immediately capture user requirements as todos\nWhen you start working on a task - Mark it as in_progress BEFORE beginning work. Ideally you should only have one todo as in_progress at a time\nAfter completing a task - Mark it as completed and add any new follow-up tasks discovered during implementation\nWhen NOT to Use This Tool\nSkip using this tool when:\n\nThere is only a single, straightforward task\nThe task is trivial and tracking it provides no organizational benefit\nThe task can be completed in less than 3 trivial steps\nThe task is purely conversational or informational\nNOTE that you should not use this tool if there is only one trivial task to do. In this case you are better off just doing the task directly.\n\nExamples of When to Use the Todo List\n<example>\nUser: I want to add a dark mode toggle to the application settings. Make sure you run the tests and build when you're done!\nAssistant: I'll help add a dark mode toggle to your application settings. Let me create a todo list to track this implementation.\n*Creates todo list with the following items:*\n1. Create dark mode toggle component in Settings page\n2. Add dark mode state management (context/store)\n3. Implement CSS-in-JS styles for dark theme\n4. Update existing components to support theme switching\n5. Run tests and build process, addressing any failures or errors that occur\n*Begins working on the first task*\n<reasoning>\nThe assistant used the todo list because:\n1. Adding dark mode is a multi-step feature requiring UI, state management, and styling changes\n2. The user explicitly requested tests and build be run afterward\n3. The assistant inferred that tests and build need to pass by adding \"Ensure tests and build succeed\" as the final task\n</reasoning>\n</example>\n<example>\nUser: Help me plan a comprehensive marketing campaign for our new product launch, including social media, email marketing, and press releases.\nAssistant: I'll help you plan a comprehensive marketing campaign for your product launch. Let me create a todo list to organize all the components.\n*Creates todo list with the following items:*\n1. Define target audience and key messaging\n2. Create social media content calendar and posting schedule\n3. Design email marketing sequence and automation flows\n4. Draft press release and identify media contacts\n5. Set up tracking and analytics for campaign performance\n6. Create visual assets and brand materials\n7. Coordinate launch timeline and deliverables\n*Begins working on the first task*\n<reasoning>\nThe assistant used the todo list because:\n1. Marketing campaign planning involves multiple distinct channels and activities\n2. Each component requires careful coordination and planning\n3. The systematic approach ensures all aspects of the launch are covered\n4. Progress tracking helps maintain timeline and deliverables\n</reasoning>\n</example>\n<example>\nUser: Help me rename the function getCwd to getCurrentWorkingDirectory across my project\nAssistant: Let me first search through your codebase to find all occurrences of 'getCwd'.\n*Uses search tools to locate all instances of getCwd in the codebase*\nAssistant: I've found 15 instances of 'getCwd' across 8 different files. Let me create a todo list to track these changes.\n*Creates todo list with specific items for each file that needs updating*\n<reasoning>\nThe assistant used the todo list because:\n1. First, the assistant searched to understand the scope of the task\n2. Upon finding multiple occurrences across different files, it determined this was a complex task with multiple steps\n3. The todo list helps ensure every instance is tracked and updated systematically\n4. This approach prevents missing any occurrences and maintains consistency\n</reasoning>\n</example>\n<example>\nUser: I need help organizing my home office: decluttering the desk, setting up a filing system, organizing digital files, and creating a daily workflow.\nAssistant: I'll help you organize your home office systematically. Let me create a todo list to track each area of organization.\n*Creates todo list with items like: 1) Sort and declutter desk items, 2) Set up physical filing system for documents, 3) Organize digital files and folders, 4) Create daily workflow and productivity systems, 5) Establish maintenance routines*\nLet's start with decluttering your desk space to create a clean foundation for the other organizational systems.\n<reasoning>\nThe assistant used the todo list because:\n1. The user provided multiple distinct organizational tasks\n2. Each area requires different approaches and careful planning\n3. Home organization benefits from systematic, step-by-step completion\n4. Progress tracking ensures all areas are addressed thoroughly\n</reasoning>\n</example>\nExamples of When NOT to Use the Todo List\n<example>\nUser: How do I print 'Hello World' in Python?\nAssistant: In Python, you can print \"Hello World\" with this simple code:\n\n```python\nprint(\"Hello World\")\n```\n\nThis will output the text \"Hello World\" to the console when executed.\n<reasoning>\nThe assistant did not use the todo list because this is a single, trivial task that can be completed in one step. There's no need to track multiple tasks or steps for such a straightforward request.\n</reasoning>\n</example>\n<example>\nUser: What's the best way to water houseplants?\nAssistant: The best way to water houseplants depends on the specific plant type, but here are some general guidelines:\n\nCheck soil moisture by inserting your finger about 1-2 inches into the soil\nWater thoroughly when the top inch feels dry, allowing water to drain from the bottom\nUse room temperature water and water in the morning when possible\nAvoid overwatering, which is more harmful than underwatering for most plants\n\nDifferent plants have different needs, so it's important to research your specific varieties for optimal care.\n\n<reasoning>\nThe assistant did not use the todo list because this is an informational request with no actual tasks to complete. The user is simply asking for advice and explanation, not for the assistant to perform multiple steps or activities.\n</reasoning>\n</example>\n<example>\nUser: Can you add a comment to the calculateTotal function to explain what it does?\nAssistant: Sure, let me add a comment to the calculateTotal function to explain what it does.\n* Uses the Edit tool to add a comment to the calculateTotal function *\n<reasoning>\nThe assistant did not use the todo list because this is a single, straightforward task confined to one location. Adding a comment doesn't require tracking multiple steps or systematic organization.\n</reasoning>\n</example>\n<example>\nUser: What time is it in Tokyo right now?\nAssistant: I'll check the current time in Tokyo for you.\n\n*Searches for current time in Tokyo*\n\nThe current time in Tokyo, Japan is [current time]. Tokyo is in the Japan Standard Time (JST) zone, which is UTC+9.\n\n<reasoning>\nThe assistant did not use the todo list because this is a single information lookup with immediate results. There are no multiple steps to track or organize, making the todo list unnecessary for this straightforward request.\n</reasoning>\n</example>\nTask States and Management\nTask States: Use these states to track progress:\n\npending: Task not yet started\nin_progress: Currently working on (limit to ONE task at a time)\ncompleted: Task finished successfully\nTask Management:\n\nUpdate task status in real-time as you work\nMark tasks complete IMMEDIATELY after finishing (don't batch completions)\nOnly have ONE task in_progress at any time\nComplete current tasks before starting new ones\nRemove tasks that are no longer relevant from the list entirely\nTask Completion Requirements:\n\nONLY mark a task as completed when you have FULLY accomplished it\nIf you encounter errors, blockers, or cannot finish, keep the task as in_progress\nWhen blocked, create a new task describing what needs to be resolved\nNever mark a task as completed if:\nThere are unresolved issues or errors\nWork is partial or incomplete\nYou encountered blockers that prevent completion\nYou couldn't find necessary resources or dependencies\nQuality standards haven't been met\nTask Breakdown:\n\nCreate specific, actionable items\nBreak complex tasks into smaller, manageable steps\nUse clear, descriptive task names\nWhen in doubt, use this tool. Being proactive with task management demonstrates attentiveness and ensures you complete all requirements successfully.";
|
|
12
|
+
/**
|
|
13
|
+
* Prefix for task tool description
|
|
14
|
+
* Ported exactly from Python TASK_DESCRIPTION_PREFIX
|
|
15
|
+
*/
|
|
16
|
+
export declare const TASK_DESCRIPTION_PREFIX = "Launch a new agent to handle complex, multi-step tasks autonomously.\n\nAvailable agent types and the tools they have access to:\n\ngeneral-purpose: General-purpose agent for researching complex questions, searching for files and content, and executing multi-step tasks. When you are searching for a keyword or file and are not confident that you will find the right match in the first few tries use this agent to perform the search for you. (Tools: *)\n{other_agents}\n";
|
|
17
|
+
/**
|
|
18
|
+
* Suffix for task tool description
|
|
19
|
+
* Ported exactly from Python TASK_DESCRIPTION_SUFFIX
|
|
20
|
+
*/
|
|
21
|
+
export declare const TASK_DESCRIPTION_SUFFIX = "When using the Task tool, you must specify a subagent_type parameter to select which agent type to use.\n\nWhen to use the Agent tool:\n\nWhen you are instructed to execute custom slash commands. Use the Agent tool with the slash command invocation as the entire prompt. The slash command can take arguments. For example: Task(description=\"Check the file\", prompt=\"/check-file path/to/file.py\")\nWhen NOT to use the Agent tool:\n\nIf you want to read a specific file path, use the Read or Glob tool instead of the Agent tool, to find the match more quickly\nIf you are searching for a specific term or definition within a known location, use the Glob tool instead, to find the match more quickly\nIf you are searching for content within a specific file or set of 2-3 files, use the Read tool instead of the Agent tool, to find the match more quickly\nOther tasks that are not related to the agent descriptions above\nUsage notes:\n\nLaunch multiple agents concurrently whenever possible, to maximize performance; to do that, use a single message with multiple tool uses\nWhen the agent is done, it will return a single message back to you. The result returned by the agent is not visible to the user. To show the user the result, you should send a text message back to the user with a concise summary of the result.\nEach agent invocation is stateless. You will not be able to send additional messages to the agent, nor will the agent be able to communicate with you outside of its final report. Therefore, your prompt should contain a highly detailed task description for the agent to perform autonomously and you should specify exactly what information the agent should return back to you in its final and only message to you.\nThe agent's outputs should generally be trusted\nClearly tell the agent whether you expect it to create content, perform analysis, or just do research (search, file reads, web fetches, etc.), since it is not aware of the user's intent\nIf the agent description mentions that it should be used proactively, then you should try your best to use it without the user having to ask for it first. Use your judgement.\nExample usage:\n\n<example_agent_descriptions>\n\"content-reviewer\": use this agent after you are done creating significant content or documents\n\"greeting-responder\": use this agent when to respond to user greetings with a friendly joke\n\"research-analyst\": use this agent to conduct thorough research on complex topics\n</example_agent_description>\n\n<example>\nuser: \"Please write a function that checks if a number is prime\"\nassistant: Sure let me write a function that checks if a number is prime\nassistant: First let me use the Write tool to write a function that checks if a number is prime\nassistant: I'm going to use the Write tool to write the following code:\n<code>\nfunction isPrime(n) {\n if (n <= 1) return false\n for (let i = 2; i * i <= n; i++) {\n if (n % i === 0) return false\n }\n return true\n}\n</code>\n<commentary>\nSince significant content was created and the task was completed, now use the content-reviewer agent to review the work\n</commentary>\nassistant: Now let me use the content-reviewer agent to review the code\nassistant: Uses the Task tool to launch with the content-reviewer agent\n</example>\n<example>\nuser: \"Can you help me research the environmental impact of different renewable energy sources and create a comprehensive report?\"\n<commentary>\nThis is a complex research task that would benefit from using the research-analyst agent to conduct thorough analysis\n</commentary>\nassistant: I'll help you research the environmental impact of renewable energy sources. Let me use the research-analyst agent to conduct comprehensive research on this topic.\nassistant: Uses the Task tool to launch with the research-analyst agent, providing detailed instructions about what research to conduct and what format the report should take\n</example>\n<example>\nuser: \"Hello\"\n<commentary>\nSince the user is greeting, use the greeting-responder agent to respond with a friendly joke\n</commentary>\nassistant: \"I'm going to use the Task tool to launch with the greeting-responder agent\"\n</example>";
|
|
22
|
+
/**
|
|
23
|
+
* Description for the edit_file tool
|
|
24
|
+
* Ported exactly from Python EDIT_DESCRIPTION
|
|
25
|
+
*/
|
|
26
|
+
export declare const EDIT_DESCRIPTION = "Performs exact string replacements in files.\nUsage:\n\nYou must use your Read tool at least once in the conversation before editing. This tool will error if you attempt an edit without reading the file.\nWhen editing text from Read tool output, ensure you preserve the exact indentation (tabs/spaces) as it appears AFTER the line number prefix. The line number prefix format is: spaces + line number + tab. Everything after that tab is the actual file content to match. Never include any part of the line number prefix in the old_string or new_string.\nALWAYS prefer editing existing files. NEVER write new files unless explicitly required.\nOnly use emojis if the user explicitly requests it. Avoid adding emojis to files unless asked.\nThe edit will FAIL if old_string is not unique in the file. Either provide a larger string with more surrounding context to make it unique or use replace_all to change every instance of old_string.\nUse replace_all for replacing and renaming strings across the file. This parameter is useful if you want to rename a variable for instance.";
|
|
27
|
+
/**
|
|
28
|
+
* Description for the read_file tool
|
|
29
|
+
* Ported exactly from Python TOOL_DESCRIPTION
|
|
30
|
+
*/
|
|
31
|
+
export declare const TOOL_DESCRIPTION = "Reads a file from the local filesystem. You can access any file directly by using this tool. Assume this tool is able to read all files on the machine. If the User provides a path to a file assume that path is valid. It is okay to read a file that does not exist; an error will be returned.\nUsage:\n\nThe file_path parameter must be an absolute path, not a relative path\nBy default, it reads up to 2000 lines starting from the beginning of the file\nYou can optionally specify a line offset and limit (especially handy for long files), but it's recommended to read the whole file by not providing these parameters\nAny lines longer than 2000 characters will be truncated\nResults are returned using cat -n format, with line numbers starting at 1\nYou have the capability to call multiple tools in a single response. It is always better to speculatively read multiple files as a batch that are potentially useful.\nIf you read a file that exists but has empty contents you will receive a system reminder warning in place of file contents.";
|