deepagents 0.0.0
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 +127 -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/dist/tools.js
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool functions for Deep Agents
|
|
3
|
+
*
|
|
4
|
+
* TypeScript versions of all tools using @langchain/core/tools tool() function.
|
|
5
|
+
* Uses getCurrentTaskInput() for state access and returns Command objects for state updates.
|
|
6
|
+
* Implements mock filesystem operations using state.files similar to Python version.
|
|
7
|
+
*/
|
|
8
|
+
import { tool } from "@langchain/core/tools";
|
|
9
|
+
import { ToolMessage } from "@langchain/core/messages";
|
|
10
|
+
import { Command, getCurrentTaskInput } from "@langchain/langgraph";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import { WRITE_TODOS_DESCRIPTION, EDIT_DESCRIPTION, TOOL_DESCRIPTION, } from "./prompts.js";
|
|
13
|
+
/**
|
|
14
|
+
* Write todos tool - manages todo list with Command return
|
|
15
|
+
* Uses getCurrentTaskInput() instead of Python's InjectedState
|
|
16
|
+
*/
|
|
17
|
+
export const writeTodos = tool((input, config) => {
|
|
18
|
+
return {
|
|
19
|
+
update: {
|
|
20
|
+
todos: input.todos,
|
|
21
|
+
messages: [
|
|
22
|
+
new ToolMessage({
|
|
23
|
+
content: `Updated todo list to ${JSON.stringify(input.todos)}`,
|
|
24
|
+
tool_call_id: config.toolCall?.id,
|
|
25
|
+
}),
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}, {
|
|
30
|
+
name: "write_todos",
|
|
31
|
+
description: WRITE_TODOS_DESCRIPTION,
|
|
32
|
+
schema: z.object({
|
|
33
|
+
todos: z
|
|
34
|
+
.array(z.object({
|
|
35
|
+
content: z.string().describe("Content of the todo item"),
|
|
36
|
+
status: z
|
|
37
|
+
.enum(["pending", "in_progress", "completed"])
|
|
38
|
+
.describe("Status of the todo"),
|
|
39
|
+
}))
|
|
40
|
+
.describe("List of todo items to update"),
|
|
41
|
+
}),
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* List files tool - returns list of files from state.files
|
|
45
|
+
* Equivalent to Python's ls function
|
|
46
|
+
*/
|
|
47
|
+
export const ls = tool(() => {
|
|
48
|
+
const state = getCurrentTaskInput();
|
|
49
|
+
const files = state.files || {};
|
|
50
|
+
return Object.keys(files);
|
|
51
|
+
}, {
|
|
52
|
+
name: "ls",
|
|
53
|
+
description: "List all files in the mock filesystem",
|
|
54
|
+
schema: z.object({}),
|
|
55
|
+
});
|
|
56
|
+
/**
|
|
57
|
+
* Read file tool - reads from mock filesystem in state.files
|
|
58
|
+
* Matches Python read_file function behavior exactly
|
|
59
|
+
*/
|
|
60
|
+
export const readFile = tool((input) => {
|
|
61
|
+
const state = getCurrentTaskInput();
|
|
62
|
+
const mockFilesystem = state.files || {};
|
|
63
|
+
const { file_path, offset = 0, limit = 2000 } = input;
|
|
64
|
+
if (!(file_path in mockFilesystem)) {
|
|
65
|
+
return `Error: File '${file_path}' not found`;
|
|
66
|
+
}
|
|
67
|
+
// Get file content
|
|
68
|
+
const content = mockFilesystem[file_path];
|
|
69
|
+
// Handle empty file
|
|
70
|
+
if (!content || content.trim() === "") {
|
|
71
|
+
return "System reminder: File exists but has empty contents";
|
|
72
|
+
}
|
|
73
|
+
// Split content into lines
|
|
74
|
+
const lines = content.split("\n");
|
|
75
|
+
// Apply line offset and limit
|
|
76
|
+
const startIdx = offset;
|
|
77
|
+
const endIdx = Math.min(startIdx + limit, lines.length);
|
|
78
|
+
// Handle case where offset is beyond file length
|
|
79
|
+
if (startIdx >= lines.length) {
|
|
80
|
+
return `Error: Line offset ${offset} exceeds file length (${lines.length} lines)`;
|
|
81
|
+
}
|
|
82
|
+
// Format output with line numbers (cat -n format)
|
|
83
|
+
const resultLines = [];
|
|
84
|
+
for (let i = startIdx; i < endIdx; i++) {
|
|
85
|
+
let lineContent = lines[i];
|
|
86
|
+
// Truncate lines longer than 2000 characters
|
|
87
|
+
if (lineContent.length > 2000) {
|
|
88
|
+
lineContent = lineContent.substring(0, 2000);
|
|
89
|
+
}
|
|
90
|
+
// Line numbers start at 1, so add 1 to the index
|
|
91
|
+
const lineNumber = i + 1;
|
|
92
|
+
resultLines.push(`${lineNumber.toString().padStart(6)} ${lineContent}`);
|
|
93
|
+
}
|
|
94
|
+
return resultLines.join("\n");
|
|
95
|
+
}, {
|
|
96
|
+
name: "read_file",
|
|
97
|
+
description: TOOL_DESCRIPTION,
|
|
98
|
+
schema: z.object({
|
|
99
|
+
file_path: z.string().describe("Absolute path to the file to read"),
|
|
100
|
+
offset: z
|
|
101
|
+
.number()
|
|
102
|
+
.optional()
|
|
103
|
+
.default(0)
|
|
104
|
+
.describe("Line offset to start reading from"),
|
|
105
|
+
limit: z
|
|
106
|
+
.number()
|
|
107
|
+
.optional()
|
|
108
|
+
.default(2000)
|
|
109
|
+
.describe("Maximum number of lines to read"),
|
|
110
|
+
}),
|
|
111
|
+
});
|
|
112
|
+
/**
|
|
113
|
+
* Write file tool - writes to mock filesystem with Command return
|
|
114
|
+
* Matches Python write_file function behavior exactly
|
|
115
|
+
*/
|
|
116
|
+
export const writeFile = tool((input, config) => {
|
|
117
|
+
const state = getCurrentTaskInput();
|
|
118
|
+
const files = { ...(state.files || {}) };
|
|
119
|
+
files[input.file_path] = input.content;
|
|
120
|
+
return new Command({
|
|
121
|
+
update: {
|
|
122
|
+
files: files,
|
|
123
|
+
messages: [
|
|
124
|
+
new ToolMessage({
|
|
125
|
+
content: `Updated file ${input.file_path}`,
|
|
126
|
+
tool_call_id: config.toolCall?.id,
|
|
127
|
+
}),
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
}, {
|
|
132
|
+
name: "write_file",
|
|
133
|
+
description: "Write content to a file in the mock filesystem",
|
|
134
|
+
schema: z.object({
|
|
135
|
+
file_path: z.string().describe("Absolute path to the file to write"),
|
|
136
|
+
content: z.string().describe("Content to write to the file"),
|
|
137
|
+
}),
|
|
138
|
+
});
|
|
139
|
+
/**
|
|
140
|
+
* Edit file tool - edits files in mock filesystem with Command return
|
|
141
|
+
* Matches Python edit_file function behavior exactly
|
|
142
|
+
*/
|
|
143
|
+
export const editFile = tool((input, config) => {
|
|
144
|
+
const state = getCurrentTaskInput();
|
|
145
|
+
const mockFilesystem = { ...(state.files || {}) };
|
|
146
|
+
const { file_path, old_string, new_string, replace_all = false } = input;
|
|
147
|
+
// Check if file exists in mock filesystem
|
|
148
|
+
if (!(file_path in mockFilesystem)) {
|
|
149
|
+
return `Error: File '${file_path}' not found`;
|
|
150
|
+
}
|
|
151
|
+
// Get current file content
|
|
152
|
+
const content = mockFilesystem[file_path];
|
|
153
|
+
// Check if old_string exists in the file
|
|
154
|
+
if (!content.includes(old_string)) {
|
|
155
|
+
return `Error: String not found in file: '${old_string}'`;
|
|
156
|
+
}
|
|
157
|
+
// If not replace_all, check for uniqueness
|
|
158
|
+
if (!replace_all) {
|
|
159
|
+
const escapedOldString = old_string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
160
|
+
const occurrences = (content.match(new RegExp(escapedOldString, "g")) || []).length;
|
|
161
|
+
if (occurrences > 1) {
|
|
162
|
+
return `Error: String '${old_string}' appears ${occurrences} times in file. Use replace_all=True to replace all instances, or provide a more specific string with surrounding context.`;
|
|
163
|
+
}
|
|
164
|
+
else if (occurrences === 0) {
|
|
165
|
+
return `Error: String not found in file: '${old_string}'`;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// Perform the replacement
|
|
169
|
+
let newContent;
|
|
170
|
+
if (replace_all) {
|
|
171
|
+
const escapedOldString = old_string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
172
|
+
newContent = content.replace(new RegExp(escapedOldString, "g"), new_string);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
newContent = content.replace(old_string, new_string);
|
|
176
|
+
}
|
|
177
|
+
// Update the mock filesystem
|
|
178
|
+
mockFilesystem[file_path] = newContent;
|
|
179
|
+
return new Command({
|
|
180
|
+
update: {
|
|
181
|
+
files: mockFilesystem,
|
|
182
|
+
messages: [
|
|
183
|
+
new ToolMessage({
|
|
184
|
+
content: `Updated file ${file_path}`,
|
|
185
|
+
tool_call_id: config.toolCall?.id,
|
|
186
|
+
}),
|
|
187
|
+
],
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
}, {
|
|
191
|
+
name: "edit_file",
|
|
192
|
+
description: EDIT_DESCRIPTION,
|
|
193
|
+
schema: z.object({
|
|
194
|
+
file_path: z.string().describe("Absolute path to the file to edit"),
|
|
195
|
+
old_string: z
|
|
196
|
+
.string()
|
|
197
|
+
.describe("String to be replaced (must match exactly)"),
|
|
198
|
+
new_string: z.string().describe("String to replace with"),
|
|
199
|
+
replace_all: z
|
|
200
|
+
.boolean()
|
|
201
|
+
.optional()
|
|
202
|
+
.default(false)
|
|
203
|
+
.describe("Whether to replace all occurrences"),
|
|
204
|
+
}),
|
|
205
|
+
});
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript type definitions for Deep Agents
|
|
3
|
+
*
|
|
4
|
+
* This file contains all the TypeScript interfaces and types that correspond
|
|
5
|
+
* to the Python TypedDict and other type definitions. Defines all necessary
|
|
6
|
+
* TypeScript interfaces and types including StateSchemaType, SubAgent, Todo,
|
|
7
|
+
* and proper generic types for state schemas.
|
|
8
|
+
*/
|
|
9
|
+
import type { BaseLanguageModelInput, LanguageModelOutput } from "@langchain/core/language_models/base";
|
|
10
|
+
import type { StructuredTool } from "@langchain/core/tools";
|
|
11
|
+
import type { DeepAgentState } from "./state.js";
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
import { Runnable } from "@langchain/core/runnables";
|
|
14
|
+
export type InferZodObjectShape<T> = T extends z.ZodObject<infer Shape> ? Shape : never;
|
|
15
|
+
/**
|
|
16
|
+
* SubAgent interface matching Python's TypedDict structure
|
|
17
|
+
*/
|
|
18
|
+
export interface SubAgent {
|
|
19
|
+
name: string;
|
|
20
|
+
description: string;
|
|
21
|
+
prompt: string;
|
|
22
|
+
tools?: string[];
|
|
23
|
+
}
|
|
24
|
+
export type TodoStatus = "pending" | "in_progress" | "completed";
|
|
25
|
+
export interface Todo {
|
|
26
|
+
content: string;
|
|
27
|
+
status: TodoStatus;
|
|
28
|
+
}
|
|
29
|
+
export type DeepAgentStateType = z.infer<typeof DeepAgentState>;
|
|
30
|
+
export type LanguageModelLike = Runnable<BaseLanguageModelInput, LanguageModelOutput>;
|
|
31
|
+
/**
|
|
32
|
+
* Parameters for createDeepAgent function with TypeScript types
|
|
33
|
+
*/
|
|
34
|
+
export interface CreateDeepAgentParams<StateSchema extends z.ZodObject<any, any, any, any, any>> {
|
|
35
|
+
tools?: StructuredTool[];
|
|
36
|
+
instructions?: string;
|
|
37
|
+
model?: LanguageModelLike;
|
|
38
|
+
subagents?: SubAgent[];
|
|
39
|
+
stateSchema?: StateSchema;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Parameters for createTaskTool function
|
|
43
|
+
*/
|
|
44
|
+
export interface CreateTaskToolParams<StateSchema extends z.ZodObject<any, any, any, any, any>> {
|
|
45
|
+
subagents: SubAgent[];
|
|
46
|
+
tools?: Record<string, StructuredTool>;
|
|
47
|
+
model?: LanguageModelLike;
|
|
48
|
+
stateSchema?: StateSchema;
|
|
49
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript type definitions for Deep Agents
|
|
3
|
+
*
|
|
4
|
+
* This file contains all the TypeScript interfaces and types that correspond
|
|
5
|
+
* to the Python TypedDict and other type definitions. Defines all necessary
|
|
6
|
+
* TypeScript interfaces and types including StateSchemaType, SubAgent, Todo,
|
|
7
|
+
* and proper generic types for state schemas.
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "deepagents",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Deep Agents - a library for building controllable AI agents with LangGraph",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "yarn clean && tsc",
|
|
10
|
+
"build:examples": "yarn clean && tsc -p examples.tsconfig.json",
|
|
11
|
+
"build:watch": "tsc --watch",
|
|
12
|
+
"dev": "tsc --watch",
|
|
13
|
+
"clean": "rm -rf dist dist-examples || true",
|
|
14
|
+
"typecheck": "tsc --noEmit",
|
|
15
|
+
"lint": "eslint src/**/*.ts examples/**/*.ts",
|
|
16
|
+
"lint:fix": "eslint src/**/*.ts examples/**/*.ts --fix",
|
|
17
|
+
"format": "prettier --write \"src/**/*.{ts,js,json,md}\" \"examples/**/*.{ts,js,json,md}\"",
|
|
18
|
+
"format:check": "prettier --check \"src/**/*.{ts,js,json,md}\" \"examples/**/*.{ts,js,json,md}\"",
|
|
19
|
+
"prepublishOnly": "yarn build",
|
|
20
|
+
"test": "echo \"Error: no test specified\" && exit 0",
|
|
21
|
+
"start": "node dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/langchain-ai/deepagentsjs.git"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"ai",
|
|
29
|
+
"agents",
|
|
30
|
+
"langgraph",
|
|
31
|
+
"langchain",
|
|
32
|
+
"typescript",
|
|
33
|
+
"llm"
|
|
34
|
+
],
|
|
35
|
+
"author": "LangChain",
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/langchain-ai/deepagentsjs/issues"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://github.com/langchain-ai/deepagentsjs#readme",
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@langchain/anthropic": "^0.3.25",
|
|
43
|
+
"@langchain/core": "^0.3.66",
|
|
44
|
+
"@langchain/langgraph": "^0.4.2",
|
|
45
|
+
"zod": "^3.25.32"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@eslint/eslintrc": "^3.1.0",
|
|
49
|
+
"@eslint/js": "^9.19.0",
|
|
50
|
+
"@langchain/tavily": "^0.1.4",
|
|
51
|
+
"@tsconfig/recommended": "^1.0.8",
|
|
52
|
+
"@types/node": "^22.13.5",
|
|
53
|
+
"dotenv": "^17.2.1",
|
|
54
|
+
"eslint": "^9.19.0",
|
|
55
|
+
"eslint-config-prettier": "^8.8.0",
|
|
56
|
+
"eslint-plugin-import": "^2.27.5",
|
|
57
|
+
"eslint-plugin-no-instanceof": "^1.0.1",
|
|
58
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
59
|
+
"globals": "^15.0.0",
|
|
60
|
+
"prettier": "^3.6.2",
|
|
61
|
+
"typescript": "^5",
|
|
62
|
+
"typescript-eslint": "^8.22.0"
|
|
63
|
+
},
|
|
64
|
+
"resolutions": {
|
|
65
|
+
"@langchain/langgraph": ">=0.2.53",
|
|
66
|
+
"@langchain/core": ">=0.3.0"
|
|
67
|
+
},
|
|
68
|
+
"files": [
|
|
69
|
+
"dist/**/*"
|
|
70
|
+
],
|
|
71
|
+
"packageManager": "yarn@1.22.22"
|
|
72
|
+
}
|