deepagents 0.0.0 → 0.0.1

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/README.md CHANGED
@@ -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
- 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
- }
13
+ yarn add deepagents
83
14
  ```
84
15
 
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.
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)
package/dist/graph.d.ts CHANGED
@@ -6,7 +6,6 @@
6
6
  * provided tools, creates task tool using createTaskTool(), and returns createReactAgent
7
7
  * with proper configuration. Ensures exact parameter matching and behavior with Python version.
8
8
  */
9
- import "@langchain/anthropic/zod";
10
9
  import type { CreateDeepAgentParams } from "./types.js";
11
10
  import { z } from "zod";
12
11
  /**
package/dist/graph.js CHANGED
@@ -6,12 +6,27 @@
6
6
  * provided tools, creates task tool using createTaskTool(), and returns createReactAgent
7
7
  * with proper configuration. Ensures exact parameter matching and behavior with Python version.
8
8
  */
9
- import "@langchain/anthropic/zod";
9
+ // import "@langchain/anthropic/zod";
10
10
  import { createReactAgent } from "@langchain/langgraph/prebuilt";
11
11
  import { createTaskTool } from "./subAgent.js";
12
12
  import { getDefaultModel } from "./model.js";
13
13
  import { writeTodos, readFile, writeFile, editFile, ls } from "./tools.js";
14
14
  import { DeepAgentState } from "./state.js";
15
+ /**
16
+ * Base prompt that provides instructions about available tools
17
+ * Ported from Python implementation to ensure consistent behavior
18
+ */
19
+ const BASE_PROMPT = `You have access to a number of standard tools
20
+
21
+ ## \`write_todos\`
22
+
23
+ You have access to the \`write_todos\` tools to help you manage and plan tasks. Use these tools VERY frequently to ensure that you are tracking your tasks and giving the user visibility into your progress.
24
+ These tools are also EXTREMELY helpful for planning tasks, and for breaking down larger complex tasks into smaller steps. If you do not use this tool when planning, you may forget to do important tasks - and that is unacceptable.
25
+
26
+ It is critical that you mark todos as completed as soon as you are done with a task. Do not batch up multiple tasks before marking them as completed.
27
+ ## \`task\`
28
+
29
+ - When doing web search, prefer to use the \`task\` tool in order to reduce context usage.`;
15
30
  /**
16
31
  * Built-in tools that are always available in Deep Agents
17
32
  */
@@ -52,11 +67,15 @@ export function createDeepAgent(params = {}) {
52
67
  });
53
68
  allTools.push(taskTool);
54
69
  }
70
+ // Combine instructions with base prompt like Python implementation
71
+ const finalInstructions = instructions
72
+ ? instructions + BASE_PROMPT
73
+ : BASE_PROMPT;
55
74
  // Return createReactAgent with proper configuration
56
75
  return createReactAgent({
57
76
  llm: model,
58
77
  tools: allTools,
59
78
  stateSchema,
60
- messageModifier: instructions,
79
+ messageModifier: finalInstructions,
61
80
  });
62
81
  }
@@ -22,20 +22,20 @@ export declare function createTaskTool<StateSchema extends z.ZodObject<any, any,
22
22
  model: LanguageModelLike;
23
23
  stateSchema: StateSchema;
24
24
  }): import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{
25
- agent_name: z.ZodString;
26
- task: z.ZodString;
25
+ description: z.ZodString;
26
+ subagent_type: z.ZodString;
27
27
  }, "strip", z.ZodTypeAny, {
28
- agent_name: string;
29
- task: string;
28
+ description: string;
29
+ subagent_type: string;
30
30
  }, {
31
- agent_name: string;
32
- task: string;
31
+ description: string;
32
+ subagent_type: string;
33
33
  }>, {
34
- agent_name: string;
35
- task: string;
34
+ description: string;
35
+ subagent_type: string;
36
36
  }, {
37
- agent_name: string;
38
- task: string;
37
+ description: string;
38
+ subagent_type: string;
39
39
  }, string | Command<unknown, {
40
40
  messages: ToolMessage[];
41
41
  }, string>>;
package/dist/subAgent.js CHANGED
@@ -13,6 +13,7 @@ import { createReactAgent } from "@langchain/langgraph/prebuilt";
13
13
  import { z } from "zod";
14
14
  import { getDefaultModel } from "./model.js";
15
15
  import { writeTodos, readFile, writeFile, editFile, ls } from "./tools.js";
16
+ import { TASK_DESCRIPTION_PREFIX, TASK_DESCRIPTION_SUFFIX } from "./prompts.js";
16
17
  /**
17
18
  * Built-in tools map for tool resolution by name
18
19
  */
@@ -30,20 +31,11 @@ const BUILTIN_TOOLS = {
30
31
  */
31
32
  export function createTaskTool(inputs) {
32
33
  const { subagents, tools = {}, model = getDefaultModel(), stateSchema, } = inputs;
33
- // Create agents map from subagents array
34
- const agentsMap = new Map();
35
- for (const subagent of subagents) {
36
- agentsMap.set(subagent.name, subagent);
37
- }
38
34
  // Combine built-in tools with provided tools for tool resolution
39
35
  const allTools = { ...BUILTIN_TOOLS, ...tools };
40
- return tool(async (input, config) => {
41
- const { agent_name, task } = input;
42
- // Get the subagent configuration
43
- const subagent = agentsMap.get(agent_name);
44
- if (!subagent) {
45
- return `Error: Agent '${agent_name}' not found. Available agents: ${Array.from(agentsMap.keys()).join(", ")}`;
46
- }
36
+ // Pre-create all agents like Python does
37
+ const agentsMap = new Map();
38
+ for (const subagent of subagents) {
47
39
  // Resolve tools by name for this subagent
48
40
  const subagentTools = [];
49
41
  if (subagent.tools) {
@@ -54,37 +46,53 @@ export function createTaskTool(inputs) {
54
46
  }
55
47
  else {
56
48
  // eslint-disable-next-line no-console
57
- console.warn(`Warning: Tool '${toolName}' not found for agent '${agent_name}'`);
49
+ console.warn(`Warning: Tool '${toolName}' not found for agent '${subagent.name}'`);
58
50
  }
59
51
  }
60
52
  }
53
+ else {
54
+ // If no tools specified, use all tools like Python does
55
+ subagentTools.push(...Object.values(allTools));
56
+ }
57
+ // Create react agent for the subagent (pre-create like Python)
58
+ const reactAgent = createReactAgent({
59
+ llm: model,
60
+ tools: subagentTools,
61
+ stateSchema,
62
+ messageModifier: subagent.prompt,
63
+ });
64
+ agentsMap.set(subagent.name, reactAgent);
65
+ }
66
+ return tool(async (input, config) => {
67
+ const { description, subagent_type } = input;
68
+ // Get the pre-created agent
69
+ const reactAgent = agentsMap.get(subagent_type);
70
+ if (!reactAgent) {
71
+ return `Error: Agent '${subagent_type}' not found. Available agents: ${Array.from(agentsMap.keys()).join(", ")}`;
72
+ }
61
73
  try {
62
- // Create react agent for the subagent
63
- const reactAgent = createReactAgent({
64
- llm: model,
65
- tools: subagentTools,
66
- stateSchema,
67
- messageModifier: subagent.prompt,
68
- });
69
74
  // Get current state for context
70
75
  const currentState = getCurrentTaskInput();
71
- // Execute the subagent with the task
72
- const result = await reactAgent.invoke({
76
+ // Modify state messages like Python does
77
+ const modifiedState = {
73
78
  ...currentState,
74
79
  messages: [
75
80
  {
76
81
  role: "user",
77
- content: task,
82
+ content: description,
78
83
  },
79
84
  ],
80
- }, config);
85
+ };
86
+ // Execute the subagent with the task
87
+ const result = await reactAgent.invoke(modifiedState, config);
81
88
  // Use Command for state updates and navigation between agents
89
+ // Return the result using Command to properly handle subgraph state
82
90
  return new Command({
83
91
  update: {
84
- ...result,
92
+ files: result.files || {},
85
93
  messages: [
86
94
  new ToolMessage({
87
- content: `Completed task '${task}' using agent '${agent_name}'. Result: ${JSON.stringify(result.messages?.slice(-1)[0]?.content || "Task completed")}`,
95
+ content: result.messages?.slice(-1)[0]?.content || "Task completed",
88
96
  tool_call_id: config.toolCall?.id,
89
97
  }),
90
98
  ],
@@ -98,7 +106,7 @@ export function createTaskTool(inputs) {
98
106
  update: {
99
107
  messages: [
100
108
  new ToolMessage({
101
- content: `Error executing task '${task}' with agent '${agent_name}': ${errorMessage}`,
109
+ content: `Error executing task '${description}' with agent '${subagent_type}': ${errorMessage}`,
102
110
  tool_call_id: config.toolCall?.id,
103
111
  }),
104
112
  ],
@@ -107,14 +115,14 @@ export function createTaskTool(inputs) {
107
115
  }
108
116
  }, {
109
117
  name: "task",
110
- description: `Execute a task using a specialized sub-agent. Available agents: ${subagents.map((a) => `${a.name} - ${a.description}`).join("; ")}`,
118
+ description: TASK_DESCRIPTION_PREFIX.replace("{other_agents}", subagents.map((a) => `- ${a.name}: ${a.description}`).join("\n")) + TASK_DESCRIPTION_SUFFIX,
111
119
  schema: z.object({
112
- agent_name: z
113
- .string()
114
- .describe(`Name of the agent to use. Available: ${subagents.map((a) => a.name).join(", ")}`),
115
- task: z
120
+ description: z
116
121
  .string()
117
122
  .describe("The task to execute with the selected agent"),
123
+ subagent_type: z
124
+ .string()
125
+ .describe(`Name of the agent to use. Available: ${subagents.map((a) => a.name).join(", ")}`),
118
126
  }),
119
127
  });
120
128
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deepagents",
3
- "version": "0.0.0",
3
+ "version": "0.0.1",
4
4
  "description": "Deep Agents - a library for building controllable AI agents with LangGraph",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",