deepagents 1.8.8 → 1.9.0-alpha.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/dist/index.cjs +2155 -831
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1771 -1241
- package/dist/index.d.ts +1772 -1240
- package/dist/index.js +2196 -879
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,225 @@
|
|
|
1
1
|
import * as _langchain from "langchain";
|
|
2
|
-
import { AgentMiddleware, AgentMiddleware as AgentMiddleware$1, AgentTypeConfig, CreateAgentParams, HumanMessage, InferMiddlewareStates, InterruptOnConfig, ProviderStrategy, ReactAgent, ResponseFormat, ResponseFormatUndefined, Runtime, StructuredTool, SystemMessage, ToolMessage, ToolStrategy } from "langchain";
|
|
3
|
-
import { Runnable } from "@langchain/core/runnables";
|
|
2
|
+
import { AgentMiddleware, AgentMiddleware as AgentMiddleware$1, AgentTypeConfig, CreateAgentParams, HumanMessage, InferMiddlewareStates, InterruptOnConfig, ProviderStrategy, ReactAgent, ResponseFormat, ResponseFormatUndefined, Runtime, StructuredTool, SystemMessage, ToolMessage, ToolRuntime, ToolStrategy } from "langchain";
|
|
4
3
|
import * as _langgraph from "@langchain/langgraph";
|
|
5
4
|
import { AnnotationRoot, Command, ReducedValue, StateSchema } from "@langchain/langgraph";
|
|
6
5
|
import { z } from "zod/v4";
|
|
7
6
|
import * as _messages from "@langchain/core/messages";
|
|
8
|
-
import * as
|
|
7
|
+
import * as z$2 from "zod";
|
|
9
8
|
import { z as z$1 } from "zod";
|
|
9
|
+
import { Client } from "@langchain/langgraph-sdk";
|
|
10
10
|
import { CreateSandboxOptions, Sandbox } from "langsmith/experimental/sandbox";
|
|
11
|
-
import * as zod_v30 from "zod/v3";
|
|
12
|
-
import * as _langchain_core_tools0 from "@langchain/core/tools";
|
|
13
|
-
import { ClientTool, ServerTool, StructuredTool as StructuredTool$1, ToolRuntime } from "@langchain/core/tools";
|
|
11
|
+
import * as _$zod_v30 from "zod/v3";
|
|
14
12
|
import { BaseCheckpointSaver, BaseStore } from "@langchain/langgraph-checkpoint";
|
|
15
|
-
import * as zod_v4_core0 from "zod/v4/core";
|
|
13
|
+
import * as _$zod_v4_core0 from "zod/v4/core";
|
|
14
|
+
import * as _$_langchain_core_tools0 from "@langchain/core/tools";
|
|
15
|
+
import { ClientTool, ServerTool, StructuredTool as StructuredTool$1 } from "@langchain/core/tools";
|
|
16
|
+
import { InteropZodObject } from "@langchain/core/utils/types";
|
|
16
17
|
import { BaseLanguageModel, LanguageModelLike } from "@langchain/core/language_models/base";
|
|
18
|
+
import { Runnable } from "@langchain/core/runnables";
|
|
17
19
|
import { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
18
|
-
import { InteropZodObject } from "@langchain/core/utils/types";
|
|
19
20
|
|
|
21
|
+
//#region src/backends/v1/protocol.d.ts
|
|
22
|
+
/**
|
|
23
|
+
* Protocol for pluggable memory backends (single, unified).
|
|
24
|
+
*
|
|
25
|
+
* Backends can store files in different locations (state, filesystem, database, etc.)
|
|
26
|
+
* and provide a uniform interface for file operations.
|
|
27
|
+
*
|
|
28
|
+
* All file data is represented as objects with the FileData structure.
|
|
29
|
+
*
|
|
30
|
+
* Methods can return either direct values or Promises, allowing both
|
|
31
|
+
* synchronous and asynchronous implementations.
|
|
32
|
+
*
|
|
33
|
+
* @deprecated Use {@link BackendProtocolV2} instead.
|
|
34
|
+
*/
|
|
35
|
+
interface BackendProtocolV1 {
|
|
36
|
+
/**
|
|
37
|
+
* Structured listing with file metadata.
|
|
38
|
+
*
|
|
39
|
+
* Lists files and directories in the specified directory (non-recursive).
|
|
40
|
+
* Directories have a trailing / in their path and is_dir=true.
|
|
41
|
+
*
|
|
42
|
+
* @param path - Absolute path to directory
|
|
43
|
+
* @returns List of FileInfo objects for files and directories directly in the directory
|
|
44
|
+
*/
|
|
45
|
+
lsInfo(path: string): MaybePromise<FileInfo[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Read file content.
|
|
48
|
+
*
|
|
49
|
+
* @param filePath - Absolute file path
|
|
50
|
+
* @param offset - Line offset to start reading from (0-indexed), default 0
|
|
51
|
+
* @param limit - Maximum number of lines to read, default 500
|
|
52
|
+
* @returns File content as plain string on success or error on failure
|
|
53
|
+
*/
|
|
54
|
+
read(filePath: string, offset?: number, limit?: number): MaybePromise<string>;
|
|
55
|
+
/**
|
|
56
|
+
* Read file content as raw FileData.
|
|
57
|
+
*
|
|
58
|
+
* @param filePath - Absolute file path
|
|
59
|
+
* @returns Raw file content as FileData
|
|
60
|
+
*/
|
|
61
|
+
readRaw(filePath: string): MaybePromise<FileData>;
|
|
62
|
+
/**
|
|
63
|
+
* Search file contents for a literal text pattern.
|
|
64
|
+
*
|
|
65
|
+
* Binary files (determined by MIME type) are skipped.
|
|
66
|
+
*
|
|
67
|
+
* @param pattern - Literal text pattern to search for
|
|
68
|
+
* @param path - Base path to search from (default: null)
|
|
69
|
+
* @param glob - Optional glob pattern to filter files (e.g., "*.py")
|
|
70
|
+
* @returns Array of GrepMatch on success or error string on failure
|
|
71
|
+
*/
|
|
72
|
+
grepRaw(pattern: string, path?: string | null, glob?: string | null): MaybePromise<GrepMatch[] | string>;
|
|
73
|
+
/**
|
|
74
|
+
* Structured glob matching returning FileInfo objects.
|
|
75
|
+
*
|
|
76
|
+
* @param pattern - Glob pattern (e.g., `*.py`, `**\/*.ts`)
|
|
77
|
+
* @param path - Base path to search from (default: "/")
|
|
78
|
+
* @returns List of FileInfo objects matching the pattern
|
|
79
|
+
*/
|
|
80
|
+
globInfo(pattern: string, path?: string): MaybePromise<FileInfo[]>;
|
|
81
|
+
/**
|
|
82
|
+
* Create a new file.
|
|
83
|
+
*
|
|
84
|
+
* @param filePath - Absolute file path
|
|
85
|
+
* @param content - File content as string
|
|
86
|
+
* @returns WriteResult with error populated on failure
|
|
87
|
+
*/
|
|
88
|
+
write(filePath: string, content: string): MaybePromise<WriteResult>;
|
|
89
|
+
/**
|
|
90
|
+
* Edit a file by replacing string occurrences.
|
|
91
|
+
*
|
|
92
|
+
* @param filePath - Absolute file path
|
|
93
|
+
* @param oldString - String to find and replace
|
|
94
|
+
* @param newString - Replacement string
|
|
95
|
+
* @param replaceAll - If true, replace all occurrences (default: false)
|
|
96
|
+
* @returns EditResult with error, path, filesUpdate, and occurrences
|
|
97
|
+
*/
|
|
98
|
+
edit(filePath: string, oldString: string, newString: string, replaceAll?: boolean): MaybePromise<EditResult>;
|
|
99
|
+
/**
|
|
100
|
+
* Upload multiple files.
|
|
101
|
+
* Optional - backends that don't support file upload can omit this.
|
|
102
|
+
*
|
|
103
|
+
* @param files - List of [path, content] tuples to upload
|
|
104
|
+
* @returns List of FileUploadResponse objects, one per input file
|
|
105
|
+
*/
|
|
106
|
+
uploadFiles?(files: Array<[string, Uint8Array]>): MaybePromise<FileUploadResponse[]>;
|
|
107
|
+
/**
|
|
108
|
+
* Download multiple files.
|
|
109
|
+
* Optional - backends that don't support file download can omit this.
|
|
110
|
+
*
|
|
111
|
+
* @param paths - List of file paths to download
|
|
112
|
+
* @returns List of FileDownloadResponse objects, one per input path
|
|
113
|
+
*/
|
|
114
|
+
downloadFiles?(paths: string[]): MaybePromise<FileDownloadResponse[]>;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Protocol for sandboxed backends with isolated runtime.
|
|
118
|
+
* Sandboxed backends run in isolated environments (e.g., containers)
|
|
119
|
+
* and communicate via defined interfaces.
|
|
120
|
+
*
|
|
121
|
+
* @deprecated Use {@link SandboxBackendProtocolV2} instead.
|
|
122
|
+
*/
|
|
123
|
+
interface SandboxBackendProtocolV1 extends BackendProtocolV1 {
|
|
124
|
+
/**
|
|
125
|
+
* Execute a command in the sandbox.
|
|
126
|
+
*
|
|
127
|
+
* @param command - Full shell command string to execute
|
|
128
|
+
* @returns ExecuteResponse with combined output, exit code, and truncation flag
|
|
129
|
+
*/
|
|
130
|
+
execute(command: string): MaybePromise<ExecuteResponse>;
|
|
131
|
+
/** Unique identifier for the sandbox backend instance */
|
|
132
|
+
readonly id: string;
|
|
133
|
+
}
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/backends/v2/protocol.d.ts
|
|
136
|
+
/**
|
|
137
|
+
* Updated protocol for pluggable memory backends.
|
|
138
|
+
*
|
|
139
|
+
* Key differences from {@link BackendProtocol}:
|
|
140
|
+
* - `read()` returns {@link ReadResult} instead of a plain string
|
|
141
|
+
* - `readRaw()` returns {@link ReadRawResult} instead of FileData
|
|
142
|
+
* - `grep()` returns {@link GrepResult} instead of `GrepMatch[] | string`
|
|
143
|
+
* - `ls()` returns {@link LsResult} instead of FileInfo[]
|
|
144
|
+
* - `glob()` returns {@link GlobResult} instead of FileInfo[]
|
|
145
|
+
*
|
|
146
|
+
* Existing v1 backends can be adapted to this interface using
|
|
147
|
+
* {@link adaptBackendProtocol} from utils.
|
|
148
|
+
*/
|
|
149
|
+
interface BackendProtocolV2 extends Omit<BackendProtocolV1, "read" | "readRaw" | "grepRaw" | "lsInfo" | "globInfo"> {
|
|
150
|
+
/**
|
|
151
|
+
* Structured listing with file metadata.
|
|
152
|
+
*
|
|
153
|
+
* Lists files and directories in the specified directory (non-recursive).
|
|
154
|
+
* Directories have a trailing / in their path and is_dir=true.
|
|
155
|
+
*
|
|
156
|
+
* @param path - Absolute path to directory
|
|
157
|
+
* @returns LsResult with list of FileInfo objects on success or error on failure
|
|
158
|
+
*/
|
|
159
|
+
ls(path: string): MaybePromise<LsResult>;
|
|
160
|
+
/**
|
|
161
|
+
* Read file content.
|
|
162
|
+
*
|
|
163
|
+
* For text files, content is paginated by line offset/limit.
|
|
164
|
+
* For binary files, the full raw Uint8Array content is returned.
|
|
165
|
+
*
|
|
166
|
+
* @param filePath - Absolute file path
|
|
167
|
+
* @param offset - Line offset to start reading from (0-indexed), default 0
|
|
168
|
+
* @param limit - Maximum number of lines to read, default 500
|
|
169
|
+
* @returns ReadResult with content on success or error on failure
|
|
170
|
+
*/
|
|
171
|
+
read(filePath: string, offset?: number, limit?: number): MaybePromise<ReadResult>;
|
|
172
|
+
/**
|
|
173
|
+
* Read file content as raw FileData.
|
|
174
|
+
*
|
|
175
|
+
* @param filePath - Absolute file path
|
|
176
|
+
* @returns ReadRawResult with raw file data on success or error on failure
|
|
177
|
+
*/
|
|
178
|
+
readRaw(filePath: string): MaybePromise<ReadRawResult>;
|
|
179
|
+
/**
|
|
180
|
+
* Search file contents for a literal text pattern.
|
|
181
|
+
*
|
|
182
|
+
* Binary files (determined by MIME type) are skipped.
|
|
183
|
+
*
|
|
184
|
+
* @param pattern - Literal text pattern to search for
|
|
185
|
+
* @param path - Base path to search from (default: null)
|
|
186
|
+
* @param glob - Optional glob pattern to filter files (e.g., "*.py")
|
|
187
|
+
* @returns GrepResult with matches on success or error on failure
|
|
188
|
+
*/
|
|
189
|
+
grep(pattern: string, path?: string | null, glob?: string | null): MaybePromise<GrepResult>;
|
|
190
|
+
/**
|
|
191
|
+
* Structured glob matching returning FileInfo objects.
|
|
192
|
+
*
|
|
193
|
+
* @param pattern - Glob pattern (e.g., `*.py`, `**\/*.ts`)
|
|
194
|
+
* @param path - Base path to search from (default: "/")
|
|
195
|
+
* @returns GlobResult with list of FileInfo objects matching the pattern on success or error on failure
|
|
196
|
+
*/
|
|
197
|
+
glob(pattern: string, path?: string): MaybePromise<GlobResult>;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Protocol for sandboxed backends with isolated runtime.
|
|
201
|
+
*
|
|
202
|
+
* Key differences from {@link SandboxBackendProtocol}:
|
|
203
|
+
* - Extends {@link BackendProtocolV2} instead of {@link BackendProtocol}
|
|
204
|
+
* - All methods return structured Result types for consistent error handling
|
|
205
|
+
*/
|
|
206
|
+
interface SandboxBackendProtocolV2 extends BackendProtocolV2 {
|
|
207
|
+
/**
|
|
208
|
+
* Execute a command in the sandbox.
|
|
209
|
+
*
|
|
210
|
+
* @param command - Full shell command string to execute
|
|
211
|
+
* @returns ExecuteResponse with combined output, exit code, and truncation flag
|
|
212
|
+
*/
|
|
213
|
+
execute(command: string): MaybePromise<ExecuteResponse>;
|
|
214
|
+
/** Unique identifier for the sandbox backend instance */
|
|
215
|
+
readonly id: string;
|
|
216
|
+
}
|
|
217
|
+
//#endregion
|
|
20
218
|
//#region src/backends/protocol.d.ts
|
|
219
|
+
/** @deprecated Use {@link BackendProtocolV2} instead. */
|
|
220
|
+
interface BackendProtocol extends BackendProtocolV1 {}
|
|
221
|
+
/** @deprecated Use {@link SandboxBackendProtocolV2} instead. */
|
|
222
|
+
interface SandboxBackendProtocol extends SandboxBackendProtocolV1 {}
|
|
21
223
|
type MaybePromise<T> = T | Promise<T>;
|
|
22
224
|
/**
|
|
23
225
|
* Structured file listing info.
|
|
@@ -47,18 +249,97 @@ interface GrepMatch {
|
|
|
47
249
|
text: string;
|
|
48
250
|
}
|
|
49
251
|
/**
|
|
50
|
-
*
|
|
252
|
+
* Structured result from grep/search operations.
|
|
253
|
+
*/
|
|
254
|
+
interface GrepResult {
|
|
255
|
+
/** Error message on failure, undefined on success */
|
|
256
|
+
error?: string;
|
|
257
|
+
/** Structured grep match entries, undefined on failure */
|
|
258
|
+
matches?: GrepMatch[];
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Legacy file data format (v1).
|
|
51
262
|
*
|
|
52
|
-
*
|
|
263
|
+
* Content is stored as an array of lines (split on "\n"). This format
|
|
264
|
+
* only supports text files and is retained for backwards compatibility
|
|
265
|
+
* with existing state/store data.
|
|
53
266
|
*/
|
|
54
|
-
interface
|
|
55
|
-
/**
|
|
267
|
+
interface FileDataV1 {
|
|
268
|
+
/** File content as an array of lines */
|
|
56
269
|
content: string[];
|
|
57
270
|
/** ISO format timestamp of creation */
|
|
58
271
|
created_at: string;
|
|
59
272
|
/** ISO format timestamp of last modification */
|
|
60
273
|
modified_at: string;
|
|
61
274
|
}
|
|
275
|
+
/**
|
|
276
|
+
* Current file data format (v2).
|
|
277
|
+
*
|
|
278
|
+
* Content is stored as a string for text files, or as a Uint8Array for
|
|
279
|
+
* binary files (images, PDFs, audio, etc.). The MIME type is stored
|
|
280
|
+
* alongside the content, allowing backend implementations to determine
|
|
281
|
+
* it however they see fit (e.g. from file extension, HTTP headers,
|
|
282
|
+
* database metadata, etc.).
|
|
283
|
+
*/
|
|
284
|
+
interface FileDataV2 {
|
|
285
|
+
/** File content: string for text, Uint8Array for binary */
|
|
286
|
+
content: string | Uint8Array;
|
|
287
|
+
/** MIME type of the file (e.g. "image/png", "text/plain") */
|
|
288
|
+
mimeType: string;
|
|
289
|
+
/** ISO format timestamp of creation */
|
|
290
|
+
created_at: string;
|
|
291
|
+
/** ISO format timestamp of last modification */
|
|
292
|
+
modified_at: string;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Union of v1 and v2 file data formats.
|
|
296
|
+
*
|
|
297
|
+
* Backends may encounter either format when reading from state or store
|
|
298
|
+
* (v1 from legacy data, v2 from new writes). Use {@link isFileDataV1}
|
|
299
|
+
* from utils for runtime discrimination.
|
|
300
|
+
*/
|
|
301
|
+
type FileData = FileDataV1 | FileDataV2;
|
|
302
|
+
/**
|
|
303
|
+
* Structured result from backend read operations.
|
|
304
|
+
*
|
|
305
|
+
* Replaces the previous plain string return, giving callers a
|
|
306
|
+
* programmatic way to distinguish errors from content.
|
|
307
|
+
*/
|
|
308
|
+
interface ReadResult {
|
|
309
|
+
/** Error message on failure, undefined on success */
|
|
310
|
+
error?: string;
|
|
311
|
+
/** File content: string for text, Uint8Array for binary. Undefined on failure. */
|
|
312
|
+
content?: string | Uint8Array;
|
|
313
|
+
/** MIME type of the file, when available */
|
|
314
|
+
mimeType?: string;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Structured result from backend readRaw operations.
|
|
318
|
+
*/
|
|
319
|
+
interface ReadRawResult {
|
|
320
|
+
/** Error message on failure, undefined on success */
|
|
321
|
+
error?: string;
|
|
322
|
+
/** Raw file data, undefined on failure */
|
|
323
|
+
data?: FileData;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Structured result from backend ls operations.
|
|
327
|
+
*/
|
|
328
|
+
interface LsResult {
|
|
329
|
+
/** Error message on failure, undefined on success */
|
|
330
|
+
error?: string;
|
|
331
|
+
/** List of FileInfo objects, undefined on failure */
|
|
332
|
+
files?: FileInfo[];
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Structured result from backend glob operations.
|
|
336
|
+
*/
|
|
337
|
+
interface GlobResult {
|
|
338
|
+
/** Error message on failure, undefined on success */
|
|
339
|
+
error?: string;
|
|
340
|
+
/** List of FileInfo objects matching the pattern, undefined on failure */
|
|
341
|
+
files?: FileInfo[];
|
|
342
|
+
}
|
|
62
343
|
/**
|
|
63
344
|
* Result from backend write operations.
|
|
64
345
|
*
|
|
@@ -74,6 +355,9 @@ interface WriteResult {
|
|
|
74
355
|
* State update dict for checkpoint backends, null for external storage.
|
|
75
356
|
* Checkpoint backends populate this with {file_path: file_data} for LangGraph state.
|
|
76
357
|
* External backends set null (already persisted to disk/S3/database/etc).
|
|
358
|
+
*
|
|
359
|
+
* @deprecated Zero-arg backends send state updates internally via
|
|
360
|
+
* `__pregel_send`. Check `if (result.filesUpdate)` before using.
|
|
77
361
|
*/
|
|
78
362
|
filesUpdate?: Record<string, FileData> | null;
|
|
79
363
|
/** Metadata for the write operation, attached to the ToolMessage */
|
|
@@ -94,6 +378,9 @@ interface EditResult {
|
|
|
94
378
|
* State update dict for checkpoint backends, null for external storage.
|
|
95
379
|
* Checkpoint backends populate this with {file_path: file_data} for LangGraph state.
|
|
96
380
|
* External backends set null (already persisted to disk/S3/database/etc).
|
|
381
|
+
*
|
|
382
|
+
* @deprecated Zero-arg backends send state updates internally via
|
|
383
|
+
* `__pregel_send`. Check `if (result.filesUpdate)` before using.
|
|
97
384
|
*/
|
|
98
385
|
filesUpdate?: Record<string, FileData> | null;
|
|
99
386
|
/** Number of replacements made, undefined on failure */
|
|
@@ -138,120 +425,36 @@ interface FileUploadResponse {
|
|
|
138
425
|
error: FileOperationError | null;
|
|
139
426
|
}
|
|
140
427
|
/**
|
|
141
|
-
*
|
|
428
|
+
* Common options shared across backend constructors.
|
|
429
|
+
*/
|
|
430
|
+
interface BackendOptions {
|
|
431
|
+
/** File data format to use for new writes. Defaults to "v2". */
|
|
432
|
+
fileFormat?: "v1" | "v2";
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Type guard to check if a backend supports execution.
|
|
142
436
|
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
437
|
+
* @param backend - Backend instance to check
|
|
438
|
+
* @returns True if the backend implements SandboxBackendProtocolV2
|
|
439
|
+
*/
|
|
440
|
+
declare function isSandboxBackend(backend: unknown): backend is SandboxBackendProtocolV2;
|
|
441
|
+
/**
|
|
442
|
+
* Union of v1 and v2 sandbox backend protocols.
|
|
145
443
|
*
|
|
146
|
-
*
|
|
444
|
+
* Use this when accepting either protocol version. Pass through
|
|
445
|
+
* {@link adaptSandboxProtocol} to normalize to {@link SandboxBackendProtocolV2}.
|
|
446
|
+
*/
|
|
447
|
+
type AnySandboxProtocol = SandboxBackendProtocol | SandboxBackendProtocolV2;
|
|
448
|
+
/**
|
|
449
|
+
* Type guard to check if a backend is a sandbox protocol (v1 or v2).
|
|
147
450
|
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
451
|
+
* Checks for the presence of `execute` function and `id` string,
|
|
452
|
+
* which are the defining features of sandbox protocols.
|
|
453
|
+
*
|
|
454
|
+
* @param backend - Backend instance to check
|
|
455
|
+
* @returns True if the backend implements sandbox protocol (v1 or v2)
|
|
150
456
|
*/
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Structured listing with file metadata.
|
|
154
|
-
*
|
|
155
|
-
* Lists files and directories in the specified directory (non-recursive).
|
|
156
|
-
* Directories have a trailing / in their path and is_dir=true.
|
|
157
|
-
*
|
|
158
|
-
* @param path - Absolute path to directory
|
|
159
|
-
* @returns List of FileInfo objects for files and directories directly in the directory
|
|
160
|
-
*/
|
|
161
|
-
lsInfo(path: string): MaybePromise<FileInfo[]>;
|
|
162
|
-
/**
|
|
163
|
-
* Read file content with line numbers or an error string.
|
|
164
|
-
*
|
|
165
|
-
* @param filePath - Absolute file path
|
|
166
|
-
* @param offset - Line offset to start reading from (0-indexed), default 0
|
|
167
|
-
* @param limit - Maximum number of lines to read, default 500
|
|
168
|
-
* @returns Formatted file content with line numbers, or error message
|
|
169
|
-
*/
|
|
170
|
-
read(filePath: string, offset?: number, limit?: number): MaybePromise<string>;
|
|
171
|
-
/**
|
|
172
|
-
* Read file content as raw FileData.
|
|
173
|
-
*
|
|
174
|
-
* @param filePath - Absolute file path
|
|
175
|
-
* @returns Raw file content as FileData
|
|
176
|
-
*/
|
|
177
|
-
readRaw(filePath: string): MaybePromise<FileData>;
|
|
178
|
-
/**
|
|
179
|
-
* Structured search results or error string for invalid input.
|
|
180
|
-
*
|
|
181
|
-
* Searches file contents for a regex pattern.
|
|
182
|
-
*
|
|
183
|
-
* @param pattern - Regex pattern to search for
|
|
184
|
-
* @param path - Base path to search from (default: null)
|
|
185
|
-
* @param glob - Optional glob pattern to filter files (e.g., "*.py")
|
|
186
|
-
* @returns List of GrepMatch objects or error string for invalid regex
|
|
187
|
-
*/
|
|
188
|
-
grepRaw(pattern: string, path?: string | null, glob?: string | null): MaybePromise<GrepMatch[] | string>;
|
|
189
|
-
/**
|
|
190
|
-
* Structured glob matching returning FileInfo objects.
|
|
191
|
-
*
|
|
192
|
-
* @param pattern - Glob pattern (e.g., `*.py`, `**\/*.ts`)
|
|
193
|
-
* @param path - Base path to search from (default: "/")
|
|
194
|
-
* @returns List of FileInfo objects matching the pattern
|
|
195
|
-
*/
|
|
196
|
-
globInfo(pattern: string, path?: string): MaybePromise<FileInfo[]>;
|
|
197
|
-
/**
|
|
198
|
-
* Create a new file.
|
|
199
|
-
*
|
|
200
|
-
* @param filePath - Absolute file path
|
|
201
|
-
* @param content - File content as string
|
|
202
|
-
* @returns WriteResult with error populated on failure
|
|
203
|
-
*/
|
|
204
|
-
write(filePath: string, content: string): MaybePromise<WriteResult>;
|
|
205
|
-
/**
|
|
206
|
-
* Edit a file by replacing string occurrences.
|
|
207
|
-
*
|
|
208
|
-
* @param filePath - Absolute file path
|
|
209
|
-
* @param oldString - String to find and replace
|
|
210
|
-
* @param newString - Replacement string
|
|
211
|
-
* @param replaceAll - If true, replace all occurrences (default: false)
|
|
212
|
-
* @returns EditResult with error, path, filesUpdate, and occurrences
|
|
213
|
-
*/
|
|
214
|
-
edit(filePath: string, oldString: string, newString: string, replaceAll?: boolean): MaybePromise<EditResult>;
|
|
215
|
-
/**
|
|
216
|
-
* Upload multiple files.
|
|
217
|
-
* Optional - backends that don't support file upload can omit this.
|
|
218
|
-
*
|
|
219
|
-
* @param files - List of [path, content] tuples to upload
|
|
220
|
-
* @returns List of FileUploadResponse objects, one per input file
|
|
221
|
-
*/
|
|
222
|
-
uploadFiles?(files: Array<[string, Uint8Array]>): MaybePromise<FileUploadResponse[]>;
|
|
223
|
-
/**
|
|
224
|
-
* Download multiple files.
|
|
225
|
-
* Optional - backends that don't support file download can omit this.
|
|
226
|
-
*
|
|
227
|
-
* @param paths - List of file paths to download
|
|
228
|
-
* @returns List of FileDownloadResponse objects, one per input path
|
|
229
|
-
*/
|
|
230
|
-
downloadFiles?(paths: string[]): MaybePromise<FileDownloadResponse[]>;
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Protocol for sandboxed backends with isolated runtime.
|
|
234
|
-
* Sandboxed backends run in isolated environments (e.g., containers)
|
|
235
|
-
* and communicate via defined interfaces.
|
|
236
|
-
*/
|
|
237
|
-
interface SandboxBackendProtocol extends BackendProtocol {
|
|
238
|
-
/**
|
|
239
|
-
* Execute a command in the sandbox.
|
|
240
|
-
*
|
|
241
|
-
* @param command - Full shell command string to execute
|
|
242
|
-
* @returns ExecuteResponse with combined output, exit code, and truncation flag
|
|
243
|
-
*/
|
|
244
|
-
execute(command: string): MaybePromise<ExecuteResponse>;
|
|
245
|
-
/** Unique identifier for the sandbox backend instance */
|
|
246
|
-
readonly id: string;
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Type guard to check if a backend supports execution.
|
|
250
|
-
*
|
|
251
|
-
* @param backend - Backend instance to check
|
|
252
|
-
* @returns True if the backend implements SandboxBackendProtocol
|
|
253
|
-
*/
|
|
254
|
-
declare function isSandboxBackend(backend: BackendProtocol): backend is SandboxBackendProtocol;
|
|
457
|
+
declare function isSandboxProtocol(backend: unknown): backend is AnySandboxProtocol;
|
|
255
458
|
/**
|
|
256
459
|
* Metadata for a single sandbox instance.
|
|
257
460
|
*
|
|
@@ -423,8 +626,18 @@ interface StateAndStore {
|
|
|
423
626
|
/** Optional assistant ID for per-assistant isolation in store */
|
|
424
627
|
assistantId?: string;
|
|
425
628
|
}
|
|
629
|
+
/**
|
|
630
|
+
* Union of v1 and v2 backend protocols.
|
|
631
|
+
*
|
|
632
|
+
* Use this when accepting either protocol version. Pass through
|
|
633
|
+
* {@link adaptBackendProtocol} to normalize to {@link BackendProtocolV2}.
|
|
634
|
+
*/
|
|
635
|
+
type AnyBackendProtocol = BackendProtocolV1 | BackendProtocolV2;
|
|
426
636
|
/**
|
|
427
637
|
* Agent {@link Runtime} with `state`
|
|
638
|
+
*
|
|
639
|
+
* @deprecated Backends now read state from the LangGraph execution context
|
|
640
|
+
* via `getCurrentTaskInput()`, `getConfig()`, and `getStore()`.
|
|
428
641
|
*/
|
|
429
642
|
interface BackendRuntime<StateT = unknown> extends Runtime {
|
|
430
643
|
/** Current agent state with files, messages, etc. */
|
|
@@ -436,6 +649,9 @@ interface BackendRuntime<StateT = unknown> extends Runtime {
|
|
|
436
649
|
* Backends receive {@link BackendRuntime} which contains the current state
|
|
437
650
|
* and runtime information, extracted from the execution context.
|
|
438
651
|
*
|
|
652
|
+
* @deprecated Pass a pre-constructed backend instance instead of a factory.
|
|
653
|
+
* E.g., `backend: new StateBackend()` instead of `backend: (runtime) => new StateBackend(runtime)`.
|
|
654
|
+
*
|
|
439
655
|
* @example
|
|
440
656
|
* ```typescript
|
|
441
657
|
* // Using in middleware
|
|
@@ -444,15 +660,17 @@ interface BackendRuntime<StateT = unknown> extends Runtime {
|
|
|
444
660
|
* });
|
|
445
661
|
* ```
|
|
446
662
|
*/
|
|
447
|
-
type BackendFactory = (runtime: BackendRuntime) => MaybePromise<
|
|
663
|
+
type BackendFactory = (runtime: BackendRuntime) => MaybePromise<AnyBackendProtocol>;
|
|
448
664
|
/**
|
|
449
665
|
* Resolve a backend instance or await a {@link BackendFactory}.
|
|
450
666
|
*
|
|
451
667
|
* Accepts {@link BackendRuntime} or {@link ToolRuntime} — store typing differs
|
|
452
668
|
* between LangGraph checkpoint stores and core `ToolRuntime`; factories receive
|
|
453
669
|
* a value that is structurally compatible at runtime.
|
|
670
|
+
*
|
|
671
|
+
* @internal
|
|
454
672
|
*/
|
|
455
|
-
declare function resolveBackend(backend:
|
|
673
|
+
declare function resolveBackend(backend: AnyBackendProtocol | BackendFactory, runtime: BackendRuntime | ToolRuntime): Promise<BackendProtocolV2>;
|
|
456
674
|
//#endregion
|
|
457
675
|
//#region src/middleware/fs.d.ts
|
|
458
676
|
/**
|
|
@@ -468,7 +686,7 @@ type FilesRecordUpdate = Record<string, FileData | null>;
|
|
|
468
686
|
*/
|
|
469
687
|
interface FilesystemMiddlewareOptions {
|
|
470
688
|
/** Backend instance or factory (default: StateBackend) */
|
|
471
|
-
backend?:
|
|
689
|
+
backend?: AnyBackendProtocol | BackendFactory;
|
|
472
690
|
/** Optional custom system prompt override */
|
|
473
691
|
systemPrompt?: string | null;
|
|
474
692
|
/** Optional custom tool descriptions override */
|
|
@@ -501,7 +719,14 @@ declare function createFilesystemMiddleware(options?: FilesystemMiddlewareOption
|
|
|
501
719
|
file_path: string;
|
|
502
720
|
offset?: unknown;
|
|
503
721
|
limit?: unknown;
|
|
504
|
-
},
|
|
722
|
+
}, {
|
|
723
|
+
type: string;
|
|
724
|
+
text: string;
|
|
725
|
+
}[] | {
|
|
726
|
+
type: string;
|
|
727
|
+
mimeType: string;
|
|
728
|
+
data: string;
|
|
729
|
+
}[], unknown, "read_file"> | _langchain.DynamicStructuredTool<z.ZodObject<{
|
|
505
730
|
file_path: z.ZodString;
|
|
506
731
|
content: z.ZodDefault<z.ZodString>;
|
|
507
732
|
}, z.core.$strip>, {
|
|
@@ -543,11 +768,11 @@ declare function createFilesystemMiddleware(options?: FilesystemMiddlewareOption
|
|
|
543
768
|
}, string, unknown, "glob"> | _langchain.DynamicStructuredTool<z.ZodObject<{
|
|
544
769
|
pattern: z.ZodString;
|
|
545
770
|
path: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
546
|
-
glob: z.ZodNullable<z.ZodOptional<z.ZodString
|
|
771
|
+
glob: z.ZodDefault<z.ZodNullable<z.ZodOptional<z.ZodString>>>;
|
|
547
772
|
}, z.core.$strip>, {
|
|
548
773
|
pattern: string;
|
|
549
774
|
path: string;
|
|
550
|
-
glob
|
|
775
|
+
glob: string | null;
|
|
551
776
|
}, {
|
|
552
777
|
pattern: string;
|
|
553
778
|
path?: string | undefined;
|
|
@@ -560,1354 +785,1649 @@ declare function createFilesystemMiddleware(options?: FilesystemMiddlewareOption
|
|
|
560
785
|
command: string;
|
|
561
786
|
}, string, unknown, "execute">)[]>;
|
|
562
787
|
//#endregion
|
|
563
|
-
//#region src/
|
|
564
|
-
/**
|
|
565
|
-
* Default system prompt for subagents.
|
|
566
|
-
* Provides a minimal base prompt that can be extended by specific subagent configurations.
|
|
567
|
-
*/
|
|
568
|
-
declare const DEFAULT_SUBAGENT_PROMPT = "In order to complete the objective that the user asks of you, you have access to a number of standard tools.";
|
|
569
|
-
/**
|
|
570
|
-
* Default description for the general-purpose subagent.
|
|
571
|
-
* This description is shown to the model when selecting which subagent to use.
|
|
572
|
-
*/
|
|
573
|
-
declare const DEFAULT_GENERAL_PURPOSE_DESCRIPTION = "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. This agent has access to all tools as the main agent.";
|
|
574
|
-
/**
|
|
575
|
-
* System prompt section that explains how to use the task tool for spawning subagents.
|
|
576
|
-
*
|
|
577
|
-
* This prompt is automatically appended to the main agent's system prompt when
|
|
578
|
-
* using `createSubAgentMiddleware`. It provides guidance on:
|
|
579
|
-
* - When to use the task tool
|
|
580
|
-
* - Subagent lifecycle (spawn → run → return → reconcile)
|
|
581
|
-
* - When NOT to use the task tool
|
|
582
|
-
* - Best practices for parallel task execution
|
|
583
|
-
*
|
|
584
|
-
* You can provide a custom `systemPrompt` to `createSubAgentMiddleware` to override
|
|
585
|
-
* or extend this default.
|
|
586
|
-
*/
|
|
587
|
-
declare const TASK_SYSTEM_PROMPT = "## `task` (subagent spawner)\n\nYou have access to a `task` tool to launch short-lived subagents that handle isolated tasks. These agents are ephemeral \u2014 they live only for the duration of the task and return a single result.\n\nWhen to use the task tool:\n- When a task is complex and multi-step, and can be fully delegated in isolation\n- When a task is independent of other tasks and can run in parallel\n- When a task requires focused reasoning or heavy token/context usage that would bloat the orchestrator thread\n- When sandboxing improves reliability (e.g. code execution, structured searches, data formatting)\n- When you only care about the output of the subagent, and not the intermediate steps (ex. performing a lot of research and then returned a synthesized report, performing a series of computations or lookups to achieve a concise, relevant answer.)\n\nSubagent lifecycle:\n1. **Spawn** \u2192 Provide clear role, instructions, and expected output\n2. **Run** \u2192 The subagent completes the task autonomously\n3. **Return** \u2192 The subagent provides a single structured result\n4. **Reconcile** \u2192 Incorporate or synthesize the result into the main thread\n\nWhen NOT to use the task tool:\n- If you need to see the intermediate reasoning or steps after the subagent has completed (the task tool hides them)\n- If the task is trivial (a few tool calls or simple lookup)\n- If delegating does not reduce token usage, complexity, or context switching\n- If splitting would add latency without benefit\n\n## Important Task Tool Usage Notes to Remember\n- Whenever possible, parallelize the work that you do. This is true for both tool_calls, and for tasks. Whenever you have independent steps to complete - make tool_calls, or kick off tasks (subagents) in parallel to accomplish them faster. This saves time for the user, which is incredibly important.\n- Remember to use the `task` tool to silo independent tasks within a multi-part objective.\n- You should use the `task` tool whenever you have a complex task that will take multiple steps, and is independent from other tasks that the agent needs to complete. These agents are highly competent and efficient.";
|
|
588
|
-
/**
|
|
589
|
-
* Type definitions for pre-compiled agents.
|
|
590
|
-
*
|
|
591
|
-
* @typeParam TRunnable - The type of the runnable (ReactAgent or Runnable).
|
|
592
|
-
* When using `createAgent` or `createDeepAgent`, this preserves the middleware
|
|
593
|
-
* types for type inference. Uses `ReactAgent<any>` to accept agents with any
|
|
594
|
-
* type configuration (including DeepAgent instances).
|
|
595
|
-
*/
|
|
596
|
-
interface CompiledSubAgent<TRunnable extends ReactAgent<any> | Runnable = ReactAgent<any> | Runnable> {
|
|
597
|
-
/** The name of the agent */
|
|
598
|
-
name: string;
|
|
599
|
-
/** The description of the agent */
|
|
600
|
-
description: string;
|
|
601
|
-
/** The agent instance */
|
|
602
|
-
runnable: TRunnable;
|
|
603
|
-
}
|
|
788
|
+
//#region src/backends/state.d.ts
|
|
604
789
|
/**
|
|
605
|
-
*
|
|
606
|
-
*
|
|
607
|
-
* When using `createDeepAgent`, subagents automatically receive a default middleware
|
|
608
|
-
* stack (todoListMiddleware, filesystemMiddleware, summarizationMiddleware, etc.) before
|
|
609
|
-
* any custom `middleware` specified in this spec.
|
|
610
|
-
*
|
|
611
|
-
* Required fields:
|
|
612
|
-
* - `name`: Identifier used to select this subagent in the task tool
|
|
613
|
-
* - `description`: Shown to the model for subagent selection
|
|
614
|
-
* - `systemPrompt`: The system prompt for the subagent
|
|
790
|
+
* Backend that stores files in agent state (ephemeral).
|
|
615
791
|
*
|
|
616
|
-
*
|
|
617
|
-
*
|
|
618
|
-
*
|
|
619
|
-
* - `middleware`: Additional middleware appended after defaults
|
|
620
|
-
* - `interruptOn`: Human-in-the-loop configuration for specific tools
|
|
621
|
-
* - `skills`: Skill source paths for SkillsMiddleware (e.g., `["/skills/user/", "/skills/project/"]`)
|
|
792
|
+
* Uses LangGraph's state management and checkpointing. Files persist within
|
|
793
|
+
* a conversation thread but not across threads. State is automatically
|
|
794
|
+
* checkpointed after each agent step.
|
|
622
795
|
*
|
|
623
|
-
*
|
|
624
|
-
*
|
|
625
|
-
*
|
|
626
|
-
* name: "researcher",
|
|
627
|
-
* description: "Research assistant for complex topics",
|
|
628
|
-
* systemPrompt: "You are a research assistant.",
|
|
629
|
-
* tools: [webSearchTool],
|
|
630
|
-
* skills: ["/skills/research/"],
|
|
631
|
-
* };
|
|
632
|
-
* ```
|
|
796
|
+
* Special handling: Since LangGraph state must be updated via Command objects
|
|
797
|
+
* (not direct mutation), operations return filesUpdate in WriteResult/EditResult
|
|
798
|
+
* for the middleware to apply via Command.
|
|
633
799
|
*/
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
description: string;
|
|
639
|
-
/** The system prompt to use for the agent */
|
|
640
|
-
systemPrompt: string;
|
|
641
|
-
/** The tools to use for the agent (tool instances, not names). Defaults to defaultTools */
|
|
642
|
-
tools?: StructuredTool[];
|
|
643
|
-
/** The model for the agent. Defaults to defaultModel */
|
|
644
|
-
model?: LanguageModelLike | string;
|
|
645
|
-
/** Additional middleware to append after default_middleware */
|
|
646
|
-
middleware?: readonly AgentMiddleware$1[];
|
|
647
|
-
/** Human-in-the-loop configuration for specific tools. Requires a checkpointer. */
|
|
648
|
-
interruptOn?: Record<string, boolean | InterruptOnConfig>;
|
|
800
|
+
declare class StateBackend implements BackendProtocolV2 {
|
|
801
|
+
private runtime;
|
|
802
|
+
private fileFormat;
|
|
803
|
+
constructor(options?: BackendOptions);
|
|
649
804
|
/**
|
|
650
|
-
*
|
|
805
|
+
* @deprecated Pass no `runtime` argument
|
|
806
|
+
*/
|
|
807
|
+
constructor(runtime: BackendRuntime, options?: BackendOptions);
|
|
808
|
+
/**
|
|
809
|
+
* Whether this instance was constructed with the legacy factory pattern.
|
|
651
810
|
*
|
|
652
|
-
*
|
|
653
|
-
*
|
|
654
|
-
*
|
|
811
|
+
* When true, state is read from the injected `runtime` and `filesUpdate`
|
|
812
|
+
* is returned to the caller. When false, state is read from LangGraph's
|
|
813
|
+
* execution context and updates are sent via `__pregel_send`.
|
|
814
|
+
*/
|
|
815
|
+
private get isLegacy();
|
|
816
|
+
/**
|
|
817
|
+
* Get files from current state.
|
|
655
818
|
*
|
|
656
|
-
*
|
|
657
|
-
*
|
|
819
|
+
* In legacy mode, reads from the injected {@link BackendRuntime}.
|
|
820
|
+
* In zero-arg mode, reads from the LangGraph execution context via
|
|
821
|
+
* {@link getCurrentTaskInput}.
|
|
822
|
+
*/
|
|
823
|
+
private getFiles;
|
|
824
|
+
/**
|
|
825
|
+
* Push a files state update through LangGraph's internal send channel.
|
|
658
826
|
*
|
|
659
|
-
*
|
|
660
|
-
*
|
|
661
|
-
*
|
|
662
|
-
*
|
|
663
|
-
*
|
|
664
|
-
*
|
|
665
|
-
* skills: ["/skills/research/", "/skills/web-search/"],
|
|
666
|
-
* };
|
|
667
|
-
* ```
|
|
827
|
+
* In zero-arg mode, sends the update via the `__pregel_send` function
|
|
828
|
+
* from {@link getConfig}, mirroring Python's `CONFIG_KEY_SEND`.
|
|
829
|
+
* In legacy mode, this is a no-op — the caller uses `filesUpdate`
|
|
830
|
+
* from the return value instead.
|
|
831
|
+
*
|
|
832
|
+
* @param update - Map of file paths to their updated {@link FileData}
|
|
668
833
|
*/
|
|
669
|
-
|
|
834
|
+
private sendFilesUpdate;
|
|
670
835
|
/**
|
|
671
|
-
*
|
|
836
|
+
* List files and directories in the specified directory (non-recursive).
|
|
672
837
|
*
|
|
673
|
-
*
|
|
674
|
-
*
|
|
675
|
-
*
|
|
838
|
+
* @param path - Absolute path to directory
|
|
839
|
+
* @returns LsResult with list of FileInfo objects on success or error on failure.
|
|
840
|
+
* Directories have a trailing / in their path and is_dir=true.
|
|
841
|
+
*/
|
|
842
|
+
ls(path: string): LsResult;
|
|
843
|
+
/**
|
|
844
|
+
* Read file content.
|
|
676
845
|
*
|
|
677
|
-
*
|
|
678
|
-
*
|
|
846
|
+
* Text files are paginated by line offset/limit.
|
|
847
|
+
* Binary files return full Uint8Array content (offset/limit ignored).
|
|
679
848
|
*
|
|
680
|
-
* @
|
|
681
|
-
*
|
|
682
|
-
*
|
|
849
|
+
* @param filePath - Absolute file path
|
|
850
|
+
* @param offset - Line offset to start reading from (0-indexed)
|
|
851
|
+
* @param limit - Maximum number of lines to read
|
|
852
|
+
* @returns ReadResult with content on success or error on failure
|
|
853
|
+
*/
|
|
854
|
+
read(filePath: string, offset?: number, limit?: number): ReadResult;
|
|
855
|
+
/**
|
|
856
|
+
* Read file content as raw FileData.
|
|
683
857
|
*
|
|
684
|
-
*
|
|
685
|
-
*
|
|
686
|
-
* description: "Analyzes data and returns structured findings",
|
|
687
|
-
* systemPrompt: "Analyze the data and return your findings.",
|
|
688
|
-
* responseFormat: z.object({
|
|
689
|
-
* findings: z.string(),
|
|
690
|
-
* confidence: z.number(),
|
|
691
|
-
* }),
|
|
692
|
-
* };
|
|
693
|
-
* ```
|
|
858
|
+
* @param filePath - Absolute file path
|
|
859
|
+
* @returns ReadRawResult with raw file data on success or error on failure
|
|
694
860
|
*/
|
|
695
|
-
|
|
861
|
+
readRaw(filePath: string): ReadRawResult;
|
|
862
|
+
/**
|
|
863
|
+
* Create a new file with content.
|
|
864
|
+
* Returns WriteResult with filesUpdate to update LangGraph state.
|
|
865
|
+
*/
|
|
866
|
+
write(filePath: string, content: string): WriteResult;
|
|
867
|
+
/**
|
|
868
|
+
* Edit a file by replacing string occurrences.
|
|
869
|
+
* Returns EditResult with filesUpdate and occurrences.
|
|
870
|
+
*/
|
|
871
|
+
edit(filePath: string, oldString: string, newString: string, replaceAll?: boolean): EditResult;
|
|
872
|
+
/**
|
|
873
|
+
* Search file contents for a literal text pattern.
|
|
874
|
+
* Binary files are skipped.
|
|
875
|
+
*/
|
|
876
|
+
grep(pattern: string, path?: string, glob?: string | null): GrepResult;
|
|
877
|
+
/**
|
|
878
|
+
* Structured glob matching returning FileInfo objects.
|
|
879
|
+
*/
|
|
880
|
+
glob(pattern: string, path?: string): GlobResult;
|
|
881
|
+
/**
|
|
882
|
+
* Upload multiple files.
|
|
883
|
+
*
|
|
884
|
+
* Note: Since LangGraph state must be updated via Command objects,
|
|
885
|
+
* the caller must apply filesUpdate via Command after calling this method.
|
|
886
|
+
*
|
|
887
|
+
* @param files - List of [path, content] tuples to upload
|
|
888
|
+
* @returns List of FileUploadResponse objects, one per input file
|
|
889
|
+
*/
|
|
890
|
+
uploadFiles(files: Array<[string, Uint8Array]>): FileUploadResponse[] & {
|
|
891
|
+
filesUpdate?: Record<string, FileData>;
|
|
892
|
+
};
|
|
893
|
+
/**
|
|
894
|
+
* Download multiple files.
|
|
895
|
+
*
|
|
896
|
+
* @param paths - List of file paths to download
|
|
897
|
+
* @returns List of FileDownloadResponse objects, one per input path
|
|
898
|
+
*/
|
|
899
|
+
downloadFiles(paths: string[]): FileDownloadResponse[];
|
|
696
900
|
}
|
|
901
|
+
//#endregion
|
|
902
|
+
//#region src/backends/store.d.ts
|
|
697
903
|
/**
|
|
698
|
-
*
|
|
699
|
-
*
|
|
700
|
-
* This constant provides the default configuration for the general-purpose subagent
|
|
701
|
-
* that is automatically included when `generalPurposeAgent: true` (the default).
|
|
702
|
-
*
|
|
703
|
-
* The general-purpose subagent:
|
|
704
|
-
* - Has access to all tools from the main agent
|
|
705
|
-
* - Inherits skills from the main agent (when skills are configured)
|
|
706
|
-
* - Uses the same model as the main agent (by default)
|
|
707
|
-
* - Is ideal for delegating complex, multi-step tasks
|
|
708
|
-
*
|
|
709
|
-
* You can spread this constant and override specific properties when creating
|
|
710
|
-
* custom subagents that should behave similarly to the general-purpose agent:
|
|
711
|
-
*
|
|
712
|
-
* @example
|
|
713
|
-
* ```typescript
|
|
714
|
-
* import { GENERAL_PURPOSE_SUBAGENT, createDeepAgent } from "@anthropic/deepagents";
|
|
715
|
-
*
|
|
716
|
-
* // Use as-is (automatically included with generalPurposeAgent: true)
|
|
717
|
-
* const agent = createDeepAgent({ model: "claude-sonnet-4-5-20250929" });
|
|
718
|
-
*
|
|
719
|
-
* // Or create a custom variant with different tools
|
|
720
|
-
* const customGP: SubAgent = {
|
|
721
|
-
* ...GENERAL_PURPOSE_SUBAGENT,
|
|
722
|
-
* name: "research-gp",
|
|
723
|
-
* tools: [webSearchTool, readFileTool],
|
|
724
|
-
* };
|
|
725
|
-
*
|
|
726
|
-
* const agent = createDeepAgent({
|
|
727
|
-
* model: "claude-sonnet-4-5-20250929",
|
|
728
|
-
* subagents: [customGP],
|
|
729
|
-
* // Disable the default general-purpose agent since we're providing our own
|
|
730
|
-
* // (handled automatically when using createSubAgentMiddleware directly)
|
|
731
|
-
* });
|
|
732
|
-
* ```
|
|
733
|
-
*/
|
|
734
|
-
declare const GENERAL_PURPOSE_SUBAGENT: Pick<SubAgent, "name" | "description" | "systemPrompt">;
|
|
735
|
-
/**
|
|
736
|
-
* Options for creating subagent middleware
|
|
904
|
+
* Options for StoreBackend constructor.
|
|
737
905
|
*/
|
|
738
|
-
interface
|
|
739
|
-
/** The model to use for subagents */
|
|
740
|
-
defaultModel: LanguageModelLike | string;
|
|
741
|
-
/** The tools to use for the default general-purpose subagent */
|
|
742
|
-
defaultTools?: StructuredTool[];
|
|
743
|
-
/** Default middleware to apply to custom subagents (WITHOUT skills from main agent) */
|
|
744
|
-
defaultMiddleware?: AgentMiddleware$1[] | null;
|
|
906
|
+
interface StoreBackendOptions extends BackendOptions {
|
|
745
907
|
/**
|
|
746
|
-
*
|
|
747
|
-
*
|
|
908
|
+
* Custom namespace for store operations.
|
|
909
|
+
*
|
|
910
|
+
* Determines where files are stored in the LangGraph store, enabling
|
|
911
|
+
* user-scoped, org-scoped, or any custom isolation pattern.
|
|
912
|
+
*
|
|
913
|
+
* If not provided, falls back to legacy behavior using assistantId from {@link BackendRuntime}.
|
|
914
|
+
*
|
|
915
|
+
* @example
|
|
916
|
+
* ```typescript
|
|
917
|
+
* // User-scoped storage
|
|
918
|
+
* new StoreBackend(runtime, {
|
|
919
|
+
* namespace: ["memories", orgId, userId, "filesystem"],
|
|
920
|
+
* });
|
|
921
|
+
*
|
|
922
|
+
* // Org-scoped storage
|
|
923
|
+
* new StoreBackend(runtime, {
|
|
924
|
+
* namespace: ["memories", orgId, "filesystem"],
|
|
925
|
+
* });
|
|
926
|
+
* ```
|
|
748
927
|
*/
|
|
749
|
-
|
|
750
|
-
/** The tool configs for the default general-purpose subagent */
|
|
751
|
-
defaultInterruptOn?: Record<string, boolean | InterruptOnConfig> | null;
|
|
752
|
-
/** A list of additional subagents to provide to the agent */
|
|
753
|
-
subagents?: (SubAgent | CompiledSubAgent)[];
|
|
754
|
-
/** Full system prompt override */
|
|
755
|
-
systemPrompt?: string | null;
|
|
756
|
-
/** Whether to include the general-purpose agent */
|
|
757
|
-
generalPurposeAgent?: boolean;
|
|
758
|
-
/** Custom description for the task tool */
|
|
759
|
-
taskDescription?: string | null;
|
|
928
|
+
namespace?: string[];
|
|
760
929
|
}
|
|
761
930
|
/**
|
|
762
|
-
*
|
|
763
|
-
*/
|
|
764
|
-
declare function createSubAgentMiddleware(options: SubAgentMiddlewareOptions): AgentMiddleware$1<undefined, undefined, unknown, readonly [_langchain.DynamicStructuredTool<z.ZodObject<{
|
|
765
|
-
description: z.ZodString;
|
|
766
|
-
subagent_type: z.ZodString;
|
|
767
|
-
}, z.core.$strip>, {
|
|
768
|
-
description: string;
|
|
769
|
-
subagent_type: string;
|
|
770
|
-
}, {
|
|
771
|
-
description: string;
|
|
772
|
-
subagent_type: string;
|
|
773
|
-
}, string | Command<unknown, Record<string, unknown>, string>, unknown, "task">]>;
|
|
774
|
-
//#endregion
|
|
775
|
-
//#region src/middleware/patch_tool_calls.d.ts
|
|
776
|
-
/**
|
|
777
|
-
* Create middleware that enforces strict tool call / tool response parity in
|
|
778
|
-
* the messages history.
|
|
779
|
-
*
|
|
780
|
-
* Two kinds of violations are repaired:
|
|
781
|
-
* 1. **Dangling tool_calls** — an AIMessage contains tool_calls with no
|
|
782
|
-
* matching ToolMessage responses. Synthetic cancellation ToolMessages are
|
|
783
|
-
* injected so every tool_call has a response.
|
|
784
|
-
* 2. **Orphaned ToolMessages** — a ToolMessage exists whose `tool_call_id`
|
|
785
|
-
* does not match any tool_call in a preceding AIMessage. These are removed.
|
|
786
|
-
*
|
|
787
|
-
* This is critical for providers like Google Gemini that reject requests with
|
|
788
|
-
* mismatched function call / function response counts (400 INVALID_ARGUMENT).
|
|
789
|
-
*
|
|
790
|
-
* This middleware patches in two places:
|
|
791
|
-
* 1. `beforeAgent`: Patches state at the start of the agent loop (handles most cases)
|
|
792
|
-
* 2. `wrapModelCall`: Patches the request right before model invocation (handles
|
|
793
|
-
* edge cases like HITL rejection during graph resume where state updates from
|
|
794
|
-
* beforeAgent may not be applied in time)
|
|
795
|
-
*
|
|
796
|
-
* @returns AgentMiddleware that enforces tool call / response parity
|
|
797
|
-
*
|
|
798
|
-
* @example
|
|
799
|
-
* ```typescript
|
|
800
|
-
* import { createAgent } from "langchain";
|
|
801
|
-
* import { createPatchToolCallsMiddleware } from "./middleware/patch_tool_calls";
|
|
802
|
-
*
|
|
803
|
-
* const agent = createAgent({
|
|
804
|
-
* model: "claude-sonnet-4-5-20250929",
|
|
805
|
-
* middleware: [createPatchToolCallsMiddleware()],
|
|
806
|
-
* });
|
|
807
|
-
* ```
|
|
808
|
-
*/
|
|
809
|
-
declare function createPatchToolCallsMiddleware(): AgentMiddleware<undefined, undefined, unknown, readonly (_langchain_core_tools0.ClientTool | _langchain_core_tools0.ServerTool)[]>;
|
|
810
|
-
//#endregion
|
|
811
|
-
//#region src/backends/state.d.ts
|
|
812
|
-
/**
|
|
813
|
-
* Backend that stores files in agent state (ephemeral).
|
|
931
|
+
* Backend that stores files in LangGraph's BaseStore (persistent).
|
|
814
932
|
*
|
|
815
|
-
* Uses LangGraph's
|
|
816
|
-
*
|
|
817
|
-
* checkpointed after each agent step.
|
|
933
|
+
* Uses LangGraph's Store for persistent, cross-conversation storage.
|
|
934
|
+
* Files are organized via namespaces and persist across all threads.
|
|
818
935
|
*
|
|
819
|
-
*
|
|
820
|
-
* (
|
|
821
|
-
*
|
|
936
|
+
* The namespace can be customized via a factory function for flexible
|
|
937
|
+
* isolation patterns (user-scoped, org-scoped, etc.), or falls back
|
|
938
|
+
* to legacy assistant_id-based isolation.
|
|
822
939
|
*/
|
|
823
|
-
declare class
|
|
824
|
-
private
|
|
825
|
-
|
|
940
|
+
declare class StoreBackend implements BackendProtocolV2 {
|
|
941
|
+
private stateAndStore;
|
|
942
|
+
private _namespace;
|
|
943
|
+
private fileFormat;
|
|
944
|
+
constructor(options?: StoreBackendOptions);
|
|
826
945
|
/**
|
|
827
|
-
*
|
|
946
|
+
* @deprecated Pass no `stateAndStore` argument
|
|
828
947
|
*/
|
|
829
|
-
|
|
948
|
+
constructor(stateAndStore: StateAndStore, options?: StoreBackendOptions);
|
|
949
|
+
/**
|
|
950
|
+
* Get the BaseStore instance for persistent storage operations.
|
|
951
|
+
*
|
|
952
|
+
* In legacy mode, reads from the injected {@link StateAndStore}.
|
|
953
|
+
* In zero-arg mode, retrieves the store from the LangGraph execution
|
|
954
|
+
* context via {@link getLangGraphStore}.
|
|
955
|
+
*
|
|
956
|
+
* @returns BaseStore instance
|
|
957
|
+
* @throws Error if no store is available in either mode
|
|
958
|
+
*/
|
|
959
|
+
private getStore;
|
|
960
|
+
/**
|
|
961
|
+
* Get the namespace for store operations.
|
|
962
|
+
*
|
|
963
|
+
* Resolution order:
|
|
964
|
+
* 1. Explicit namespace from constructor options (both modes)
|
|
965
|
+
* 2. Legacy mode: `[assistantId, "filesystem"]` fallback from {@link StateAndStore}
|
|
966
|
+
* 3. Zero-arg mode without namespace: `["filesystem"]` with a deprecation warning
|
|
967
|
+
* nudging callers to pass an explicit namespace
|
|
968
|
+
* 4. Legacy mode without assistantId: `["filesystem"]`
|
|
969
|
+
*/
|
|
970
|
+
protected getNamespace(): string[];
|
|
971
|
+
/**
|
|
972
|
+
* Convert a store Item to FileData format.
|
|
973
|
+
*
|
|
974
|
+
* @param storeItem - The store Item containing file data
|
|
975
|
+
* @returns FileData object
|
|
976
|
+
* @throws Error if required fields are missing or have incorrect types
|
|
977
|
+
*/
|
|
978
|
+
private convertStoreItemToFileData;
|
|
979
|
+
/**
|
|
980
|
+
* Convert FileData to a value suitable for store.put().
|
|
981
|
+
*
|
|
982
|
+
* @param fileData - The FileData to convert
|
|
983
|
+
* @returns Object with content, mimeType, created_at, and modified_at fields
|
|
984
|
+
*/
|
|
985
|
+
private convertFileDataToStoreValue;
|
|
986
|
+
/**
|
|
987
|
+
* Search store with automatic pagination to retrieve all results.
|
|
988
|
+
*
|
|
989
|
+
* @param store - The store to search
|
|
990
|
+
* @param namespace - Hierarchical path prefix to search within
|
|
991
|
+
* @param options - Optional query, filter, and page_size
|
|
992
|
+
* @returns List of all items matching the search criteria
|
|
993
|
+
*/
|
|
994
|
+
private searchStorePaginated;
|
|
830
995
|
/**
|
|
831
996
|
* List files and directories in the specified directory (non-recursive).
|
|
832
997
|
*
|
|
833
998
|
* @param path - Absolute path to directory
|
|
834
|
-
* @returns
|
|
999
|
+
* @returns LsResult with list of FileInfo objects on success or error on failure.
|
|
835
1000
|
* Directories have a trailing / in their path and is_dir=true.
|
|
836
1001
|
*/
|
|
837
|
-
|
|
1002
|
+
ls(path: string): Promise<LsResult>;
|
|
838
1003
|
/**
|
|
839
|
-
* Read file content
|
|
1004
|
+
* Read file content.
|
|
1005
|
+
*
|
|
1006
|
+
* Text files are paginated by line offset/limit.
|
|
1007
|
+
* Binary files return full Uint8Array content (offset/limit ignored).
|
|
840
1008
|
*
|
|
841
1009
|
* @param filePath - Absolute file path
|
|
842
1010
|
* @param offset - Line offset to start reading from (0-indexed)
|
|
843
1011
|
* @param limit - Maximum number of lines to read
|
|
844
|
-
* @returns
|
|
1012
|
+
* @returns ReadResult with content on success or error on failure
|
|
845
1013
|
*/
|
|
846
|
-
read(filePath: string, offset?: number, limit?: number):
|
|
1014
|
+
read(filePath: string, offset?: number, limit?: number): Promise<ReadResult>;
|
|
847
1015
|
/**
|
|
848
1016
|
* Read file content as raw FileData.
|
|
849
1017
|
*
|
|
850
1018
|
* @param filePath - Absolute file path
|
|
851
|
-
* @returns
|
|
1019
|
+
* @returns ReadRawResult with raw file data on success or error on failure
|
|
852
1020
|
*/
|
|
853
|
-
readRaw(filePath: string):
|
|
1021
|
+
readRaw(filePath: string): Promise<ReadRawResult>;
|
|
854
1022
|
/**
|
|
855
1023
|
* Create a new file with content.
|
|
856
|
-
* Returns WriteResult
|
|
1024
|
+
* Returns WriteResult. External storage sets filesUpdate=null.
|
|
857
1025
|
*/
|
|
858
|
-
write(filePath: string, content: string): WriteResult
|
|
1026
|
+
write(filePath: string, content: string): Promise<WriteResult>;
|
|
859
1027
|
/**
|
|
860
1028
|
* Edit a file by replacing string occurrences.
|
|
861
|
-
* Returns EditResult
|
|
1029
|
+
* Returns EditResult. External storage sets filesUpdate=null.
|
|
862
1030
|
*/
|
|
863
|
-
edit(filePath: string, oldString: string, newString: string, replaceAll?: boolean): EditResult
|
|
1031
|
+
edit(filePath: string, oldString: string, newString: string, replaceAll?: boolean): Promise<EditResult>;
|
|
864
1032
|
/**
|
|
865
|
-
*
|
|
1033
|
+
* Search file contents for a literal text pattern.
|
|
1034
|
+
* Binary files are skipped.
|
|
866
1035
|
*/
|
|
867
|
-
|
|
1036
|
+
grep(pattern: string, path?: string, glob?: string | null): Promise<GrepResult>;
|
|
868
1037
|
/**
|
|
869
1038
|
* Structured glob matching returning FileInfo objects.
|
|
870
1039
|
*/
|
|
871
|
-
|
|
1040
|
+
glob(pattern: string, path?: string): Promise<GlobResult>;
|
|
872
1041
|
/**
|
|
873
1042
|
* Upload multiple files.
|
|
874
1043
|
*
|
|
875
|
-
* Note: Since LangGraph state must be updated via Command objects,
|
|
876
|
-
* the caller must apply filesUpdate via Command after calling this method.
|
|
877
|
-
*
|
|
878
1044
|
* @param files - List of [path, content] tuples to upload
|
|
879
1045
|
* @returns List of FileUploadResponse objects, one per input file
|
|
880
1046
|
*/
|
|
881
|
-
uploadFiles(files: Array<[string, Uint8Array]>): FileUploadResponse[]
|
|
882
|
-
filesUpdate?: Record<string, FileData>;
|
|
883
|
-
};
|
|
1047
|
+
uploadFiles(files: Array<[string, Uint8Array]>): Promise<FileUploadResponse[]>;
|
|
884
1048
|
/**
|
|
885
1049
|
* Download multiple files.
|
|
886
1050
|
*
|
|
887
1051
|
* @param paths - List of file paths to download
|
|
888
1052
|
* @returns List of FileDownloadResponse objects, one per input path
|
|
889
1053
|
*/
|
|
890
|
-
downloadFiles(paths: string[]): FileDownloadResponse[]
|
|
1054
|
+
downloadFiles(paths: string[]): Promise<FileDownloadResponse[]>;
|
|
891
1055
|
}
|
|
892
1056
|
//#endregion
|
|
893
|
-
//#region src/
|
|
1057
|
+
//#region src/backends/filesystem.d.ts
|
|
894
1058
|
/**
|
|
895
|
-
*
|
|
1059
|
+
* Backend that reads and writes files directly from the filesystem.
|
|
1060
|
+
*
|
|
1061
|
+
* Files are accessed using their actual filesystem paths. Relative paths are
|
|
1062
|
+
* resolved relative to the current working directory. Content is read/written
|
|
1063
|
+
* as plain text, and metadata (timestamps) are derived from filesystem stats.
|
|
896
1064
|
*/
|
|
897
|
-
|
|
1065
|
+
declare class FilesystemBackend implements BackendProtocolV2 {
|
|
1066
|
+
protected cwd: string;
|
|
1067
|
+
protected virtualMode: boolean;
|
|
1068
|
+
private maxFileSizeBytes;
|
|
1069
|
+
constructor(options?: {
|
|
1070
|
+
rootDir?: string;
|
|
1071
|
+
virtualMode?: boolean;
|
|
1072
|
+
maxFileSizeMb?: number;
|
|
1073
|
+
});
|
|
898
1074
|
/**
|
|
899
|
-
*
|
|
900
|
-
*
|
|
1075
|
+
* Resolve a file path with security checks.
|
|
1076
|
+
*
|
|
1077
|
+
* When virtualMode=true, treat incoming paths as virtual absolute paths under
|
|
1078
|
+
* this.cwd, disallow traversal (.., ~) and ensure resolved path stays within root.
|
|
1079
|
+
* When virtualMode=false, preserve legacy behavior: absolute paths are allowed
|
|
1080
|
+
* as-is; relative paths resolve under cwd.
|
|
1081
|
+
*
|
|
1082
|
+
* @param key - File path (absolute, relative, or virtual when virtualMode=true)
|
|
1083
|
+
* @returns Resolved absolute path string
|
|
1084
|
+
* @throws Error if path traversal detected or path outside root
|
|
901
1085
|
*/
|
|
902
|
-
|
|
903
|
-
state: unknown;
|
|
904
|
-
store?: BaseStore;
|
|
905
|
-
}) => StateBackend);
|
|
1086
|
+
private resolvePath;
|
|
906
1087
|
/**
|
|
907
|
-
* List
|
|
908
|
-
*
|
|
909
|
-
*
|
|
1088
|
+
* List files and directories in the specified directory (non-recursive).
|
|
1089
|
+
*
|
|
1090
|
+
* @param dirPath - Absolute directory path to list files from
|
|
1091
|
+
* @returns List of FileInfo objects for files and directories directly in the directory.
|
|
1092
|
+
* Directories have a trailing / in their path and is_dir=true.
|
|
910
1093
|
*/
|
|
911
|
-
|
|
1094
|
+
ls(dirPath: string): Promise<LsResult>;
|
|
912
1095
|
/**
|
|
913
|
-
*
|
|
914
|
-
*
|
|
915
|
-
*
|
|
916
|
-
* @
|
|
1096
|
+
* Read file content with line numbers.
|
|
1097
|
+
*
|
|
1098
|
+
* @param filePath - Absolute or relative file path
|
|
1099
|
+
* @param offset - Line offset to start reading from (0-indexed)
|
|
1100
|
+
* @param limit - Maximum number of lines to read
|
|
1101
|
+
* @returns Formatted file content with line numbers, or error message
|
|
917
1102
|
*/
|
|
918
|
-
|
|
919
|
-
}
|
|
920
|
-
/**
|
|
921
|
-
* Create middleware for loading agent memory from AGENTS.md files.
|
|
922
|
-
*
|
|
923
|
-
* Loads memory content from configured sources and injects into the system prompt.
|
|
924
|
-
* Supports multiple sources that are combined together.
|
|
925
|
-
*
|
|
926
|
-
* @param options - Configuration options
|
|
927
|
-
* @returns AgentMiddleware for memory loading and injection
|
|
928
|
-
*
|
|
929
|
-
* @example
|
|
930
|
-
* ```typescript
|
|
931
|
-
* const middleware = createMemoryMiddleware({
|
|
932
|
-
* backend: new FilesystemBackend({ rootDir: "/" }),
|
|
933
|
-
* sources: [
|
|
934
|
-
* "~/.deepagents/AGENTS.md",
|
|
935
|
-
* "./.deepagents/AGENTS.md",
|
|
936
|
-
* ],
|
|
937
|
-
* });
|
|
938
|
-
* ```
|
|
939
|
-
*/
|
|
940
|
-
declare function createMemoryMiddleware(options: MemoryMiddlewareOptions): AgentMiddleware<StateSchema<{
|
|
1103
|
+
read(filePath: string, offset?: number, limit?: number): Promise<ReadResult>;
|
|
941
1104
|
/**
|
|
942
|
-
*
|
|
943
|
-
*
|
|
1105
|
+
* Read file content as raw FileData.
|
|
1106
|
+
*
|
|
1107
|
+
* @param filePath - Absolute file path
|
|
1108
|
+
* @returns ReadRawResult with raw file data on success or error on failure
|
|
944
1109
|
*/
|
|
945
|
-
|
|
946
|
-
files: _langgraph.ReducedValue<FilesRecord | undefined, FilesRecordUpdate | undefined>;
|
|
947
|
-
}>, undefined, unknown, readonly (_langchain_core_tools0.ClientTool | _langchain_core_tools0.ServerTool)[]>;
|
|
948
|
-
//#endregion
|
|
949
|
-
//#region src/middleware/skills.d.ts
|
|
950
|
-
declare const MAX_SKILL_FILE_SIZE: number;
|
|
951
|
-
declare const MAX_SKILL_NAME_LENGTH = 64;
|
|
952
|
-
declare const MAX_SKILL_DESCRIPTION_LENGTH = 1024;
|
|
953
|
-
/**
|
|
954
|
-
* Metadata for a skill per Agent Skills specification.
|
|
955
|
-
*/
|
|
956
|
-
interface SkillMetadata$1 {
|
|
1110
|
+
readRaw(filePath: string): Promise<ReadRawResult>;
|
|
957
1111
|
/**
|
|
958
|
-
*
|
|
959
|
-
*
|
|
960
|
-
* Constraints per Agent Skills specification:
|
|
961
|
-
*
|
|
962
|
-
* - 1-64 characters
|
|
963
|
-
* - Unicode lowercase alphanumeric and hyphens only (`a-z` and `-`).
|
|
964
|
-
* - Must not start or end with `-`
|
|
965
|
-
* - Must not contain consecutive `--`
|
|
966
|
-
* - Must match the parent directory name containing the `SKILL.md` file
|
|
1112
|
+
* Create a new file with content.
|
|
1113
|
+
* Returns WriteResult. External storage sets filesUpdate=null.
|
|
967
1114
|
*/
|
|
968
|
-
|
|
1115
|
+
write(filePath: string, content: string): Promise<WriteResult>;
|
|
969
1116
|
/**
|
|
970
|
-
*
|
|
971
|
-
*
|
|
972
|
-
* Constraints per Agent Skills specification:
|
|
973
|
-
*
|
|
974
|
-
* - 1-1024 characters
|
|
975
|
-
* - Should describe both what the skill does and when to use it
|
|
976
|
-
* - Should include specific keywords that help agents identify relevant tasks
|
|
1117
|
+
* Edit a file by replacing string occurrences.
|
|
1118
|
+
* Returns EditResult. External storage sets filesUpdate=null.
|
|
977
1119
|
*/
|
|
978
|
-
|
|
979
|
-
/** Path to the SKILL.md file in the backend */
|
|
980
|
-
path: string;
|
|
981
|
-
/** License name or reference to bundled license file. */
|
|
982
|
-
license?: string | null;
|
|
1120
|
+
edit(filePath: string, oldString: string, newString: string, replaceAll?: boolean): Promise<EditResult>;
|
|
983
1121
|
/**
|
|
984
|
-
*
|
|
1122
|
+
* Search for a literal text pattern in files.
|
|
985
1123
|
*
|
|
986
|
-
*
|
|
1124
|
+
* Uses ripgrep if available, falling back to substring search.
|
|
987
1125
|
*
|
|
988
|
-
*
|
|
989
|
-
* -
|
|
990
|
-
* -
|
|
1126
|
+
* @param pattern - Literal string to search for (NOT regex).
|
|
1127
|
+
* @param dirPath - Directory or file path to search in. Defaults to current directory.
|
|
1128
|
+
* @param glob - Optional glob pattern to filter which files to search.
|
|
1129
|
+
* @returns List of GrepMatch dicts containing path, line number, and matched text.
|
|
991
1130
|
*/
|
|
992
|
-
|
|
1131
|
+
grep(pattern: string, dirPath?: string, glob?: string | null): Promise<GrepResult>;
|
|
993
1132
|
/**
|
|
994
|
-
*
|
|
995
|
-
*
|
|
996
|
-
* Clients can use this to store additional properties not defined by the spec.
|
|
1133
|
+
* Search using ripgrep with fixed-string (literal) mode.
|
|
997
1134
|
*
|
|
998
|
-
*
|
|
1135
|
+
* @param pattern - Literal string to search for (unescaped).
|
|
1136
|
+
* @param baseFull - Resolved base path to search in.
|
|
1137
|
+
* @param includeGlob - Optional glob pattern to filter files.
|
|
1138
|
+
* @returns Dict mapping file paths to list of (line_number, line_text) tuples.
|
|
1139
|
+
* Returns null if ripgrep is unavailable or times out.
|
|
999
1140
|
*/
|
|
1000
|
-
|
|
1141
|
+
private ripgrepSearch;
|
|
1001
1142
|
/**
|
|
1002
|
-
*
|
|
1003
|
-
*
|
|
1004
|
-
* Warning: this is experimental.
|
|
1143
|
+
* Fallback search using literal substring matching when ripgrep is unavailable.
|
|
1005
1144
|
*
|
|
1006
|
-
*
|
|
1145
|
+
* Recursively searches files, respecting maxFileSizeBytes limit.
|
|
1007
1146
|
*
|
|
1008
|
-
*
|
|
1147
|
+
* @param pattern - Literal string to search for.
|
|
1148
|
+
* @param baseFull - Resolved base path to search in.
|
|
1149
|
+
* @param includeGlob - Optional glob pattern to filter files by name.
|
|
1150
|
+
* @returns Dict mapping file paths to list of (line_number, line_text) tuples.
|
|
1009
1151
|
*/
|
|
1010
|
-
|
|
1011
|
-
}
|
|
1012
|
-
/**
|
|
1013
|
-
* Options for the skills middleware.
|
|
1014
|
-
*/
|
|
1015
|
-
interface SkillsMiddlewareOptions {
|
|
1152
|
+
private literalSearch;
|
|
1016
1153
|
/**
|
|
1017
|
-
*
|
|
1018
|
-
* Use a factory for StateBackend since it requires runtime state.
|
|
1154
|
+
* Structured glob matching returning FileInfo objects.
|
|
1019
1155
|
*/
|
|
1020
|
-
|
|
1021
|
-
state: unknown;
|
|
1022
|
-
store?: BaseStore;
|
|
1023
|
-
}) => StateBackend);
|
|
1156
|
+
glob(pattern: string, searchPath?: string): Promise<GlobResult>;
|
|
1024
1157
|
/**
|
|
1025
|
-
*
|
|
1026
|
-
*
|
|
1027
|
-
*
|
|
1158
|
+
* Upload multiple files to the filesystem.
|
|
1159
|
+
*
|
|
1160
|
+
* @param files - List of [path, content] tuples to upload
|
|
1161
|
+
* @returns List of FileUploadResponse objects, one per input file
|
|
1028
1162
|
*/
|
|
1029
|
-
|
|
1163
|
+
uploadFiles(files: Array<[string, Uint8Array]>): Promise<FileUploadResponse[]>;
|
|
1164
|
+
/**
|
|
1165
|
+
* Download multiple files from the filesystem.
|
|
1166
|
+
*
|
|
1167
|
+
* @param paths - List of file paths to download
|
|
1168
|
+
* @returns List of FileDownloadResponse objects, one per input path
|
|
1169
|
+
*/
|
|
1170
|
+
downloadFiles(paths: string[]): Promise<FileDownloadResponse[]>;
|
|
1030
1171
|
}
|
|
1172
|
+
//#endregion
|
|
1173
|
+
//#region src/backends/composite.d.ts
|
|
1031
1174
|
/**
|
|
1032
|
-
*
|
|
1033
|
-
*
|
|
1034
|
-
* This middleware loads skills from configurable backend sources and injects
|
|
1035
|
-
* skill metadata into the system prompt. It implements the progressive disclosure
|
|
1036
|
-
* pattern: skill names and descriptions are shown in the prompt, but the agent
|
|
1037
|
-
* reads full SKILL.md content only when needed.
|
|
1175
|
+
* Backend that routes file operations to different backends based on path prefix.
|
|
1038
1176
|
*
|
|
1039
|
-
*
|
|
1040
|
-
*
|
|
1177
|
+
* This enables hybrid storage strategies like:
|
|
1178
|
+
* - `/memories/` → StoreBackend (persistent, cross-thread)
|
|
1179
|
+
* - Everything else → StateBackend (ephemeral, per-thread)
|
|
1041
1180
|
*
|
|
1042
|
-
*
|
|
1043
|
-
* ```typescript
|
|
1044
|
-
* const middleware = createSkillsMiddleware({
|
|
1045
|
-
* backend: new FilesystemBackend({ rootDir: "/" }),
|
|
1046
|
-
* sources: ["/skills/user/", "/skills/project/"],
|
|
1047
|
-
* });
|
|
1048
|
-
* ```
|
|
1049
|
-
*/
|
|
1050
|
-
declare function createSkillsMiddleware(options: SkillsMiddlewareOptions): AgentMiddleware<StateSchema<{
|
|
1051
|
-
skillsMetadata: ReducedValue<{
|
|
1052
|
-
name: string;
|
|
1053
|
-
description: string;
|
|
1054
|
-
path: string;
|
|
1055
|
-
license?: string | null | undefined;
|
|
1056
|
-
compatibility?: string | null | undefined;
|
|
1057
|
-
metadata?: Record<string, string> | undefined;
|
|
1058
|
-
allowedTools?: string[] | undefined;
|
|
1059
|
-
}[] | undefined, {
|
|
1060
|
-
name: string;
|
|
1061
|
-
description: string;
|
|
1062
|
-
path: string;
|
|
1063
|
-
license?: string | null | undefined;
|
|
1064
|
-
compatibility?: string | null | undefined;
|
|
1065
|
-
metadata?: Record<string, string> | undefined;
|
|
1066
|
-
allowedTools?: string[] | undefined;
|
|
1067
|
-
}[] | undefined>;
|
|
1068
|
-
files: ReducedValue<FilesRecord | undefined, FilesRecordUpdate | undefined>;
|
|
1069
|
-
}>, undefined, unknown, readonly (_langchain_core_tools0.ClientTool | _langchain_core_tools0.ServerTool)[]>;
|
|
1070
|
-
//#endregion
|
|
1071
|
-
//#region src/middleware/summarization.d.ts
|
|
1072
|
-
/**
|
|
1073
|
-
* Context size specification for summarization triggers and retention policies.
|
|
1074
|
-
*/
|
|
1075
|
-
interface ContextSize {
|
|
1076
|
-
/** Type of context measurement */
|
|
1077
|
-
type: "messages" | "tokens" | "fraction";
|
|
1078
|
-
/** Threshold value */
|
|
1079
|
-
value: number;
|
|
1080
|
-
}
|
|
1081
|
-
/**
|
|
1082
|
-
* Settings for truncating large tool arguments in old messages.
|
|
1181
|
+
* The CompositeBackend handles path prefix stripping/re-adding transparently.
|
|
1083
1182
|
*/
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1183
|
+
declare class CompositeBackend implements BackendProtocolV2 {
|
|
1184
|
+
private default;
|
|
1185
|
+
private routes;
|
|
1186
|
+
private sortedRoutes;
|
|
1187
|
+
constructor(defaultBackend: AnyBackendProtocol, routes: Record<string, AnyBackendProtocol>);
|
|
1188
|
+
/** Delegates to default backend's id if it is a sandbox, otherwise empty string. */
|
|
1189
|
+
get id(): string;
|
|
1090
1190
|
/**
|
|
1091
|
-
*
|
|
1092
|
-
*
|
|
1191
|
+
* Determine which backend handles this key and strip prefix.
|
|
1192
|
+
*
|
|
1193
|
+
* @param key - Original file path
|
|
1194
|
+
* @returns Tuple of [backend, stripped_key] where stripped_key has the route
|
|
1195
|
+
* prefix removed (but keeps leading slash).
|
|
1093
1196
|
*/
|
|
1094
|
-
|
|
1197
|
+
private getBackendAndKey;
|
|
1095
1198
|
/**
|
|
1096
|
-
*
|
|
1097
|
-
*
|
|
1199
|
+
* List files and directories in the specified directory (non-recursive).
|
|
1200
|
+
*
|
|
1201
|
+
* @param path - Absolute path to directory
|
|
1202
|
+
* @returns LsResult with list of FileInfo objects (with route prefixes added) on success or error on failure.
|
|
1203
|
+
* Directories have a trailing / in their path and is_dir=true.
|
|
1098
1204
|
*/
|
|
1099
|
-
|
|
1205
|
+
ls(path: string): Promise<LsResult>;
|
|
1100
1206
|
/**
|
|
1101
|
-
*
|
|
1102
|
-
*
|
|
1207
|
+
* Read file content, routing to appropriate backend.
|
|
1208
|
+
*
|
|
1209
|
+
* @param filePath - Absolute file path
|
|
1210
|
+
* @param offset - Line offset to start reading from (0-indexed)
|
|
1211
|
+
* @param limit - Maximum number of lines to read
|
|
1212
|
+
* @returns Formatted file content with line numbers, or error message
|
|
1103
1213
|
*/
|
|
1104
|
-
|
|
1105
|
-
}
|
|
1106
|
-
/**
|
|
1107
|
-
* Options for the summarization middleware.
|
|
1108
|
-
*/
|
|
1109
|
-
interface SummarizationMiddlewareOptions {
|
|
1214
|
+
read(filePath: string, offset?: number, limit?: number): Promise<ReadResult>;
|
|
1110
1215
|
/**
|
|
1111
|
-
*
|
|
1112
|
-
*
|
|
1216
|
+
* Read file content as raw FileData.
|
|
1217
|
+
*
|
|
1218
|
+
* @param filePath - Absolute file path
|
|
1219
|
+
* @returns ReadRawResult with raw file data on success or error on failure
|
|
1113
1220
|
*/
|
|
1114
|
-
|
|
1221
|
+
readRaw(filePath: string): Promise<ReadRawResult>;
|
|
1115
1222
|
/**
|
|
1116
|
-
*
|
|
1223
|
+
* Structured search results or error string for invalid input.
|
|
1117
1224
|
*/
|
|
1118
|
-
|
|
1119
|
-
state: unknown;
|
|
1120
|
-
store?: BaseStore;
|
|
1121
|
-
}) => StateBackend);
|
|
1225
|
+
grep(pattern: string, path?: string, glob?: string | null): Promise<GrepResult>;
|
|
1122
1226
|
/**
|
|
1123
|
-
*
|
|
1124
|
-
* Can be a single ContextSize or an array for multiple triggers.
|
|
1227
|
+
* Structured glob matching returning FileInfo objects.
|
|
1125
1228
|
*/
|
|
1126
|
-
|
|
1229
|
+
glob(pattern: string, path?: string): Promise<GlobResult>;
|
|
1127
1230
|
/**
|
|
1128
|
-
*
|
|
1129
|
-
*
|
|
1231
|
+
* Create a new file, routing to appropriate backend.
|
|
1232
|
+
*
|
|
1233
|
+
* @param filePath - Absolute file path
|
|
1234
|
+
* @param content - File content as string
|
|
1235
|
+
* @returns WriteResult with path or error
|
|
1130
1236
|
*/
|
|
1131
|
-
|
|
1237
|
+
write(filePath: string, content: string): Promise<WriteResult>;
|
|
1132
1238
|
/**
|
|
1133
|
-
*
|
|
1239
|
+
* Edit a file, routing to appropriate backend.
|
|
1240
|
+
*
|
|
1241
|
+
* @param filePath - Absolute file path
|
|
1242
|
+
* @param oldString - String to find and replace
|
|
1243
|
+
* @param newString - Replacement string
|
|
1244
|
+
* @param replaceAll - If true, replace all occurrences
|
|
1245
|
+
* @returns EditResult with path, occurrences, or error
|
|
1134
1246
|
*/
|
|
1135
|
-
|
|
1247
|
+
edit(filePath: string, oldString: string, newString: string, replaceAll?: boolean): Promise<EditResult>;
|
|
1136
1248
|
/**
|
|
1137
|
-
*
|
|
1138
|
-
*
|
|
1249
|
+
* Execute a command via the default backend.
|
|
1250
|
+
* Execution is not path-specific, so it always delegates to the default backend.
|
|
1251
|
+
*
|
|
1252
|
+
* @param command - Full shell command string to execute
|
|
1253
|
+
* @returns ExecuteResponse with combined output, exit code, and truncation flag
|
|
1254
|
+
* @throws Error if the default backend doesn't support command execution
|
|
1139
1255
|
*/
|
|
1140
|
-
|
|
1256
|
+
execute(command: string): Promise<ExecuteResponse>;
|
|
1141
1257
|
/**
|
|
1142
|
-
*
|
|
1143
|
-
*
|
|
1258
|
+
* Upload multiple files, batching by backend for efficiency.
|
|
1259
|
+
*
|
|
1260
|
+
* @param files - List of [path, content] tuples to upload
|
|
1261
|
+
* @returns List of FileUploadResponse objects, one per input file
|
|
1144
1262
|
*/
|
|
1145
|
-
|
|
1263
|
+
uploadFiles(files: Array<[string, Uint8Array]>): Promise<FileUploadResponse[]>;
|
|
1146
1264
|
/**
|
|
1147
|
-
*
|
|
1148
|
-
*
|
|
1265
|
+
* Download multiple files, batching by backend for efficiency.
|
|
1266
|
+
*
|
|
1267
|
+
* @param paths - List of file paths to download
|
|
1268
|
+
* @returns List of FileDownloadResponse objects, one per input path
|
|
1149
1269
|
*/
|
|
1150
|
-
|
|
1270
|
+
downloadFiles(paths: string[]): Promise<FileDownloadResponse[]>;
|
|
1151
1271
|
}
|
|
1152
|
-
/**
|
|
1153
|
-
* Compute summarization defaults based on model profile.
|
|
1154
|
-
* Mirrors Python's `_compute_summarization_defaults`.
|
|
1155
|
-
*
|
|
1156
|
-
* If the model has a profile with `maxInputTokens`, uses fraction-based
|
|
1157
|
-
* settings. Otherwise, uses fixed token/message counts.
|
|
1158
|
-
*
|
|
1159
|
-
* @param resolvedModel - The resolved chat model instance.
|
|
1160
|
-
*/
|
|
1161
|
-
declare function computeSummarizationDefaults(resolvedModel: BaseChatModel): {
|
|
1162
|
-
trigger: ContextSize;
|
|
1163
|
-
keep: ContextSize;
|
|
1164
|
-
truncateArgsSettings: TruncateArgsSettings;
|
|
1165
|
-
};
|
|
1166
|
-
/**
|
|
1167
|
-
* Create summarization middleware with backend support for conversation history offloading.
|
|
1168
|
-
*
|
|
1169
|
-
* This middleware:
|
|
1170
|
-
* 1. Monitors conversation length against configured thresholds
|
|
1171
|
-
* 2. When triggered, offloads old messages to backend storage
|
|
1172
|
-
* 3. Generates a summary of offloaded messages
|
|
1173
|
-
* 4. Replaces old messages with the summary, preserving recent context
|
|
1174
|
-
*
|
|
1175
|
-
* @param options - Configuration options
|
|
1176
|
-
* @returns AgentMiddleware for summarization and history offloading
|
|
1177
|
-
*/
|
|
1178
|
-
declare function createSummarizationMiddleware(options: SummarizationMiddlewareOptions): AgentMiddleware<z$1.ZodObject<{
|
|
1179
|
-
_summarizationSessionId: z$1.ZodOptional<z$1.ZodString>;
|
|
1180
|
-
_summarizationEvent: z$1.ZodOptional<z$1.ZodObject<{
|
|
1181
|
-
cutoffIndex: z$1.ZodNumber;
|
|
1182
|
-
summaryMessage: z$1.ZodCustom<HumanMessage<_messages.MessageStructure<_messages.MessageToolSet>>, HumanMessage<_messages.MessageStructure<_messages.MessageToolSet>>>;
|
|
1183
|
-
filePath: z$1.ZodNullable<z$1.ZodString>;
|
|
1184
|
-
}, z$1.core.$strip>>;
|
|
1185
|
-
}, z$1.core.$strip>, undefined, unknown, readonly (ClientTool | ServerTool)[]>;
|
|
1186
1272
|
//#endregion
|
|
1187
|
-
//#region src/backends/
|
|
1273
|
+
//#region src/backends/local-shell.d.ts
|
|
1188
1274
|
/**
|
|
1189
|
-
* Options for
|
|
1275
|
+
* Options for creating a LocalShellBackend instance.
|
|
1190
1276
|
*/
|
|
1191
|
-
interface
|
|
1277
|
+
interface LocalShellBackendOptions {
|
|
1192
1278
|
/**
|
|
1193
|
-
*
|
|
1194
|
-
*
|
|
1195
|
-
* Determines where files are stored in the LangGraph store, enabling
|
|
1196
|
-
* user-scoped, org-scoped, or any custom isolation pattern.
|
|
1197
|
-
*
|
|
1198
|
-
* If not provided, falls back to legacy behavior using assistantId from {@link BackendRuntime}.
|
|
1199
|
-
*
|
|
1200
|
-
* @example
|
|
1201
|
-
* ```typescript
|
|
1202
|
-
* // User-scoped storage
|
|
1203
|
-
* new StoreBackend(runtime, {
|
|
1204
|
-
* namespace: ["memories", orgId, userId, "filesystem"],
|
|
1205
|
-
* });
|
|
1206
|
-
*
|
|
1207
|
-
* // Org-scoped storage
|
|
1208
|
-
* new StoreBackend(runtime, {
|
|
1209
|
-
* namespace: ["memories", orgId, "filesystem"],
|
|
1210
|
-
* });
|
|
1211
|
-
* ```
|
|
1279
|
+
* Working directory for both filesystem operations and shell commands.
|
|
1280
|
+
* @defaultValue `process.cwd()`
|
|
1212
1281
|
*/
|
|
1213
|
-
|
|
1214
|
-
}
|
|
1215
|
-
/**
|
|
1216
|
-
* Backend that stores files in LangGraph's BaseStore (persistent).
|
|
1217
|
-
*
|
|
1218
|
-
* Uses LangGraph's Store for persistent, cross-conversation storage.
|
|
1219
|
-
* Files are organized via namespaces and persist across all threads.
|
|
1220
|
-
*
|
|
1221
|
-
* The namespace can be customized via a factory function for flexible
|
|
1222
|
-
* isolation patterns (user-scoped, org-scoped, etc.), or falls back
|
|
1223
|
-
* to legacy assistant_id-based isolation.
|
|
1224
|
-
*/
|
|
1225
|
-
declare class StoreBackend implements BackendProtocol {
|
|
1226
|
-
private stateAndStore;
|
|
1227
|
-
private _namespace;
|
|
1228
|
-
constructor(stateAndStore: StateAndStore, options?: StoreBackendOptions);
|
|
1282
|
+
rootDir?: string;
|
|
1229
1283
|
/**
|
|
1230
|
-
*
|
|
1231
|
-
*
|
|
1232
|
-
*
|
|
1233
|
-
* @
|
|
1284
|
+
* Enable virtual path mode for filesystem operations.
|
|
1285
|
+
* When true, treats rootDir as a virtual root filesystem.
|
|
1286
|
+
* Does NOT restrict shell commands.
|
|
1287
|
+
* @defaultValue `false`
|
|
1234
1288
|
*/
|
|
1235
|
-
|
|
1289
|
+
virtualMode?: boolean;
|
|
1236
1290
|
/**
|
|
1237
|
-
*
|
|
1238
|
-
*
|
|
1239
|
-
*
|
|
1240
|
-
*
|
|
1241
|
-
* Otherwise, falls back to legacy behavior:
|
|
1242
|
-
* - If assistantId is set: [assistantId, "filesystem"]
|
|
1243
|
-
* - Otherwise: ["filesystem"]
|
|
1291
|
+
* Maximum time in seconds to wait for shell command execution.
|
|
1292
|
+
* Commands exceeding this timeout will be terminated.
|
|
1293
|
+
* @defaultValue `120`
|
|
1244
1294
|
*/
|
|
1245
|
-
|
|
1295
|
+
timeout?: number;
|
|
1246
1296
|
/**
|
|
1247
|
-
*
|
|
1248
|
-
*
|
|
1249
|
-
* @
|
|
1250
|
-
* @returns FileData object
|
|
1251
|
-
* @throws Error if required fields are missing or have incorrect types
|
|
1297
|
+
* Maximum number of bytes to capture from command output.
|
|
1298
|
+
* Output exceeding this limit will be truncated.
|
|
1299
|
+
* @defaultValue `100_000`
|
|
1252
1300
|
*/
|
|
1253
|
-
|
|
1301
|
+
maxOutputBytes?: number;
|
|
1254
1302
|
/**
|
|
1255
|
-
*
|
|
1256
|
-
*
|
|
1257
|
-
* @
|
|
1258
|
-
* @returns Object with content, created_at, and modified_at fields
|
|
1303
|
+
* Environment variables for shell commands. If undefined, starts with an empty
|
|
1304
|
+
* environment (unless inheritEnv is true).
|
|
1305
|
+
* @defaultValue `undefined`
|
|
1259
1306
|
*/
|
|
1260
|
-
|
|
1307
|
+
env?: Record<string, string>;
|
|
1261
1308
|
/**
|
|
1262
|
-
*
|
|
1263
|
-
*
|
|
1264
|
-
*
|
|
1265
|
-
* @
|
|
1266
|
-
* @param options - Optional query, filter, and page_size
|
|
1267
|
-
* @returns List of all items matching the search criteria
|
|
1309
|
+
* Whether to inherit the parent process's environment variables.
|
|
1310
|
+
* When false, only variables in env dict are available.
|
|
1311
|
+
* When true, inherits all process.env variables and applies env overrides.
|
|
1312
|
+
* @defaultValue `false`
|
|
1268
1313
|
*/
|
|
1269
|
-
|
|
1314
|
+
inheritEnv?: boolean;
|
|
1270
1315
|
/**
|
|
1271
|
-
*
|
|
1272
|
-
*
|
|
1273
|
-
*
|
|
1274
|
-
* @
|
|
1275
|
-
* Directories have a trailing / in their path and is_dir=true.
|
|
1316
|
+
* Files to create on disk during `create()`.
|
|
1317
|
+
* Keys are file paths (resolved via the backend's path handling),
|
|
1318
|
+
* values are string content.
|
|
1319
|
+
* @defaultValue `undefined`
|
|
1276
1320
|
*/
|
|
1277
|
-
|
|
1321
|
+
initialFiles?: Record<string, string>;
|
|
1322
|
+
}
|
|
1323
|
+
/**
|
|
1324
|
+
* Filesystem backend with unrestricted local shell command execution.
|
|
1325
|
+
*
|
|
1326
|
+
* This backend extends FilesystemBackend to add shell command execution
|
|
1327
|
+
* capabilities. Commands are executed directly on the host system without any
|
|
1328
|
+
* sandboxing, process isolation, or security restrictions.
|
|
1329
|
+
*
|
|
1330
|
+
* **Security Warning:**
|
|
1331
|
+
* This backend grants agents BOTH direct filesystem access AND unrestricted
|
|
1332
|
+
* shell execution on your local machine. Use with extreme caution and only in
|
|
1333
|
+
* appropriate environments.
|
|
1334
|
+
*
|
|
1335
|
+
* **Appropriate use cases:**
|
|
1336
|
+
* - Local development CLIs (coding assistants, development tools)
|
|
1337
|
+
* - Personal development environments where you trust the agent's code
|
|
1338
|
+
* - CI/CD pipelines with proper secret management
|
|
1339
|
+
*
|
|
1340
|
+
* **Inappropriate use cases:**
|
|
1341
|
+
* - Production environments (e.g., web servers, APIs, multi-tenant systems)
|
|
1342
|
+
* - Processing untrusted user input or executing untrusted code
|
|
1343
|
+
*
|
|
1344
|
+
* Use StateBackend, StoreBackend, or extend BaseSandbox for production.
|
|
1345
|
+
*
|
|
1346
|
+
* @example
|
|
1347
|
+
* ```typescript
|
|
1348
|
+
* import { LocalShellBackend } from "@langchain/deepagents";
|
|
1349
|
+
*
|
|
1350
|
+
* // Create backend with explicit environment
|
|
1351
|
+
* const backend = new LocalShellBackend({
|
|
1352
|
+
* rootDir: "/home/user/project",
|
|
1353
|
+
* env: { PATH: "/usr/bin:/bin" },
|
|
1354
|
+
* });
|
|
1355
|
+
*
|
|
1356
|
+
* // Execute shell commands (runs directly on host)
|
|
1357
|
+
* const result = await backend.execute("ls -la");
|
|
1358
|
+
* console.log(result.output);
|
|
1359
|
+
* console.log(result.exitCode);
|
|
1360
|
+
*
|
|
1361
|
+
* // Use filesystem operations (inherited from FilesystemBackend)
|
|
1362
|
+
* const content = await backend.read("/README.md");
|
|
1363
|
+
* await backend.write("/output.txt", "Hello world");
|
|
1364
|
+
*
|
|
1365
|
+
* // Inherit all environment variables
|
|
1366
|
+
* const backend2 = new LocalShellBackend({
|
|
1367
|
+
* rootDir: "/home/user/project",
|
|
1368
|
+
* inheritEnv: true,
|
|
1369
|
+
* });
|
|
1370
|
+
* ```
|
|
1371
|
+
*/
|
|
1372
|
+
declare class LocalShellBackend extends FilesystemBackend implements SandboxBackendProtocolV2 {
|
|
1373
|
+
#private;
|
|
1374
|
+
constructor(options?: LocalShellBackendOptions);
|
|
1375
|
+
/** Unique identifier for this backend instance (format: "local-{random_hex}"). */
|
|
1376
|
+
get id(): string;
|
|
1377
|
+
/** Whether the backend has been initialized and is ready to use. */
|
|
1378
|
+
get isInitialized(): boolean;
|
|
1379
|
+
/** Alias for `isInitialized`, matching the standard sandbox interface. */
|
|
1380
|
+
get isRunning(): boolean;
|
|
1278
1381
|
/**
|
|
1279
|
-
*
|
|
1382
|
+
* Initialize the backend by ensuring the rootDir exists.
|
|
1280
1383
|
*
|
|
1281
|
-
*
|
|
1282
|
-
*
|
|
1283
|
-
*
|
|
1284
|
-
*
|
|
1384
|
+
* Creates the rootDir (and any parent directories) if it does not already
|
|
1385
|
+
* exist. Safe to call on an existing directory. Must be called before
|
|
1386
|
+
* `execute()`, or use the static `LocalShellBackend.create()` factory.
|
|
1387
|
+
*
|
|
1388
|
+
* @throws {SandboxError} If already initialized (`ALREADY_INITIALIZED`)
|
|
1285
1389
|
*/
|
|
1286
|
-
|
|
1390
|
+
initialize(): Promise<void>;
|
|
1287
1391
|
/**
|
|
1288
|
-
*
|
|
1392
|
+
* Mark the backend as no longer running.
|
|
1289
1393
|
*
|
|
1290
|
-
*
|
|
1291
|
-
*
|
|
1394
|
+
* For local shell backends there is no remote resource to tear down,
|
|
1395
|
+
* so this simply flips the `isRunning` / `isInitialized` flag.
|
|
1292
1396
|
*/
|
|
1293
|
-
|
|
1397
|
+
close(): Promise<void>;
|
|
1294
1398
|
/**
|
|
1295
|
-
*
|
|
1296
|
-
* Returns WriteResult. External storage sets filesUpdate=null.
|
|
1399
|
+
* Read a file, adapting error messages to the standard sandbox format.
|
|
1297
1400
|
*/
|
|
1298
|
-
|
|
1401
|
+
read(filePath: string, offset?: number, limit?: number): Promise<ReadResult>;
|
|
1299
1402
|
/**
|
|
1300
|
-
* Edit a file
|
|
1301
|
-
* Returns EditResult. External storage sets filesUpdate=null.
|
|
1403
|
+
* Edit a file, adapting error messages to the standard sandbox format.
|
|
1302
1404
|
*/
|
|
1303
1405
|
edit(filePath: string, oldString: string, newString: string, replaceAll?: boolean): Promise<EditResult>;
|
|
1304
1406
|
/**
|
|
1305
|
-
*
|
|
1407
|
+
* List directory contents, returning paths relative to rootDir.
|
|
1306
1408
|
*/
|
|
1307
|
-
|
|
1409
|
+
ls(dirPath: string): Promise<LsResult>;
|
|
1308
1410
|
/**
|
|
1309
|
-
*
|
|
1411
|
+
* Glob matching that returns relative paths and includes directories.
|
|
1310
1412
|
*/
|
|
1311
|
-
|
|
1413
|
+
glob(pattern: string, searchPath?: string): Promise<GlobResult>;
|
|
1312
1414
|
/**
|
|
1313
|
-
*
|
|
1415
|
+
* Execute a shell command directly on the host system.
|
|
1314
1416
|
*
|
|
1315
|
-
*
|
|
1316
|
-
*
|
|
1317
|
-
|
|
1318
|
-
uploadFiles(files: Array<[string, Uint8Array]>): Promise<FileUploadResponse[]>;
|
|
1319
|
-
/**
|
|
1320
|
-
* Download multiple files.
|
|
1417
|
+
* Commands are executed directly on your host system using `spawn()`
|
|
1418
|
+
* with `shell: true`. There is NO sandboxing, isolation, or security
|
|
1419
|
+
* restrictions. The command runs with your user's full permissions.
|
|
1321
1420
|
*
|
|
1322
|
-
*
|
|
1323
|
-
*
|
|
1421
|
+
* The command is executed using the system shell with the working directory
|
|
1422
|
+
* set to the backend's rootDir. Stdout and stderr are combined into a single
|
|
1423
|
+
* output stream, with stderr lines prefixed with `[stderr]`.
|
|
1424
|
+
*
|
|
1425
|
+
* @param command - Shell command string to execute
|
|
1426
|
+
* @returns ExecuteResponse containing output, exit code, and truncation flag
|
|
1324
1427
|
*/
|
|
1325
|
-
|
|
1428
|
+
execute(command: string): Promise<ExecuteResponse>;
|
|
1429
|
+
/**
|
|
1430
|
+
* Create and initialize a new LocalShellBackend in one step.
|
|
1431
|
+
*
|
|
1432
|
+
* This is the recommended way to create a backend when the rootDir may
|
|
1433
|
+
* not exist yet. It combines construction and initialization (ensuring
|
|
1434
|
+
* rootDir exists) into a single async operation.
|
|
1435
|
+
*
|
|
1436
|
+
* @param options - Configuration options for the backend
|
|
1437
|
+
* @returns An initialized and ready-to-use backend
|
|
1438
|
+
*/
|
|
1439
|
+
static create(options?: LocalShellBackendOptions): Promise<LocalShellBackend>;
|
|
1326
1440
|
}
|
|
1327
1441
|
//#endregion
|
|
1328
|
-
//#region src/backends/
|
|
1442
|
+
//#region src/backends/sandbox.d.ts
|
|
1329
1443
|
/**
|
|
1330
|
-
*
|
|
1444
|
+
* Base sandbox implementation with execute() as the only abstract method.
|
|
1331
1445
|
*
|
|
1332
|
-
*
|
|
1333
|
-
*
|
|
1334
|
-
*
|
|
1446
|
+
* This class provides default implementations for all SandboxBackendProtocol
|
|
1447
|
+
* methods using shell commands executed via execute(). Concrete implementations
|
|
1448
|
+
* only need to implement execute(), uploadFiles(), and downloadFiles().
|
|
1449
|
+
*
|
|
1450
|
+
* All shell commands use pure POSIX utilities (awk, grep, find, stat) that are
|
|
1451
|
+
* available on any Linux including Alpine/busybox. No Python, Node.js, or
|
|
1452
|
+
* other runtime is required on the sandbox host.
|
|
1335
1453
|
*/
|
|
1336
|
-
declare class
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
private maxFileSizeBytes;
|
|
1340
|
-
constructor(options?: {
|
|
1341
|
-
rootDir?: string;
|
|
1342
|
-
virtualMode?: boolean;
|
|
1343
|
-
maxFileSizeMb?: number;
|
|
1344
|
-
});
|
|
1454
|
+
declare abstract class BaseSandbox implements SandboxBackendProtocolV2 {
|
|
1455
|
+
/** Unique identifier for the sandbox backend */
|
|
1456
|
+
abstract readonly id: string;
|
|
1345
1457
|
/**
|
|
1346
|
-
*
|
|
1347
|
-
*
|
|
1348
|
-
* When virtualMode=true, treat incoming paths as virtual absolute paths under
|
|
1349
|
-
* this.cwd, disallow traversal (.., ~) and ensure resolved path stays within root.
|
|
1350
|
-
* When virtualMode=false, preserve legacy behavior: absolute paths are allowed
|
|
1351
|
-
* as-is; relative paths resolve under cwd.
|
|
1352
|
-
*
|
|
1353
|
-
* @param key - File path (absolute, relative, or virtual when virtualMode=true)
|
|
1354
|
-
* @returns Resolved absolute path string
|
|
1355
|
-
* @throws Error if path traversal detected or path outside root
|
|
1458
|
+
* Execute a command in the sandbox.
|
|
1459
|
+
* This is the only method concrete implementations must provide.
|
|
1356
1460
|
*/
|
|
1357
|
-
|
|
1461
|
+
abstract execute(command: string): MaybePromise<ExecuteResponse>;
|
|
1462
|
+
/**
|
|
1463
|
+
* Upload multiple files to the sandbox.
|
|
1464
|
+
* Implementations must support partial success.
|
|
1465
|
+
*/
|
|
1466
|
+
abstract uploadFiles(files: Array<[string, Uint8Array]>): MaybePromise<FileUploadResponse[]>;
|
|
1467
|
+
/**
|
|
1468
|
+
* Download multiple files from the sandbox.
|
|
1469
|
+
* Implementations must support partial success.
|
|
1470
|
+
*/
|
|
1471
|
+
abstract downloadFiles(paths: string[]): MaybePromise<FileDownloadResponse[]>;
|
|
1358
1472
|
/**
|
|
1359
1473
|
* List files and directories in the specified directory (non-recursive).
|
|
1360
1474
|
*
|
|
1361
|
-
*
|
|
1362
|
-
*
|
|
1363
|
-
*
|
|
1475
|
+
* Uses pure POSIX shell (find + stat) via execute() — works on any Linux
|
|
1476
|
+
* including Alpine. No Python or Node.js needed.
|
|
1477
|
+
*
|
|
1478
|
+
* @param path - Absolute path to directory
|
|
1479
|
+
* @returns LsResult with list of FileInfo objects on success or error on failure.
|
|
1364
1480
|
*/
|
|
1365
|
-
|
|
1481
|
+
ls(path: string): Promise<LsResult>;
|
|
1366
1482
|
/**
|
|
1367
1483
|
* Read file content with line numbers.
|
|
1368
1484
|
*
|
|
1369
|
-
*
|
|
1485
|
+
* Uses pure POSIX shell (awk) via execute() — only the requested slice
|
|
1486
|
+
* is returned over the wire, making this efficient for large files.
|
|
1487
|
+
* Works on any Linux including Alpine (no Python or Node.js needed).
|
|
1488
|
+
*
|
|
1489
|
+
* @param filePath - Absolute file path
|
|
1370
1490
|
* @param offset - Line offset to start reading from (0-indexed)
|
|
1371
1491
|
* @param limit - Maximum number of lines to read
|
|
1372
1492
|
* @returns Formatted file content with line numbers, or error message
|
|
1373
1493
|
*/
|
|
1374
|
-
read(filePath: string, offset?: number, limit?: number): Promise<
|
|
1494
|
+
read(filePath: string, offset?: number, limit?: number): Promise<ReadResult>;
|
|
1375
1495
|
/**
|
|
1376
1496
|
* Read file content as raw FileData.
|
|
1377
1497
|
*
|
|
1498
|
+
* Uses downloadFiles() directly — no runtime needed on the sandbox host.
|
|
1499
|
+
*
|
|
1378
1500
|
* @param filePath - Absolute file path
|
|
1379
|
-
* @returns
|
|
1380
|
-
*/
|
|
1381
|
-
readRaw(filePath: string): Promise<FileData>;
|
|
1382
|
-
/**
|
|
1383
|
-
* Create a new file with content.
|
|
1384
|
-
* Returns WriteResult. External storage sets filesUpdate=null.
|
|
1501
|
+
* @returns ReadRawResult with raw file data on success or error on failure
|
|
1385
1502
|
*/
|
|
1386
|
-
|
|
1387
|
-
/**
|
|
1388
|
-
* Edit a file by replacing string occurrences.
|
|
1389
|
-
* Returns EditResult. External storage sets filesUpdate=null.
|
|
1390
|
-
*/
|
|
1391
|
-
edit(filePath: string, oldString: string, newString: string, replaceAll?: boolean): Promise<EditResult>;
|
|
1503
|
+
readRaw(filePath: string): Promise<ReadRawResult>;
|
|
1392
1504
|
/**
|
|
1393
|
-
* Search for a literal text pattern in files.
|
|
1394
|
-
*
|
|
1395
|
-
* Uses ripgrep if available, falling back to substring search.
|
|
1505
|
+
* Search for a literal text pattern in files using grep.
|
|
1396
1506
|
*
|
|
1397
1507
|
* @param pattern - Literal string to search for (NOT regex).
|
|
1398
|
-
* @param
|
|
1508
|
+
* @param path - Directory or file path to search in.
|
|
1399
1509
|
* @param glob - Optional glob pattern to filter which files to search.
|
|
1400
1510
|
* @returns List of GrepMatch dicts containing path, line number, and matched text.
|
|
1401
1511
|
*/
|
|
1402
|
-
|
|
1512
|
+
grep(pattern: string, path?: string, glob?: string | null): Promise<GrepResult>;
|
|
1403
1513
|
/**
|
|
1404
|
-
*
|
|
1514
|
+
* Structured glob matching returning FileInfo objects.
|
|
1405
1515
|
*
|
|
1406
|
-
*
|
|
1407
|
-
*
|
|
1408
|
-
*
|
|
1409
|
-
*
|
|
1410
|
-
*
|
|
1516
|
+
* Uses pure POSIX shell (find + stat) via execute() to list all files,
|
|
1517
|
+
* then applies glob-to-regex matching in TypeScript. No Python or Node.js
|
|
1518
|
+
* needed on the sandbox host.
|
|
1519
|
+
*
|
|
1520
|
+
* Glob patterns are matched against paths relative to the search base:
|
|
1521
|
+
* - `*` matches any characters except `/`
|
|
1522
|
+
* - `**` matches any characters including `/` (recursive)
|
|
1523
|
+
* - `?` matches a single character except `/`
|
|
1524
|
+
* - `[...]` character classes
|
|
1411
1525
|
*/
|
|
1412
|
-
|
|
1526
|
+
glob(pattern: string, path?: string): Promise<GlobResult>;
|
|
1413
1527
|
/**
|
|
1414
|
-
*
|
|
1528
|
+
* Create a new file with content.
|
|
1415
1529
|
*
|
|
1416
|
-
*
|
|
1530
|
+
* Uses downloadFiles() to check existence and uploadFiles() to write.
|
|
1531
|
+
* No runtime needed on the sandbox host.
|
|
1532
|
+
*/
|
|
1533
|
+
write(filePath: string, content: string): Promise<WriteResult>;
|
|
1534
|
+
/**
|
|
1535
|
+
* Edit a file by replacing string occurrences.
|
|
1417
1536
|
*
|
|
1418
|
-
*
|
|
1419
|
-
*
|
|
1420
|
-
*
|
|
1421
|
-
*
|
|
1537
|
+
* Uses downloadFiles() to read, performs string replacement in TypeScript,
|
|
1538
|
+
* then uploadFiles() to write back. No runtime needed on the sandbox host.
|
|
1539
|
+
*
|
|
1540
|
+
* Memory-conscious: releases intermediate references early so the GC can
|
|
1541
|
+
* reclaim buffers before the next large allocation is made.
|
|
1422
1542
|
*/
|
|
1423
|
-
|
|
1543
|
+
edit(filePath: string, oldString: string, newString: string, replaceAll?: boolean): Promise<EditResult>;
|
|
1544
|
+
}
|
|
1545
|
+
//#endregion
|
|
1546
|
+
//#region src/backends/langsmith.d.ts
|
|
1547
|
+
/** Options for constructing a LangSmithSandbox from an existing Sandbox instance. */
|
|
1548
|
+
interface LangSmithSandboxOptions {
|
|
1549
|
+
/** An already-created LangSmith Sandbox instance to wrap. */
|
|
1550
|
+
sandbox: Sandbox;
|
|
1424
1551
|
/**
|
|
1425
|
-
*
|
|
1552
|
+
* Default command timeout in seconds.
|
|
1553
|
+
* @default 1800 (30 minutes)
|
|
1426
1554
|
*/
|
|
1427
|
-
|
|
1555
|
+
defaultTimeout?: number;
|
|
1556
|
+
}
|
|
1557
|
+
/** Options for the `LangSmithSandbox.create()` static factory. */
|
|
1558
|
+
interface LangSmithSandboxCreateOptions extends Omit<CreateSandboxOptions, "name" | "timeout" | "waitForReady"> {
|
|
1428
1559
|
/**
|
|
1429
|
-
*
|
|
1430
|
-
*
|
|
1431
|
-
* @param files - List of [path, content] tuples to upload
|
|
1432
|
-
* @returns List of FileUploadResponse objects, one per input file
|
|
1560
|
+
* Name of the LangSmith sandbox template to use.
|
|
1561
|
+
* @default "deepagents"
|
|
1433
1562
|
*/
|
|
1434
|
-
|
|
1563
|
+
templateName?: string;
|
|
1435
1564
|
/**
|
|
1436
|
-
*
|
|
1437
|
-
*
|
|
1438
|
-
* @param paths - List of file paths to download
|
|
1439
|
-
* @returns List of FileDownloadResponse objects, one per input path
|
|
1565
|
+
* LangSmith API key. Defaults to the `LANGSMITH_API_KEY` environment variable.
|
|
1440
1566
|
*/
|
|
1441
|
-
|
|
1567
|
+
apiKey?: string;
|
|
1568
|
+
/**
|
|
1569
|
+
* Default command timeout in seconds.
|
|
1570
|
+
* @default 1800 (30 minutes)
|
|
1571
|
+
*/
|
|
1572
|
+
defaultTimeout?: number;
|
|
1442
1573
|
}
|
|
1443
|
-
//#endregion
|
|
1444
|
-
//#region src/backends/composite.d.ts
|
|
1445
1574
|
/**
|
|
1446
|
-
*
|
|
1575
|
+
* LangSmith Sandbox backend for deepagents.
|
|
1447
1576
|
*
|
|
1448
|
-
*
|
|
1449
|
-
*
|
|
1450
|
-
* - Everything else → StateBackend (ephemeral, per-thread)
|
|
1577
|
+
* Extends `BaseSandbox` to provide command execution and file operations
|
|
1578
|
+
* via the LangSmith Sandbox API.
|
|
1451
1579
|
*
|
|
1452
|
-
*
|
|
1580
|
+
* Use the static `LangSmithSandbox.create()` factory for the simplest setup,
|
|
1581
|
+
* or construct directly with an existing `Sandbox` instance.
|
|
1453
1582
|
*/
|
|
1454
|
-
declare class
|
|
1455
|
-
private
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
/**
|
|
1583
|
+
declare class LangSmithSandbox extends BaseSandbox {
|
|
1584
|
+
#private;
|
|
1585
|
+
constructor(options: LangSmithSandboxOptions);
|
|
1586
|
+
/** Whether the sandbox is currently active. */
|
|
1587
|
+
get isRunning(): boolean;
|
|
1588
|
+
/** Return the LangSmith sandbox name as the unique identifier. */
|
|
1460
1589
|
get id(): string;
|
|
1461
1590
|
/**
|
|
1462
|
-
*
|
|
1463
|
-
*
|
|
1464
|
-
* @param key - Original file path
|
|
1465
|
-
* @returns Tuple of [backend, stripped_key] where stripped_key has the route
|
|
1466
|
-
* prefix removed (but keeps leading slash).
|
|
1467
|
-
*/
|
|
1468
|
-
private getBackendAndKey;
|
|
1469
|
-
/**
|
|
1470
|
-
* List files and directories in the specified directory (non-recursive).
|
|
1471
|
-
*
|
|
1472
|
-
* @param path - Absolute path to directory
|
|
1473
|
-
* @returns List of FileInfo objects with route prefixes added, for files and directories
|
|
1474
|
-
* directly in the directory. Directories have a trailing / in their path and is_dir=true.
|
|
1475
|
-
*/
|
|
1476
|
-
lsInfo(path: string): Promise<FileInfo[]>;
|
|
1477
|
-
/**
|
|
1478
|
-
* Read file content, routing to appropriate backend.
|
|
1479
|
-
*
|
|
1480
|
-
* @param filePath - Absolute file path
|
|
1481
|
-
* @param offset - Line offset to start reading from (0-indexed)
|
|
1482
|
-
* @param limit - Maximum number of lines to read
|
|
1483
|
-
* @returns Formatted file content with line numbers, or error message
|
|
1484
|
-
*/
|
|
1485
|
-
read(filePath: string, offset?: number, limit?: number): Promise<string>;
|
|
1486
|
-
/**
|
|
1487
|
-
* Read file content as raw FileData.
|
|
1591
|
+
* Execute a shell command in the LangSmith sandbox.
|
|
1488
1592
|
*
|
|
1489
|
-
* @param
|
|
1490
|
-
* @
|
|
1593
|
+
* @param command - Shell command string to execute
|
|
1594
|
+
* @param options.timeout - Override timeout in seconds; 0 disables timeout
|
|
1491
1595
|
*/
|
|
1492
|
-
|
|
1596
|
+
execute(command: string, options?: {
|
|
1597
|
+
timeout?: number;
|
|
1598
|
+
}): Promise<ExecuteResponse>;
|
|
1493
1599
|
/**
|
|
1494
|
-
*
|
|
1600
|
+
* Download files from the sandbox using LangSmith's native file read API.
|
|
1601
|
+
* @param paths - List of file paths to download
|
|
1602
|
+
* @returns List of FileDownloadResponse objects, one per input path
|
|
1495
1603
|
*/
|
|
1496
|
-
|
|
1604
|
+
downloadFiles(paths: string[]): Promise<FileDownloadResponse[]>;
|
|
1497
1605
|
/**
|
|
1498
|
-
*
|
|
1606
|
+
* Upload files to the sandbox using LangSmith's native file write API.
|
|
1607
|
+
* @param files - List of [path, content] tuples to upload
|
|
1608
|
+
* @returns List of FileUploadResponse objects, one per input file
|
|
1499
1609
|
*/
|
|
1500
|
-
|
|
1610
|
+
uploadFiles(files: Array<[string, Uint8Array]>): Promise<FileUploadResponse[]>;
|
|
1501
1611
|
/**
|
|
1502
|
-
*
|
|
1612
|
+
* Delete this sandbox and mark it as no longer running.
|
|
1503
1613
|
*
|
|
1504
|
-
*
|
|
1505
|
-
*
|
|
1506
|
-
* @returns WriteResult with path or error
|
|
1614
|
+
* After calling this, `isRunning` will be `false` and the sandbox
|
|
1615
|
+
* cannot be used again.
|
|
1507
1616
|
*/
|
|
1508
|
-
|
|
1617
|
+
close(): Promise<void>;
|
|
1509
1618
|
/**
|
|
1510
|
-
*
|
|
1619
|
+
* Create and return a new LangSmithSandbox in one step.
|
|
1511
1620
|
*
|
|
1512
|
-
*
|
|
1513
|
-
*
|
|
1514
|
-
* @param newString - Replacement string
|
|
1515
|
-
* @param replaceAll - If true, replace all occurrences
|
|
1516
|
-
* @returns EditResult with path, occurrences, or error
|
|
1517
|
-
*/
|
|
1518
|
-
edit(filePath: string, oldString: string, newString: string, replaceAll?: boolean): Promise<EditResult>;
|
|
1519
|
-
/**
|
|
1520
|
-
* Execute a command via the default backend.
|
|
1521
|
-
* Execution is not path-specific, so it always delegates to the default backend.
|
|
1621
|
+
* This is the recommended way to create a sandbox — no need to import
|
|
1622
|
+
* anything from `langsmith/experimental/sandbox` directly.
|
|
1522
1623
|
*
|
|
1523
|
-
* @
|
|
1524
|
-
*
|
|
1525
|
-
*
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
*
|
|
1530
|
-
*
|
|
1531
|
-
*
|
|
1532
|
-
*
|
|
1533
|
-
*/
|
|
1534
|
-
uploadFiles(files: Array<[string, Uint8Array]>): Promise<FileUploadResponse[]>;
|
|
1535
|
-
/**
|
|
1536
|
-
* Download multiple files, batching by backend for efficiency.
|
|
1537
|
-
*
|
|
1538
|
-
* @param paths - List of file paths to download
|
|
1539
|
-
* @returns List of FileDownloadResponse objects, one per input path
|
|
1624
|
+
* @example
|
|
1625
|
+
* ```typescript
|
|
1626
|
+
* const sandbox = await LangSmithSandbox.create({ templateName: "deepagents" });
|
|
1627
|
+
* try {
|
|
1628
|
+
* const agent = createDeepAgent({ model, backend: sandbox });
|
|
1629
|
+
* await agent.invoke({ messages: [...] });
|
|
1630
|
+
* } finally {
|
|
1631
|
+
* await sandbox.close();
|
|
1632
|
+
* }
|
|
1633
|
+
* ```
|
|
1540
1634
|
*/
|
|
1541
|
-
|
|
1635
|
+
static create(options?: LangSmithSandboxCreateOptions): Promise<LangSmithSandbox>;
|
|
1542
1636
|
}
|
|
1543
1637
|
//#endregion
|
|
1544
|
-
//#region src/backends/
|
|
1638
|
+
//#region src/backends/utils.d.ts
|
|
1545
1639
|
/**
|
|
1546
|
-
*
|
|
1640
|
+
* Adapt a v1 {@link BackendProtocol} to {@link BackendProtocolV2}.
|
|
1641
|
+
*
|
|
1642
|
+
* If the backend already implements v2, it is returned as-is.
|
|
1643
|
+
* For v1 backends, wraps returns in Result types:
|
|
1644
|
+
* - `read()` string returns wrapped in {@link ReadResult}
|
|
1645
|
+
* - `readRaw()` FileData returns wrapped in {@link ReadRawResult}
|
|
1646
|
+
* - `grep()` returns wrapped in {@link GrepResult}
|
|
1647
|
+
* - `ls()` FileInfo[] returns wrapped in {@link LsResult}
|
|
1648
|
+
* - `glob()` FileInfo[] returns wrapped in {@link GlobResult}
|
|
1649
|
+
*
|
|
1650
|
+
* Note: For sandbox instances, use {@link adaptSandboxProtocol} instead.
|
|
1651
|
+
*
|
|
1652
|
+
* @param backend - Backend instance (v1 or v2)
|
|
1653
|
+
* @returns BackendProtocolV2-compatible backend
|
|
1547
1654
|
*/
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1655
|
+
declare function adaptBackendProtocol(backend: AnyBackendProtocol): BackendProtocolV2;
|
|
1656
|
+
/**
|
|
1657
|
+
* Adapt a sandbox backend from v1 to v2 interface.
|
|
1658
|
+
*
|
|
1659
|
+
* This extends {@link adaptBackendProtocol} to also preserve sandbox-specific
|
|
1660
|
+
* properties from {@link SandboxBackendProtocol}: `execute` and `id`.
|
|
1661
|
+
*
|
|
1662
|
+
* @param sandbox - Sandbox backend (v1 or v2)
|
|
1663
|
+
* @returns SandboxBackendProtocolV2-compatible sandbox
|
|
1664
|
+
*/
|
|
1665
|
+
declare function adaptSandboxProtocol(sandbox: AnySandboxProtocol): SandboxBackendProtocolV2;
|
|
1666
|
+
//#endregion
|
|
1667
|
+
//#region src/middleware/subagents.d.ts
|
|
1668
|
+
/**
|
|
1669
|
+
* Default system prompt for subagents.
|
|
1670
|
+
* Provides a minimal base prompt that can be extended by specific subagent configurations.
|
|
1671
|
+
*/
|
|
1672
|
+
declare const DEFAULT_SUBAGENT_PROMPT = "In order to complete the objective that the user asks of you, you have access to a number of standard tools.";
|
|
1673
|
+
/**
|
|
1674
|
+
* Default description for the general-purpose subagent.
|
|
1675
|
+
* This description is shown to the model when selecting which subagent to use.
|
|
1676
|
+
*/
|
|
1677
|
+
declare const DEFAULT_GENERAL_PURPOSE_DESCRIPTION = "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. This agent has access to all tools as the main agent.";
|
|
1678
|
+
/**
|
|
1679
|
+
* System prompt section that explains how to use the task tool for spawning subagents.
|
|
1680
|
+
*
|
|
1681
|
+
* This prompt is automatically appended to the main agent's system prompt when
|
|
1682
|
+
* using `createSubAgentMiddleware`. It provides guidance on:
|
|
1683
|
+
* - When to use the task tool
|
|
1684
|
+
* - Subagent lifecycle (spawn → run → return → reconcile)
|
|
1685
|
+
* - When NOT to use the task tool
|
|
1686
|
+
* - Best practices for parallel task execution
|
|
1687
|
+
*
|
|
1688
|
+
* You can provide a custom `systemPrompt` to `createSubAgentMiddleware` to override
|
|
1689
|
+
* or extend this default.
|
|
1690
|
+
*/
|
|
1691
|
+
declare const TASK_SYSTEM_PROMPT: string;
|
|
1692
|
+
/**
|
|
1693
|
+
* Type definitions for pre-compiled agents.
|
|
1694
|
+
*
|
|
1695
|
+
* @typeParam TRunnable - The type of the runnable (ReactAgent or Runnable).
|
|
1696
|
+
* When using `createAgent` or `createDeepAgent`, this preserves the middleware
|
|
1697
|
+
* types for type inference. Uses `ReactAgent<any>` to accept agents with any
|
|
1698
|
+
* type configuration (including DeepAgent instances).
|
|
1699
|
+
*/
|
|
1700
|
+
interface CompiledSubAgent<TRunnable extends ReactAgent<any> | Runnable = ReactAgent<any> | Runnable> {
|
|
1701
|
+
/** The name of the agent */
|
|
1702
|
+
name: string;
|
|
1703
|
+
/** The description of the agent */
|
|
1704
|
+
description: string;
|
|
1705
|
+
/** The agent instance */
|
|
1706
|
+
runnable: TRunnable;
|
|
1707
|
+
}
|
|
1708
|
+
/**
|
|
1709
|
+
* Specification for a subagent that can be dynamically created.
|
|
1710
|
+
*
|
|
1711
|
+
* When using `createDeepAgent`, subagents automatically receive a default middleware
|
|
1712
|
+
* stack (todoListMiddleware, filesystemMiddleware, summarizationMiddleware, etc.) before
|
|
1713
|
+
* any custom `middleware` specified in this spec.
|
|
1714
|
+
*
|
|
1715
|
+
* Required fields:
|
|
1716
|
+
* - `name`: Identifier used to select this subagent in the task tool
|
|
1717
|
+
* - `description`: Shown to the model for subagent selection
|
|
1718
|
+
* - `systemPrompt`: The system prompt for the subagent
|
|
1719
|
+
*
|
|
1720
|
+
* Optional fields:
|
|
1721
|
+
* - `model`: Override the default model for this subagent
|
|
1722
|
+
* - `tools`: Override the default tools for this subagent
|
|
1723
|
+
* - `middleware`: Additional middleware appended after defaults
|
|
1724
|
+
* - `interruptOn`: Human-in-the-loop configuration for specific tools
|
|
1725
|
+
* - `skills`: Skill source paths for SkillsMiddleware (e.g., `["/skills/user/", "/skills/project/"]`)
|
|
1726
|
+
*
|
|
1727
|
+
* @example
|
|
1728
|
+
* ```typescript
|
|
1729
|
+
* const researcher: SubAgent = {
|
|
1730
|
+
* name: "researcher",
|
|
1731
|
+
* description: "Research assistant for complex topics",
|
|
1732
|
+
* systemPrompt: "You are a research assistant.",
|
|
1733
|
+
* tools: [webSearchTool],
|
|
1734
|
+
* skills: ["/skills/research/"],
|
|
1735
|
+
* };
|
|
1736
|
+
* ```
|
|
1737
|
+
*/
|
|
1738
|
+
interface SubAgent {
|
|
1739
|
+
/** Identifier used to select this subagent in the task tool */
|
|
1740
|
+
name: string;
|
|
1741
|
+
/** Description shown to the model for subagent selection */
|
|
1742
|
+
description: string;
|
|
1743
|
+
/** The system prompt to use for the agent */
|
|
1744
|
+
systemPrompt: string;
|
|
1745
|
+
/** The tools to use for the agent (tool instances, not names). Defaults to defaultTools */
|
|
1746
|
+
tools?: StructuredTool[];
|
|
1747
|
+
/** The model for the agent. Defaults to defaultModel */
|
|
1748
|
+
model?: LanguageModelLike | string;
|
|
1749
|
+
/** Additional middleware to append after default_middleware */
|
|
1750
|
+
middleware?: readonly AgentMiddleware$1[];
|
|
1751
|
+
/** Human-in-the-loop configuration for specific tools. Requires a checkpointer. */
|
|
1752
|
+
interruptOn?: Record<string, boolean | InterruptOnConfig>;
|
|
1579
1753
|
/**
|
|
1580
|
-
*
|
|
1581
|
-
*
|
|
1582
|
-
*
|
|
1583
|
-
*
|
|
1754
|
+
* Skill source paths for SkillsMiddleware.
|
|
1755
|
+
*
|
|
1756
|
+
* List of paths to skill directories (e.g., `["/skills/user/", "/skills/project/"]`).
|
|
1757
|
+
* When specified, the subagent will have its own SkillsMiddleware that loads skills
|
|
1758
|
+
* from these paths. This allows subagents to have different skill sets than the main agent.
|
|
1759
|
+
*
|
|
1760
|
+
* Note: Custom subagents do NOT inherit skills from the main agent by default.
|
|
1761
|
+
* Only the general-purpose subagent inherits the main agent's skills.
|
|
1762
|
+
*
|
|
1763
|
+
* @example
|
|
1764
|
+
* ```typescript
|
|
1765
|
+
* const researcher: SubAgent = {
|
|
1766
|
+
* name: "researcher",
|
|
1767
|
+
* description: "Research assistant",
|
|
1768
|
+
* systemPrompt: "You are a researcher.",
|
|
1769
|
+
* skills: ["/skills/research/", "/skills/web-search/"],
|
|
1770
|
+
* };
|
|
1771
|
+
* ```
|
|
1584
1772
|
*/
|
|
1585
|
-
|
|
1773
|
+
skills?: string[];
|
|
1586
1774
|
/**
|
|
1587
|
-
*
|
|
1588
|
-
*
|
|
1589
|
-
*
|
|
1590
|
-
*
|
|
1775
|
+
* Structured output response format for the subagent.
|
|
1776
|
+
*
|
|
1777
|
+
* When specified, the subagent will produce a `structuredResponse` conforming to the
|
|
1778
|
+
* given schema. The structured response is JSON-serialized and returned as the
|
|
1779
|
+
* ToolMessage content to the parent agent, replacing the default last-message extraction.
|
|
1780
|
+
*
|
|
1781
|
+
* Accepts any format supported by `createAgent`: Zod schemas, JSON schema objects,
|
|
1782
|
+
* `toolStrategy(schema)`, `providerStrategy(schema)`, etc.
|
|
1783
|
+
*
|
|
1784
|
+
* @example
|
|
1785
|
+
* ```typescript
|
|
1786
|
+
* import { z } from "zod"
|
|
1787
|
+
*
|
|
1788
|
+
* const analyzer: SubAgent = {
|
|
1789
|
+
* name: "analyzer",
|
|
1790
|
+
* description: "Analyzes data and returns structured findings",
|
|
1791
|
+
* systemPrompt: "Analyze the data and return your findings.",
|
|
1792
|
+
* responseFormat: z.object({
|
|
1793
|
+
* findings: z.string(),
|
|
1794
|
+
* confidence: z.number(),
|
|
1795
|
+
* }),
|
|
1796
|
+
* };
|
|
1797
|
+
* ```
|
|
1591
1798
|
*/
|
|
1592
|
-
|
|
1799
|
+
responseFormat?: CreateAgentParams["responseFormat"];
|
|
1593
1800
|
}
|
|
1594
1801
|
/**
|
|
1595
|
-
*
|
|
1596
|
-
*
|
|
1597
|
-
* This backend extends FilesystemBackend to add shell command execution
|
|
1598
|
-
* capabilities. Commands are executed directly on the host system without any
|
|
1599
|
-
* sandboxing, process isolation, or security restrictions.
|
|
1600
|
-
*
|
|
1601
|
-
* **Security Warning:**
|
|
1602
|
-
* This backend grants agents BOTH direct filesystem access AND unrestricted
|
|
1603
|
-
* shell execution on your local machine. Use with extreme caution and only in
|
|
1604
|
-
* appropriate environments.
|
|
1802
|
+
* Base specification for the general-purpose subagent.
|
|
1605
1803
|
*
|
|
1606
|
-
*
|
|
1607
|
-
*
|
|
1608
|
-
* - Personal development environments where you trust the agent's code
|
|
1609
|
-
* - CI/CD pipelines with proper secret management
|
|
1804
|
+
* This constant provides the default configuration for the general-purpose subagent
|
|
1805
|
+
* that is automatically included when `generalPurposeAgent: true` (the default).
|
|
1610
1806
|
*
|
|
1611
|
-
*
|
|
1612
|
-
* -
|
|
1613
|
-
* -
|
|
1807
|
+
* The general-purpose subagent:
|
|
1808
|
+
* - Has access to all tools from the main agent
|
|
1809
|
+
* - Inherits skills from the main agent (when skills are configured)
|
|
1810
|
+
* - Uses the same model as the main agent (by default)
|
|
1811
|
+
* - Is ideal for delegating complex, multi-step tasks
|
|
1614
1812
|
*
|
|
1615
|
-
*
|
|
1813
|
+
* You can spread this constant and override specific properties when creating
|
|
1814
|
+
* custom subagents that should behave similarly to the general-purpose agent:
|
|
1616
1815
|
*
|
|
1617
1816
|
* @example
|
|
1618
1817
|
* ```typescript
|
|
1619
|
-
* import {
|
|
1818
|
+
* import { GENERAL_PURPOSE_SUBAGENT, createDeepAgent } from "@anthropic/deepagents";
|
|
1620
1819
|
*
|
|
1621
|
-
* //
|
|
1622
|
-
* const
|
|
1623
|
-
*
|
|
1624
|
-
*
|
|
1820
|
+
* // Use as-is (automatically included with generalPurposeAgent: true)
|
|
1821
|
+
* const agent = createDeepAgent({ model: "claude-sonnet-4-5-20250929" });
|
|
1822
|
+
*
|
|
1823
|
+
* // Or create a custom variant with different tools
|
|
1824
|
+
* const customGP: SubAgent = {
|
|
1825
|
+
* ...GENERAL_PURPOSE_SUBAGENT,
|
|
1826
|
+
* name: "research-gp",
|
|
1827
|
+
* tools: [webSearchTool, readFileTool],
|
|
1828
|
+
* };
|
|
1829
|
+
*
|
|
1830
|
+
* const agent = createDeepAgent({
|
|
1831
|
+
* model: "claude-sonnet-4-5-20250929",
|
|
1832
|
+
* subagents: [customGP],
|
|
1833
|
+
* // Disable the default general-purpose agent since we're providing our own
|
|
1834
|
+
* // (handled automatically when using createSubAgentMiddleware directly)
|
|
1625
1835
|
* });
|
|
1836
|
+
* ```
|
|
1837
|
+
*/
|
|
1838
|
+
declare const GENERAL_PURPOSE_SUBAGENT: Pick<SubAgent, "name" | "description" | "systemPrompt">;
|
|
1839
|
+
/**
|
|
1840
|
+
* Options for creating subagent middleware
|
|
1841
|
+
*/
|
|
1842
|
+
interface SubAgentMiddlewareOptions {
|
|
1843
|
+
/** The model to use for subagents */
|
|
1844
|
+
defaultModel: LanguageModelLike | string;
|
|
1845
|
+
/** The tools to use for the default general-purpose subagent */
|
|
1846
|
+
defaultTools?: StructuredTool[];
|
|
1847
|
+
/** Default middleware to apply to custom subagents (WITHOUT skills from main agent) */
|
|
1848
|
+
defaultMiddleware?: AgentMiddleware$1[] | null;
|
|
1849
|
+
/**
|
|
1850
|
+
* Middleware specifically for the general-purpose subagent (includes skills from main agent).
|
|
1851
|
+
* If not provided, falls back to defaultMiddleware.
|
|
1852
|
+
*/
|
|
1853
|
+
generalPurposeMiddleware?: AgentMiddleware$1[] | null;
|
|
1854
|
+
/** The tool configs for the default general-purpose subagent */
|
|
1855
|
+
defaultInterruptOn?: Record<string, boolean | InterruptOnConfig> | null;
|
|
1856
|
+
/** A list of additional subagents to provide to the agent */
|
|
1857
|
+
subagents?: (SubAgent | CompiledSubAgent)[];
|
|
1858
|
+
/** Full system prompt override */
|
|
1859
|
+
systemPrompt?: string | null;
|
|
1860
|
+
/** Whether to include the general-purpose agent */
|
|
1861
|
+
generalPurposeAgent?: boolean;
|
|
1862
|
+
/** Custom description for the task tool */
|
|
1863
|
+
taskDescription?: string | null;
|
|
1864
|
+
}
|
|
1865
|
+
/**
|
|
1866
|
+
* Create subagent middleware with task tool
|
|
1867
|
+
*/
|
|
1868
|
+
declare function createSubAgentMiddleware(options: SubAgentMiddlewareOptions): AgentMiddleware$1<undefined, undefined, unknown, readonly [_langchain.DynamicStructuredTool<z.ZodObject<{
|
|
1869
|
+
description: z.ZodString;
|
|
1870
|
+
subagent_type: z.ZodString;
|
|
1871
|
+
}, z.core.$strip>, {
|
|
1872
|
+
description: string;
|
|
1873
|
+
subagent_type: string;
|
|
1874
|
+
}, {
|
|
1875
|
+
description: string;
|
|
1876
|
+
subagent_type: string;
|
|
1877
|
+
}, string | Command<unknown, Record<string, unknown>, string>, unknown, "task">]>;
|
|
1878
|
+
//#endregion
|
|
1879
|
+
//#region src/middleware/patch_tool_calls.d.ts
|
|
1880
|
+
/**
|
|
1881
|
+
* Create middleware that enforces strict tool call / tool response parity in
|
|
1882
|
+
* the messages history.
|
|
1883
|
+
*
|
|
1884
|
+
* Two kinds of violations are repaired:
|
|
1885
|
+
* 1. **Dangling tool_calls** — an AIMessage contains tool_calls with no
|
|
1886
|
+
* matching ToolMessage responses. Synthetic cancellation ToolMessages are
|
|
1887
|
+
* injected so every tool_call has a response.
|
|
1888
|
+
* 2. **Orphaned ToolMessages** — a ToolMessage exists whose `tool_call_id`
|
|
1889
|
+
* does not match any tool_call in a preceding AIMessage. These are removed.
|
|
1890
|
+
*
|
|
1891
|
+
* This is critical for providers like Google Gemini that reject requests with
|
|
1892
|
+
* mismatched function call / function response counts (400 INVALID_ARGUMENT).
|
|
1893
|
+
*
|
|
1894
|
+
* This middleware patches in two places:
|
|
1895
|
+
* 1. `beforeAgent`: Patches state at the start of the agent loop (handles most cases)
|
|
1896
|
+
* 2. `wrapModelCall`: Patches the request right before model invocation (handles
|
|
1897
|
+
* edge cases like HITL rejection during graph resume where state updates from
|
|
1898
|
+
* beforeAgent may not be applied in time)
|
|
1626
1899
|
*
|
|
1627
|
-
*
|
|
1628
|
-
* const result = await backend.execute("ls -la");
|
|
1629
|
-
* console.log(result.output);
|
|
1630
|
-
* console.log(result.exitCode);
|
|
1900
|
+
* @returns AgentMiddleware that enforces tool call / response parity
|
|
1631
1901
|
*
|
|
1632
|
-
*
|
|
1633
|
-
*
|
|
1634
|
-
*
|
|
1902
|
+
* @example
|
|
1903
|
+
* ```typescript
|
|
1904
|
+
* import { createAgent } from "langchain";
|
|
1905
|
+
* import { createPatchToolCallsMiddleware } from "./middleware/patch_tool_calls";
|
|
1635
1906
|
*
|
|
1636
|
-
*
|
|
1637
|
-
*
|
|
1638
|
-
*
|
|
1639
|
-
* inheritEnv: true,
|
|
1907
|
+
* const agent = createAgent({
|
|
1908
|
+
* model: "claude-sonnet-4-5-20250929",
|
|
1909
|
+
* middleware: [createPatchToolCallsMiddleware()],
|
|
1640
1910
|
* });
|
|
1641
1911
|
* ```
|
|
1642
1912
|
*/
|
|
1643
|
-
declare
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
/** Alias for `isInitialized`, matching the standard sandbox interface. */
|
|
1651
|
-
get isRunning(): boolean;
|
|
1652
|
-
/**
|
|
1653
|
-
* Initialize the backend by ensuring the rootDir exists.
|
|
1654
|
-
*
|
|
1655
|
-
* Creates the rootDir (and any parent directories) if it does not already
|
|
1656
|
-
* exist. Safe to call on an existing directory. Must be called before
|
|
1657
|
-
* `execute()`, or use the static `LocalShellBackend.create()` factory.
|
|
1658
|
-
*
|
|
1659
|
-
* @throws {SandboxError} If already initialized (`ALREADY_INITIALIZED`)
|
|
1660
|
-
*/
|
|
1661
|
-
initialize(): Promise<void>;
|
|
1662
|
-
/**
|
|
1663
|
-
* Mark the backend as no longer running.
|
|
1664
|
-
*
|
|
1665
|
-
* For local shell backends there is no remote resource to tear down,
|
|
1666
|
-
* so this simply flips the `isRunning` / `isInitialized` flag.
|
|
1667
|
-
*/
|
|
1668
|
-
close(): Promise<void>;
|
|
1669
|
-
/**
|
|
1670
|
-
* Read a file, adapting error messages to the standard sandbox format.
|
|
1671
|
-
*/
|
|
1672
|
-
read(filePath: string, offset?: number, limit?: number): Promise<string>;
|
|
1673
|
-
/**
|
|
1674
|
-
* Edit a file, adapting error messages to the standard sandbox format.
|
|
1675
|
-
*/
|
|
1676
|
-
edit(filePath: string, oldString: string, newString: string, replaceAll?: boolean): Promise<EditResult>;
|
|
1677
|
-
/**
|
|
1678
|
-
* List directory contents, returning paths relative to rootDir.
|
|
1679
|
-
*/
|
|
1680
|
-
lsInfo(dirPath: string): Promise<FileInfo[]>;
|
|
1913
|
+
declare function createPatchToolCallsMiddleware(): AgentMiddleware<undefined, undefined, unknown, readonly (_$_langchain_core_tools0.ClientTool | _$_langchain_core_tools0.ServerTool)[]>;
|
|
1914
|
+
//#endregion
|
|
1915
|
+
//#region src/middleware/memory.d.ts
|
|
1916
|
+
/**
|
|
1917
|
+
* Options for the memory middleware.
|
|
1918
|
+
*/
|
|
1919
|
+
interface MemoryMiddlewareOptions {
|
|
1681
1920
|
/**
|
|
1682
|
-
*
|
|
1921
|
+
* Backend instance or factory function for file operations.
|
|
1922
|
+
* Use a factory for StateBackend since it requires runtime state.
|
|
1683
1923
|
*/
|
|
1684
|
-
|
|
1924
|
+
backend: AnyBackendProtocol | BackendFactory | ((config: {
|
|
1925
|
+
state: unknown;
|
|
1926
|
+
store?: BaseStore;
|
|
1927
|
+
}) => StateBackend);
|
|
1685
1928
|
/**
|
|
1686
|
-
*
|
|
1687
|
-
*
|
|
1688
|
-
*
|
|
1689
|
-
* with `shell: true`. There is NO sandboxing, isolation, or security
|
|
1690
|
-
* restrictions. The command runs with your user's full permissions.
|
|
1691
|
-
*
|
|
1692
|
-
* The command is executed using the system shell with the working directory
|
|
1693
|
-
* set to the backend's rootDir. Stdout and stderr are combined into a single
|
|
1694
|
-
* output stream, with stderr lines prefixed with `[stderr]`.
|
|
1695
|
-
*
|
|
1696
|
-
* @param command - Shell command string to execute
|
|
1697
|
-
* @returns ExecuteResponse containing output, exit code, and truncation flag
|
|
1929
|
+
* List of memory file paths to load (e.g., ["~/.deepagents/AGENTS.md", "./.deepagents/AGENTS.md"]).
|
|
1930
|
+
* Display names are automatically derived from the paths.
|
|
1931
|
+
* Sources are loaded in order.
|
|
1698
1932
|
*/
|
|
1699
|
-
|
|
1933
|
+
sources: string[];
|
|
1700
1934
|
/**
|
|
1701
|
-
*
|
|
1702
|
-
*
|
|
1703
|
-
*
|
|
1704
|
-
*
|
|
1705
|
-
* rootDir exists) into a single async operation.
|
|
1706
|
-
*
|
|
1707
|
-
* @param options - Configuration options for the backend
|
|
1708
|
-
* @returns An initialized and ready-to-use backend
|
|
1935
|
+
* Whether to add cache_control breakpoints to the memory content block.
|
|
1936
|
+
* When true, the memory block is tagged with `cache_control: { type: "ephemeral" }`
|
|
1937
|
+
* to enable prompt caching for providers that support it (e.g., Anthropic).
|
|
1938
|
+
* @default false
|
|
1709
1939
|
*/
|
|
1710
|
-
|
|
1940
|
+
addCacheControl?: boolean;
|
|
1711
1941
|
}
|
|
1712
|
-
//#endregion
|
|
1713
|
-
//#region src/backends/sandbox.d.ts
|
|
1714
1942
|
/**
|
|
1715
|
-
*
|
|
1943
|
+
* Create middleware for loading agent memory from AGENTS.md files.
|
|
1716
1944
|
*
|
|
1717
|
-
*
|
|
1718
|
-
*
|
|
1719
|
-
* only need to implement execute(), uploadFiles(), and downloadFiles().
|
|
1945
|
+
* Loads memory content from configured sources and injects into the system prompt.
|
|
1946
|
+
* Supports multiple sources that are combined together.
|
|
1720
1947
|
*
|
|
1721
|
-
*
|
|
1722
|
-
*
|
|
1723
|
-
*
|
|
1948
|
+
* @param options - Configuration options
|
|
1949
|
+
* @returns AgentMiddleware for memory loading and injection
|
|
1950
|
+
*
|
|
1951
|
+
* @example
|
|
1952
|
+
* ```typescript
|
|
1953
|
+
* const middleware = createMemoryMiddleware({
|
|
1954
|
+
* backend: new FilesystemBackend({ rootDir: "/" }),
|
|
1955
|
+
* sources: [
|
|
1956
|
+
* "~/.deepagents/AGENTS.md",
|
|
1957
|
+
* "./.deepagents/AGENTS.md",
|
|
1958
|
+
* ],
|
|
1959
|
+
* });
|
|
1960
|
+
* ```
|
|
1724
1961
|
*/
|
|
1725
|
-
declare
|
|
1726
|
-
/** Unique identifier for the sandbox backend */
|
|
1727
|
-
abstract readonly id: string;
|
|
1962
|
+
declare function createMemoryMiddleware(options: MemoryMiddlewareOptions): AgentMiddleware<StateSchema<{
|
|
1728
1963
|
/**
|
|
1729
|
-
*
|
|
1730
|
-
*
|
|
1964
|
+
* Dict mapping source paths to their loaded content.
|
|
1965
|
+
* Marked as private so it's not included in the final agent state.
|
|
1731
1966
|
*/
|
|
1732
|
-
|
|
1967
|
+
memoryContents: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodString>>;
|
|
1968
|
+
files: _langgraph.ReducedValue<FilesRecord | undefined, FilesRecordUpdate | undefined>;
|
|
1969
|
+
}>, undefined, unknown, readonly (_$_langchain_core_tools0.ClientTool | _$_langchain_core_tools0.ServerTool)[]>;
|
|
1970
|
+
//#endregion
|
|
1971
|
+
//#region src/middleware/skills.d.ts
|
|
1972
|
+
declare const MAX_SKILL_FILE_SIZE: number;
|
|
1973
|
+
declare const MAX_SKILL_NAME_LENGTH = 64;
|
|
1974
|
+
declare const MAX_SKILL_DESCRIPTION_LENGTH = 1024;
|
|
1975
|
+
/**
|
|
1976
|
+
* Metadata for a skill per Agent Skills specification.
|
|
1977
|
+
*/
|
|
1978
|
+
interface SkillMetadata$1 {
|
|
1733
1979
|
/**
|
|
1734
|
-
*
|
|
1735
|
-
*
|
|
1980
|
+
* Skill identifier.
|
|
1981
|
+
*
|
|
1982
|
+
* Constraints per Agent Skills specification:
|
|
1983
|
+
*
|
|
1984
|
+
* - 1-64 characters
|
|
1985
|
+
* - Unicode lowercase alphanumeric and hyphens only (`a-z` and `-`).
|
|
1986
|
+
* - Must not start or end with `-`
|
|
1987
|
+
* - Must not contain consecutive `--`
|
|
1988
|
+
* - Must match the parent directory name containing the `SKILL.md` file
|
|
1736
1989
|
*/
|
|
1737
|
-
|
|
1990
|
+
name: string;
|
|
1738
1991
|
/**
|
|
1739
|
-
*
|
|
1740
|
-
*
|
|
1992
|
+
* What the skill does.
|
|
1993
|
+
*
|
|
1994
|
+
* Constraints per Agent Skills specification:
|
|
1995
|
+
*
|
|
1996
|
+
* - 1-1024 characters
|
|
1997
|
+
* - Should describe both what the skill does and when to use it
|
|
1998
|
+
* - Should include specific keywords that help agents identify relevant tasks
|
|
1741
1999
|
*/
|
|
1742
|
-
|
|
2000
|
+
description: string;
|
|
2001
|
+
/** Path to the SKILL.md file in the backend */
|
|
2002
|
+
path: string;
|
|
2003
|
+
/** License name or reference to bundled license file. */
|
|
2004
|
+
license?: string | null;
|
|
1743
2005
|
/**
|
|
1744
|
-
*
|
|
2006
|
+
* Environment requirements.
|
|
1745
2007
|
*
|
|
1746
|
-
*
|
|
1747
|
-
* including Alpine. No Python or Node.js needed.
|
|
2008
|
+
* Constraints per Agent Skills specification:
|
|
1748
2009
|
*
|
|
1749
|
-
*
|
|
1750
|
-
*
|
|
2010
|
+
* - 1-500 characters if provided
|
|
2011
|
+
* - Should only be included if there are specific compatibility requirements
|
|
2012
|
+
* - Can indicate intended product, required packages, etc.
|
|
1751
2013
|
*/
|
|
1752
|
-
|
|
2014
|
+
compatibility?: string | null;
|
|
1753
2015
|
/**
|
|
1754
|
-
*
|
|
2016
|
+
* Arbitrary key-value mapping for additional metadata.
|
|
1755
2017
|
*
|
|
1756
|
-
*
|
|
1757
|
-
* is returned over the wire, making this efficient for large files.
|
|
1758
|
-
* Works on any Linux including Alpine (no Python or Node.js needed).
|
|
2018
|
+
* Clients can use this to store additional properties not defined by the spec.
|
|
1759
2019
|
*
|
|
1760
|
-
*
|
|
1761
|
-
* @param offset - Line offset to start reading from (0-indexed)
|
|
1762
|
-
* @param limit - Maximum number of lines to read
|
|
1763
|
-
* @returns Formatted file content with line numbers, or error message
|
|
2020
|
+
* It is recommended to keep key names unique to avoid conflicts.
|
|
1764
2021
|
*/
|
|
1765
|
-
|
|
2022
|
+
metadata?: Record<string, string>;
|
|
1766
2023
|
/**
|
|
1767
|
-
*
|
|
2024
|
+
* Tool names the skill recommends using.
|
|
1768
2025
|
*
|
|
1769
|
-
*
|
|
2026
|
+
* Warning: this is experimental.
|
|
1770
2027
|
*
|
|
1771
|
-
*
|
|
1772
|
-
*
|
|
2028
|
+
* Constraints per Agent Skills specification:
|
|
2029
|
+
*
|
|
2030
|
+
* - Space-delimited list of tool names
|
|
1773
2031
|
*/
|
|
1774
|
-
|
|
2032
|
+
allowedTools?: string[];
|
|
2033
|
+
}
|
|
2034
|
+
/**
|
|
2035
|
+
* Options for the skills middleware.
|
|
2036
|
+
*/
|
|
2037
|
+
interface SkillsMiddlewareOptions {
|
|
1775
2038
|
/**
|
|
1776
|
-
*
|
|
1777
|
-
*
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
2039
|
+
* Backend instance or factory function for file operations.
|
|
2040
|
+
* Use a factory for StateBackend since it requires runtime state.
|
|
2041
|
+
*/
|
|
2042
|
+
backend: AnyBackendProtocol | BackendFactory | ((config: {
|
|
2043
|
+
state: unknown;
|
|
2044
|
+
store?: BaseStore;
|
|
2045
|
+
}) => StateBackend);
|
|
2046
|
+
/**
|
|
2047
|
+
* List of skill source paths to load (e.g., ["/skills/user/", "/skills/project/"]).
|
|
2048
|
+
* Paths must use POSIX conventions (forward slashes).
|
|
2049
|
+
* Later sources override earlier ones for skills with the same name (last one wins).
|
|
1782
2050
|
*/
|
|
1783
|
-
|
|
2051
|
+
sources: string[];
|
|
2052
|
+
}
|
|
2053
|
+
/**
|
|
2054
|
+
* Create backend-agnostic middleware for loading and exposing agent skills.
|
|
2055
|
+
*
|
|
2056
|
+
* This middleware loads skills from configurable backend sources and injects
|
|
2057
|
+
* skill metadata into the system prompt. It implements the progressive disclosure
|
|
2058
|
+
* pattern: skill names and descriptions are shown in the prompt, but the agent
|
|
2059
|
+
* reads full SKILL.md content only when needed.
|
|
2060
|
+
*
|
|
2061
|
+
* @param options - Configuration options
|
|
2062
|
+
* @returns AgentMiddleware for skills loading and injection
|
|
2063
|
+
*
|
|
2064
|
+
* @example
|
|
2065
|
+
* ```typescript
|
|
2066
|
+
* const middleware = createSkillsMiddleware({
|
|
2067
|
+
* backend: new FilesystemBackend({ rootDir: "/" }),
|
|
2068
|
+
* sources: ["/skills/user/", "/skills/project/"],
|
|
2069
|
+
* });
|
|
2070
|
+
* ```
|
|
2071
|
+
*/
|
|
2072
|
+
declare function createSkillsMiddleware(options: SkillsMiddlewareOptions): AgentMiddleware<StateSchema<{
|
|
2073
|
+
skillsMetadata: ReducedValue<{
|
|
2074
|
+
name: string;
|
|
2075
|
+
description: string;
|
|
2076
|
+
path: string;
|
|
2077
|
+
license?: string | null | undefined;
|
|
2078
|
+
compatibility?: string | null | undefined;
|
|
2079
|
+
metadata?: Record<string, string> | undefined;
|
|
2080
|
+
allowedTools?: string[] | undefined;
|
|
2081
|
+
}[] | undefined, {
|
|
2082
|
+
name: string;
|
|
2083
|
+
description: string;
|
|
2084
|
+
path: string;
|
|
2085
|
+
license?: string | null | undefined;
|
|
2086
|
+
compatibility?: string | null | undefined;
|
|
2087
|
+
metadata?: Record<string, string> | undefined;
|
|
2088
|
+
allowedTools?: string[] | undefined;
|
|
2089
|
+
}[] | undefined>;
|
|
2090
|
+
files: ReducedValue<FilesRecord | undefined, FilesRecordUpdate | undefined>;
|
|
2091
|
+
}>, undefined, unknown, readonly (_$_langchain_core_tools0.ClientTool | _$_langchain_core_tools0.ServerTool)[]>;
|
|
2092
|
+
//#endregion
|
|
2093
|
+
//#region src/middleware/completion_callback.d.ts
|
|
2094
|
+
/**
|
|
2095
|
+
* Options for creating the completion callback middleware.
|
|
2096
|
+
*/
|
|
2097
|
+
interface CompletionCallbackOptions {
|
|
1784
2098
|
/**
|
|
1785
|
-
*
|
|
1786
|
-
*
|
|
1787
|
-
* Uses pure POSIX shell (find + stat) via execute() to list all files,
|
|
1788
|
-
* then applies glob-to-regex matching in TypeScript. No Python or Node.js
|
|
1789
|
-
* needed on the sandbox host.
|
|
1790
|
-
*
|
|
1791
|
-
* Glob patterns are matched against paths relative to the search base:
|
|
1792
|
-
* - `*` matches any characters except `/`
|
|
1793
|
-
* - `**` matches any characters including `/` (recursive)
|
|
1794
|
-
* - `?` matches a single character except `/`
|
|
1795
|
-
* - `[...]` character classes
|
|
2099
|
+
* Callback graph or assistant identifier. Used as the `assistant_id`
|
|
2100
|
+
* argument in `runs.create()`.
|
|
1796
2101
|
*/
|
|
1797
|
-
|
|
2102
|
+
callbackGraphId: string;
|
|
1798
2103
|
/**
|
|
1799
|
-
*
|
|
1800
|
-
*
|
|
1801
|
-
* Uses downloadFiles() to check existence and uploadFiles() to write.
|
|
1802
|
-
* No runtime needed on the sandbox host.
|
|
2104
|
+
* URL of the callback LangGraph server. Omit to use same-deployment
|
|
2105
|
+
* ASGI transport.
|
|
1803
2106
|
*/
|
|
1804
|
-
|
|
2107
|
+
url?: string;
|
|
1805
2108
|
/**
|
|
1806
|
-
*
|
|
1807
|
-
*
|
|
1808
|
-
* Uses downloadFiles() to read, performs string replacement in TypeScript,
|
|
1809
|
-
* then uploadFiles() to write back. No runtime needed on the sandbox host.
|
|
1810
|
-
*
|
|
1811
|
-
* Memory-conscious: releases intermediate references early so the GC can
|
|
1812
|
-
* reclaim buffers before the next large allocation is made.
|
|
2109
|
+
* Additional headers to include in requests to the callback server.
|
|
1813
2110
|
*/
|
|
1814
|
-
|
|
2111
|
+
headers?: Record<string, string>;
|
|
1815
2112
|
}
|
|
2113
|
+
/**
|
|
2114
|
+
* Create a completion callback middleware for async subagents.
|
|
2115
|
+
*
|
|
2116
|
+
* **Experimental** — this middleware is experimental and may change.
|
|
2117
|
+
*
|
|
2118
|
+
* This middleware is added to a subagent's middleware stack. On success or
|
|
2119
|
+
* model-call error, it sends a notification to the configured callback
|
|
2120
|
+
* thread by calling `runs.create()`.
|
|
2121
|
+
*
|
|
2122
|
+
* The callback destination is configured with `callbackGraphId` and
|
|
2123
|
+
* optional `url` and `headers`. The target thread is read from
|
|
2124
|
+
* `callbackThreadId` in the subagent state.
|
|
2125
|
+
*
|
|
2126
|
+
* If `callbackThreadId` is not present in state, the middleware does
|
|
2127
|
+
* nothing.
|
|
2128
|
+
*
|
|
2129
|
+
* @param options - Configuration options.
|
|
2130
|
+
* @returns An `AgentMiddleware` instance.
|
|
2131
|
+
*
|
|
2132
|
+
* @example
|
|
2133
|
+
* ```typescript
|
|
2134
|
+
* import { createCompletionCallbackMiddleware } from "deepagents";
|
|
2135
|
+
*
|
|
2136
|
+
* const notifier = createCompletionCallbackMiddleware({
|
|
2137
|
+
* callbackGraphId: "supervisor",
|
|
2138
|
+
* });
|
|
2139
|
+
*
|
|
2140
|
+
* const agent = createDeepAgent({
|
|
2141
|
+
* model: "claude-sonnet-4-5-20250929",
|
|
2142
|
+
* middleware: [notifier],
|
|
2143
|
+
* });
|
|
2144
|
+
* ```
|
|
2145
|
+
*/
|
|
2146
|
+
declare function createCompletionCallbackMiddleware(options: CompletionCallbackOptions): AgentMiddleware<z$2.ZodObject<{
|
|
2147
|
+
callbackThreadId: z$2.ZodOptional<z$2.ZodString>;
|
|
2148
|
+
}, z$2.core.$strip>, undefined, unknown, readonly (_$_langchain_core_tools0.ClientTool | _$_langchain_core_tools0.ServerTool)[]>;
|
|
1816
2149
|
//#endregion
|
|
1817
|
-
//#region src/
|
|
1818
|
-
/**
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
2150
|
+
//#region src/middleware/summarization.d.ts
|
|
2151
|
+
/**
|
|
2152
|
+
* Context size specification for summarization triggers and retention policies.
|
|
2153
|
+
*/
|
|
2154
|
+
interface ContextSize {
|
|
2155
|
+
/** Type of context measurement */
|
|
2156
|
+
type: "messages" | "tokens" | "fraction";
|
|
2157
|
+
/** Threshold value */
|
|
2158
|
+
value: number;
|
|
2159
|
+
}
|
|
2160
|
+
/**
|
|
2161
|
+
* Settings for truncating large tool arguments in old messages.
|
|
2162
|
+
*/
|
|
2163
|
+
interface TruncateArgsSettings {
|
|
1822
2164
|
/**
|
|
1823
|
-
*
|
|
1824
|
-
*
|
|
2165
|
+
* Threshold to trigger argument truncation.
|
|
2166
|
+
* If not provided, truncation is disabled.
|
|
1825
2167
|
*/
|
|
1826
|
-
|
|
1827
|
-
}
|
|
1828
|
-
/** Options for the `LangSmithSandbox.create()` static factory. */
|
|
1829
|
-
interface LangSmithSandboxCreateOptions extends Omit<CreateSandboxOptions, "name" | "timeout" | "waitForReady"> {
|
|
2168
|
+
trigger?: ContextSize;
|
|
1830
2169
|
/**
|
|
1831
|
-
*
|
|
1832
|
-
*
|
|
2170
|
+
* Context retention policy for message truncation.
|
|
2171
|
+
* Defaults to keeping last 20 messages.
|
|
1833
2172
|
*/
|
|
1834
|
-
|
|
2173
|
+
keep?: ContextSize;
|
|
1835
2174
|
/**
|
|
1836
|
-
*
|
|
2175
|
+
* Maximum character length for tool arguments before truncation.
|
|
2176
|
+
* Defaults to 2000.
|
|
1837
2177
|
*/
|
|
1838
|
-
|
|
2178
|
+
maxLength?: number;
|
|
1839
2179
|
/**
|
|
1840
|
-
*
|
|
1841
|
-
*
|
|
2180
|
+
* Text to replace truncated arguments with.
|
|
2181
|
+
* Defaults to "...(argument truncated)".
|
|
1842
2182
|
*/
|
|
1843
|
-
|
|
2183
|
+
truncationText?: string;
|
|
1844
2184
|
}
|
|
1845
2185
|
/**
|
|
1846
|
-
*
|
|
1847
|
-
*
|
|
1848
|
-
* Extends `BaseSandbox` to provide command execution and file operations
|
|
1849
|
-
* via the LangSmith Sandbox API.
|
|
1850
|
-
*
|
|
1851
|
-
* Use the static `LangSmithSandbox.create()` factory for the simplest setup,
|
|
1852
|
-
* or construct directly with an existing `Sandbox` instance.
|
|
2186
|
+
* Options for the summarization middleware.
|
|
1853
2187
|
*/
|
|
1854
|
-
|
|
1855
|
-
#private;
|
|
1856
|
-
constructor(options: LangSmithSandboxOptions);
|
|
1857
|
-
/** Whether the sandbox is currently active. */
|
|
1858
|
-
get isRunning(): boolean;
|
|
1859
|
-
/** Return the LangSmith sandbox name as the unique identifier. */
|
|
1860
|
-
get id(): string;
|
|
2188
|
+
interface SummarizationMiddlewareOptions {
|
|
1861
2189
|
/**
|
|
1862
|
-
*
|
|
1863
|
-
*
|
|
1864
|
-
* @param command - Shell command string to execute
|
|
1865
|
-
* @param options.timeout - Override timeout in seconds; 0 disables timeout
|
|
2190
|
+
* The language model to use for generating summaries.
|
|
2191
|
+
* Can be a model string (e.g., "gpt-4o-mini") or a language model instance.
|
|
1866
2192
|
*/
|
|
1867
|
-
|
|
1868
|
-
timeout?: number;
|
|
1869
|
-
}): Promise<ExecuteResponse>;
|
|
2193
|
+
model: string | BaseChatModel | BaseLanguageModel;
|
|
1870
2194
|
/**
|
|
1871
|
-
*
|
|
1872
|
-
* @param paths - List of file paths to download
|
|
1873
|
-
* @returns List of FileDownloadResponse objects, one per input path
|
|
2195
|
+
* Backend instance or factory for persisting conversation history.
|
|
1874
2196
|
*/
|
|
1875
|
-
|
|
2197
|
+
backend: AnyBackendProtocol | BackendFactory | ((config: {
|
|
2198
|
+
state: unknown;
|
|
2199
|
+
store?: BaseStore;
|
|
2200
|
+
}) => StateBackend);
|
|
1876
2201
|
/**
|
|
1877
|
-
*
|
|
1878
|
-
*
|
|
1879
|
-
* @returns List of FileUploadResponse objects, one per input file
|
|
2202
|
+
* Threshold(s) that trigger summarization.
|
|
2203
|
+
* Can be a single ContextSize or an array for multiple triggers.
|
|
1880
2204
|
*/
|
|
1881
|
-
|
|
2205
|
+
trigger?: ContextSize | ContextSize[];
|
|
1882
2206
|
/**
|
|
1883
|
-
*
|
|
1884
|
-
*
|
|
1885
|
-
* After calling this, `isRunning` will be `false` and the sandbox
|
|
1886
|
-
* cannot be used again.
|
|
2207
|
+
* Context retention policy after summarization.
|
|
2208
|
+
* Defaults to keeping last 20 messages.
|
|
1887
2209
|
*/
|
|
1888
|
-
|
|
2210
|
+
keep?: ContextSize;
|
|
1889
2211
|
/**
|
|
1890
|
-
*
|
|
1891
|
-
*
|
|
1892
|
-
* This is the recommended way to create a sandbox — no need to import
|
|
1893
|
-
* anything from `langsmith/experimental/sandbox` directly.
|
|
1894
|
-
*
|
|
1895
|
-
* @example
|
|
1896
|
-
* ```typescript
|
|
1897
|
-
* const sandbox = await LangSmithSandbox.create({ templateName: "deepagents" });
|
|
1898
|
-
* try {
|
|
1899
|
-
* const agent = createDeepAgent({ model, backend: sandbox });
|
|
1900
|
-
* await agent.invoke({ messages: [...] });
|
|
1901
|
-
* } finally {
|
|
1902
|
-
* await sandbox.close();
|
|
1903
|
-
* }
|
|
1904
|
-
* ```
|
|
2212
|
+
* Prompt template for generating summaries.
|
|
1905
2213
|
*/
|
|
1906
|
-
|
|
2214
|
+
summaryPrompt?: string;
|
|
2215
|
+
/**
|
|
2216
|
+
* Max tokens to include when generating summary.
|
|
2217
|
+
* Defaults to 4000.
|
|
2218
|
+
*/
|
|
2219
|
+
trimTokensToSummarize?: number;
|
|
2220
|
+
/**
|
|
2221
|
+
* Path prefix for storing conversation history.
|
|
2222
|
+
* Defaults to "/conversation_history".
|
|
2223
|
+
*/
|
|
2224
|
+
historyPathPrefix?: string;
|
|
2225
|
+
/**
|
|
2226
|
+
* Settings for truncating large tool arguments in old messages.
|
|
2227
|
+
* If not provided, argument truncation is disabled.
|
|
2228
|
+
*/
|
|
2229
|
+
truncateArgsSettings?: TruncateArgsSettings;
|
|
2230
|
+
}
|
|
2231
|
+
/**
|
|
2232
|
+
* Compute summarization defaults based on model profile.
|
|
2233
|
+
* Mirrors Python's `_compute_summarization_defaults`.
|
|
2234
|
+
*
|
|
2235
|
+
* If the model has a profile with `maxInputTokens`, uses fraction-based
|
|
2236
|
+
* settings. Otherwise, uses fixed token/message counts.
|
|
2237
|
+
*
|
|
2238
|
+
* @param resolvedModel - The resolved chat model instance.
|
|
2239
|
+
*/
|
|
2240
|
+
declare function computeSummarizationDefaults(resolvedModel: BaseChatModel): {
|
|
2241
|
+
trigger: ContextSize;
|
|
2242
|
+
keep: ContextSize;
|
|
2243
|
+
truncateArgsSettings: TruncateArgsSettings;
|
|
2244
|
+
};
|
|
2245
|
+
/**
|
|
2246
|
+
* Create summarization middleware with backend support for conversation history offloading.
|
|
2247
|
+
*
|
|
2248
|
+
* This middleware:
|
|
2249
|
+
* 1. Monitors conversation length against configured thresholds
|
|
2250
|
+
* 2. When triggered, offloads old messages to backend storage
|
|
2251
|
+
* 3. Generates a summary of offloaded messages
|
|
2252
|
+
* 4. Replaces old messages with the summary, preserving recent context
|
|
2253
|
+
*
|
|
2254
|
+
* @param options - Configuration options
|
|
2255
|
+
* @returns AgentMiddleware for summarization and history offloading
|
|
2256
|
+
*/
|
|
2257
|
+
declare function createSummarizationMiddleware(options: SummarizationMiddlewareOptions): AgentMiddleware<z$1.ZodObject<{
|
|
2258
|
+
_summarizationSessionId: z$1.ZodOptional<z$1.ZodString>;
|
|
2259
|
+
_summarizationEvent: z$1.ZodOptional<z$1.ZodObject<{
|
|
2260
|
+
cutoffIndex: z$1.ZodNumber;
|
|
2261
|
+
summaryMessage: z$1.ZodCustom<HumanMessage<_messages.MessageStructure<_messages.MessageToolSet>>, HumanMessage<_messages.MessageStructure<_messages.MessageToolSet>>>;
|
|
2262
|
+
filePath: z$1.ZodNullable<z$1.ZodString>;
|
|
2263
|
+
}, z$1.core.$strip>>;
|
|
2264
|
+
}, z$1.core.$strip>, undefined, unknown, readonly (ClientTool | ServerTool)[]>;
|
|
2265
|
+
//#endregion
|
|
2266
|
+
//#region src/middleware/async_subagents.d.ts
|
|
2267
|
+
/**
|
|
2268
|
+
* Specification for an async subagent running on a remote [Agent Protocol](https://github.com/langchain-ai/agent-protocol)
|
|
2269
|
+
* server.
|
|
2270
|
+
*
|
|
2271
|
+
* Async subagents connect to any Agent Protocol-compliant server via the
|
|
2272
|
+
* LangGraph SDK. They run as background tasks that the main agent can
|
|
2273
|
+
* monitor and update.
|
|
2274
|
+
*
|
|
2275
|
+
* Compatible with LangGraph Platform (managed) and self-hosted servers.
|
|
2276
|
+
* Authentication for LangGraph Platform is handled automatically by the SDK
|
|
2277
|
+
* via environment variables (`LANGGRAPH_API_KEY`, `LANGSMITH_API_KEY`, or
|
|
2278
|
+
* `LANGCHAIN_API_KEY`). For self-hosted servers, pass custom auth via `headers`.
|
|
2279
|
+
*/
|
|
2280
|
+
interface AsyncSubAgent {
|
|
2281
|
+
/** Unique identifier for the async subagent. */
|
|
2282
|
+
name: string;
|
|
2283
|
+
/** What this subagent does. The main agent uses this to decide when to delegate. */
|
|
2284
|
+
description: string;
|
|
2285
|
+
/** The graph name or assistant ID on the Agent Protocol server. */
|
|
2286
|
+
graphId: string;
|
|
2287
|
+
/** URL of the Agent Protocol server. Defaults to the LangGraph SDK's default endpoint. */
|
|
2288
|
+
url?: string;
|
|
2289
|
+
/** Additional headers to include in requests to the server (e.g. for custom auth). */
|
|
2290
|
+
headers?: Record<string, string>;
|
|
2291
|
+
}
|
|
2292
|
+
/**
|
|
2293
|
+
* Possible statuses for an async subagent task.
|
|
2294
|
+
*
|
|
2295
|
+
* Statuses set by the middleware tools: `"running"`, `"success"`, `"error"`, `"cancelled"`.
|
|
2296
|
+
* Statuses that may be returned by the remote server: `"pending"`, `"timeout"`, `"interrupted"`.
|
|
2297
|
+
*/
|
|
2298
|
+
type AsyncTaskStatus = "pending" | "running" | "success" | "error" | "cancelled" | "timeout" | "interrupted";
|
|
2299
|
+
/**
|
|
2300
|
+
* A tracked async subagent task persisted in agent state.
|
|
2301
|
+
*
|
|
2302
|
+
* Each task maps to a single thread + run on a remote Agent Protocol server.
|
|
2303
|
+
* The `taskId` is the same as `threadId`, so it can be used to look up
|
|
2304
|
+
* the thread directly via the SDK.
|
|
2305
|
+
*/
|
|
2306
|
+
interface AsyncTask {
|
|
2307
|
+
/** Unique identifier for the task (same as thread id). */
|
|
2308
|
+
taskId: string;
|
|
2309
|
+
/** Name of the async subagent type that is running. */
|
|
2310
|
+
agentName: string;
|
|
2311
|
+
/** Thread ID on the remote server. */
|
|
2312
|
+
threadId: string;
|
|
2313
|
+
/** Run ID for the current execution on the thread. */
|
|
2314
|
+
runId: string;
|
|
2315
|
+
/** Current task status. */
|
|
2316
|
+
status: AsyncTaskStatus;
|
|
2317
|
+
/** ISO timestamp of when the task was launched. */
|
|
2318
|
+
createdAt: string;
|
|
2319
|
+
/** The prompt/description passed to the subagent when the task was launched. */
|
|
2320
|
+
description?: string;
|
|
2321
|
+
/** ISO timestamp of the most recent task update — set when the task status changes or a follow-up message is sent via the update tool. */
|
|
2322
|
+
updatedAt?: string;
|
|
2323
|
+
/** ISO timestamp of the most recent status poll via the check tool. */
|
|
2324
|
+
checkedAt?: string;
|
|
2325
|
+
}
|
|
2326
|
+
/**
|
|
2327
|
+
* Options for creating async subagent middleware.
|
|
2328
|
+
*/
|
|
2329
|
+
interface AsyncSubAgentMiddlewareOptions {
|
|
2330
|
+
/** List of async subagent specifications. Must have at least one. */
|
|
2331
|
+
asyncSubAgents: AsyncSubAgent[];
|
|
2332
|
+
/** System prompt override. Set to `null` to disable. Defaults to {@link ASYNC_TASK_SYSTEM_PROMPT}. */
|
|
2333
|
+
systemPrompt?: string;
|
|
1907
2334
|
}
|
|
2335
|
+
/**
|
|
2336
|
+
* Create middleware that adds async subagent tools to an agent.
|
|
2337
|
+
*
|
|
2338
|
+
* Provides five tools for launching, checking, updating, cancelling, and
|
|
2339
|
+
* listing background tasks on remote Agent Protocol servers. Task state is
|
|
2340
|
+
* persisted in the `asyncTasks` state channel so it survives
|
|
2341
|
+
* context compaction.
|
|
2342
|
+
*
|
|
2343
|
+
* Works with any Agent Protocol-compliant server — LangGraph Platform (managed)
|
|
2344
|
+
* or self-hosted (e.g. a Hono/Express server implementing the Agent Protocol spec).
|
|
2345
|
+
*
|
|
2346
|
+
* @throws {Error} If no async subagents are provided or names are duplicated.
|
|
2347
|
+
*
|
|
2348
|
+
* @example
|
|
2349
|
+
* ```ts
|
|
2350
|
+
* const middleware = createAsyncSubAgentMiddleware({
|
|
2351
|
+
* asyncSubAgents: [{
|
|
2352
|
+
* name: "researcher",
|
|
2353
|
+
* description: "Research agent for deep analysis",
|
|
2354
|
+
* url: "https://my-agent-protocol-server.example.com",
|
|
2355
|
+
* graphId: "research_agent",
|
|
2356
|
+
* }],
|
|
2357
|
+
* });
|
|
2358
|
+
* ```
|
|
2359
|
+
*/
|
|
2360
|
+
/**
|
|
2361
|
+
* Type guard to distinguish async SubAgents from sync SubAgents/CompiledSubAgents.
|
|
2362
|
+
*
|
|
2363
|
+
* Uses the presence of the `graphId` field as the runtime discriminant —
|
|
2364
|
+
* `AsyncSubAgent` requires it, while `SubAgent` and `CompiledSubAgent` do not have it.
|
|
2365
|
+
*/
|
|
2366
|
+
declare function isAsyncSubAgent(subAgent: AnySubAgent): subAgent is AsyncSubAgent;
|
|
2367
|
+
declare function createAsyncSubAgentMiddleware(options: AsyncSubAgentMiddlewareOptions): _langchain.AgentMiddleware<StateSchema<{
|
|
2368
|
+
asyncTasks: ReducedValue<Record<string, {
|
|
2369
|
+
taskId: string;
|
|
2370
|
+
agentName: string;
|
|
2371
|
+
threadId: string;
|
|
2372
|
+
runId: string;
|
|
2373
|
+
status: string;
|
|
2374
|
+
createdAt: string;
|
|
2375
|
+
description?: string | undefined;
|
|
2376
|
+
updatedAt?: string | undefined;
|
|
2377
|
+
checkedAt?: string | undefined;
|
|
2378
|
+
}> | undefined, Record<string, {
|
|
2379
|
+
taskId: string;
|
|
2380
|
+
agentName: string;
|
|
2381
|
+
threadId: string;
|
|
2382
|
+
runId: string;
|
|
2383
|
+
status: string;
|
|
2384
|
+
createdAt: string;
|
|
2385
|
+
description?: string | undefined;
|
|
2386
|
+
updatedAt?: string | undefined;
|
|
2387
|
+
checkedAt?: string | undefined;
|
|
2388
|
+
}> | undefined>;
|
|
2389
|
+
}>, undefined, unknown, (_langchain.DynamicStructuredTool<z.ZodObject<{
|
|
2390
|
+
description: z.ZodString;
|
|
2391
|
+
agentName: z.ZodString;
|
|
2392
|
+
}, z.core.$strip>, {
|
|
2393
|
+
description: string;
|
|
2394
|
+
agentName: string;
|
|
2395
|
+
}, {
|
|
2396
|
+
description: string;
|
|
2397
|
+
agentName: string;
|
|
2398
|
+
}, string | Command<unknown, Record<string, unknown>, string>, unknown, "start_async_task"> | _langchain.DynamicStructuredTool<z.ZodObject<{
|
|
2399
|
+
taskId: z.ZodString;
|
|
2400
|
+
}, z.core.$strip>, {
|
|
2401
|
+
taskId: string;
|
|
2402
|
+
}, {
|
|
2403
|
+
taskId: string;
|
|
2404
|
+
}, string | Command<unknown, Record<string, unknown>, string>, unknown, "check_async_task"> | _langchain.DynamicStructuredTool<z.ZodObject<{
|
|
2405
|
+
taskId: z.ZodString;
|
|
2406
|
+
message: z.ZodString;
|
|
2407
|
+
}, z.core.$strip>, {
|
|
2408
|
+
taskId: string;
|
|
2409
|
+
message: string;
|
|
2410
|
+
}, {
|
|
2411
|
+
taskId: string;
|
|
2412
|
+
message: string;
|
|
2413
|
+
}, string | Command<unknown, Record<string, unknown>, string>, unknown, "update_async_task"> | _langchain.DynamicStructuredTool<z.ZodObject<{
|
|
2414
|
+
taskId: z.ZodString;
|
|
2415
|
+
}, z.core.$strip>, {
|
|
2416
|
+
taskId: string;
|
|
2417
|
+
}, {
|
|
2418
|
+
taskId: string;
|
|
2419
|
+
}, string | Command<unknown, Record<string, unknown>, string>, unknown, "cancel_async_task"> | _langchain.DynamicStructuredTool<z.ZodObject<{
|
|
2420
|
+
statusFilter: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
2421
|
+
}, z.core.$strip>, {
|
|
2422
|
+
statusFilter?: string | null | undefined;
|
|
2423
|
+
}, {
|
|
2424
|
+
statusFilter?: string | null | undefined;
|
|
2425
|
+
}, string | Command<unknown, Record<string, unknown>, string>, unknown, "list_async_tasks">)[]>;
|
|
1908
2426
|
//#endregion
|
|
1909
2427
|
//#region src/types.d.ts
|
|
1910
2428
|
type AnyAnnotationRoot = AnnotationRoot<any>;
|
|
2429
|
+
/** Any subagent specification — sync, compiled, or async. */
|
|
2430
|
+
type AnySubAgent = SubAgent | CompiledSubAgent | AsyncSubAgent;
|
|
1911
2431
|
interface TypedToolStrategy<T = unknown> extends Array<ToolStrategy<any>> {
|
|
1912
2432
|
_schemaType?: T;
|
|
1913
2433
|
}
|
|
@@ -1921,15 +2441,15 @@ type ExtractSubAgentMiddleware<T> = T extends {
|
|
|
1921
2441
|
/**
|
|
1922
2442
|
* Helper type to flatten and merge middleware from all subagents
|
|
1923
2443
|
*/
|
|
1924
|
-
type FlattenSubAgentMiddleware<T extends readonly
|
|
2444
|
+
type FlattenSubAgentMiddleware<T extends readonly AnySubAgent[]> = T extends readonly [] ? readonly [] : T extends readonly [infer First, ...infer Rest] ? Rest extends readonly AnySubAgent[] ? readonly [...ExtractSubAgentMiddleware<First>, ...FlattenSubAgentMiddleware<Rest>] : ExtractSubAgentMiddleware<First> : readonly [];
|
|
1925
2445
|
/**
|
|
1926
2446
|
* Helper type to merge states from subagent middleware
|
|
1927
2447
|
*/
|
|
1928
|
-
type InferSubAgentMiddlewareStates<T extends readonly
|
|
2448
|
+
type InferSubAgentMiddlewareStates<T extends readonly AnySubAgent[]> = InferMiddlewareStates<FlattenSubAgentMiddleware<T>>;
|
|
1929
2449
|
/**
|
|
1930
2450
|
* Combined state type including custom middleware and subagent middleware states
|
|
1931
2451
|
*/
|
|
1932
|
-
type MergedDeepAgentState<TMiddleware extends readonly AgentMiddleware[], TSubagents extends readonly
|
|
2452
|
+
type MergedDeepAgentState<TMiddleware extends readonly AgentMiddleware[], TSubagents extends readonly AnySubAgent[]> = InferMiddlewareStates<TMiddleware> & InferSubAgentMiddlewareStates<TSubagents>;
|
|
1933
2453
|
/**
|
|
1934
2454
|
* Union of all response format types accepted by `createDeepAgent`.
|
|
1935
2455
|
*
|
|
@@ -1986,7 +2506,7 @@ type InferStructuredResponse<T extends SupportedResponseFormat> = SupportedRespo
|
|
|
1986
2506
|
* type Types = InferDeepAgentType<typeof agent, "Subagents">;
|
|
1987
2507
|
* ```
|
|
1988
2508
|
*/
|
|
1989
|
-
interface DeepAgentTypeConfig<TResponse extends Record<string, any> | ResponseFormatUndefined = Record<string, any> | ResponseFormatUndefined, TState extends AnyAnnotationRoot | InteropZodObject | undefined = AnyAnnotationRoot | InteropZodObject | undefined, TContext extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot | InteropZodObject, TMiddleware extends readonly AgentMiddleware[] = readonly AgentMiddleware[], TTools extends readonly (ClientTool | ServerTool)[] = readonly (ClientTool | ServerTool)[], TSubagents extends readonly
|
|
2509
|
+
interface DeepAgentTypeConfig<TResponse extends Record<string, any> | ResponseFormatUndefined = Record<string, any> | ResponseFormatUndefined, TState extends AnyAnnotationRoot | InteropZodObject | undefined = AnyAnnotationRoot | InteropZodObject | undefined, TContext extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot | InteropZodObject, TMiddleware extends readonly AgentMiddleware[] = readonly AgentMiddleware[], TTools extends readonly (ClientTool | ServerTool)[] = readonly (ClientTool | ServerTool)[], TSubagents extends readonly AnySubAgent[] = readonly AnySubAgent[]> extends AgentTypeConfig<TResponse, TState, TContext, TMiddleware, TTools> {
|
|
1990
2510
|
/** The subagents array type for type-safe streaming */
|
|
1991
2511
|
Subagents: TSubagents;
|
|
1992
2512
|
}
|
|
@@ -2000,7 +2520,7 @@ interface DefaultDeepAgentTypeConfig extends DeepAgentTypeConfig {
|
|
|
2000
2520
|
Context: AnyAnnotationRoot;
|
|
2001
2521
|
Middleware: readonly AgentMiddleware[];
|
|
2002
2522
|
Tools: readonly (ClientTool | ServerTool)[];
|
|
2003
|
-
Subagents: readonly
|
|
2523
|
+
Subagents: readonly AnySubAgent[];
|
|
2004
2524
|
}
|
|
2005
2525
|
/**
|
|
2006
2526
|
* DeepAgent extends ReactAgent with additional subagent type information.
|
|
@@ -2101,7 +2621,7 @@ type InferSubagentReactAgentType<TSubagent extends SubAgent | CompiledSubAgent>
|
|
|
2101
2621
|
* @typeParam TSubagents - The subagents array type for extracting subagent middleware states
|
|
2102
2622
|
* @typeParam TTools - The tools array type
|
|
2103
2623
|
*/
|
|
2104
|
-
interface CreateDeepAgentParams<TResponse extends SupportedResponseFormat = SupportedResponseFormat, ContextSchema extends AnnotationRoot<any> | InteropZodObject = AnnotationRoot<any>, TMiddleware extends readonly AgentMiddleware[] = readonly AgentMiddleware[], TSubagents extends readonly
|
|
2624
|
+
interface CreateDeepAgentParams<TResponse extends SupportedResponseFormat = SupportedResponseFormat, ContextSchema extends AnnotationRoot<any> | InteropZodObject = AnnotationRoot<any>, TMiddleware extends readonly AgentMiddleware[] = readonly AgentMiddleware[], TSubagents extends readonly AnySubAgent[] = readonly AnySubAgent[], TTools extends readonly (ClientTool | ServerTool)[] = readonly (ClientTool | ServerTool)[]> {
|
|
2105
2625
|
/** The model to use (model name string or LanguageModelLike instance). Defaults to claude-sonnet-4-5-20250929 */
|
|
2106
2626
|
model?: BaseLanguageModel | string;
|
|
2107
2627
|
/** Tools the agent should have access to */
|
|
@@ -2110,7 +2630,13 @@ interface CreateDeepAgentParams<TResponse extends SupportedResponseFormat = Supp
|
|
|
2110
2630
|
systemPrompt?: string | SystemMessage;
|
|
2111
2631
|
/** Custom middleware to apply after standard middleware */
|
|
2112
2632
|
middleware?: TMiddleware;
|
|
2113
|
-
/**
|
|
2633
|
+
/**
|
|
2634
|
+
* List of subagent specifications for task delegation.
|
|
2635
|
+
*
|
|
2636
|
+
* Supports sync SubAgents, CompiledSubAgents, and AsyncSubAgents in the same array.
|
|
2637
|
+
* AsyncSubAgents (identified by their `graphId` field) are automatically separated
|
|
2638
|
+
* at runtime and wired to the async SubAgent middleware.
|
|
2639
|
+
*/
|
|
2114
2640
|
subagents?: TSubagents;
|
|
2115
2641
|
/** Structured output response format for the agent (Zod schema or other format) */
|
|
2116
2642
|
responseFormat?: TResponse;
|
|
@@ -2125,10 +2651,10 @@ interface CreateDeepAgentParams<TResponse extends SupportedResponseFormat = Supp
|
|
|
2125
2651
|
* Can be either a backend instance or a factory function that creates one.
|
|
2126
2652
|
* The factory receives a config object with state and store.
|
|
2127
2653
|
*/
|
|
2128
|
-
backend?:
|
|
2654
|
+
backend?: AnyBackendProtocol | ((config: {
|
|
2129
2655
|
state: unknown;
|
|
2130
2656
|
store?: BaseStore;
|
|
2131
|
-
}) =>
|
|
2657
|
+
}) => AnyBackendProtocol);
|
|
2132
2658
|
/** Optional interrupt configuration mapping tool names to interrupt configs */
|
|
2133
2659
|
interruptOn?: Record<string, boolean | InterruptOnConfig>;
|
|
2134
2660
|
/** The name of the agent */
|
|
@@ -2175,19 +2701,18 @@ interface CreateDeepAgentParams<TResponse extends SupportedResponseFormat = Supp
|
|
|
2175
2701
|
//#endregion
|
|
2176
2702
|
//#region src/agent.d.ts
|
|
2177
2703
|
/**
|
|
2178
|
-
* Create a Deep Agent
|
|
2704
|
+
* Create a Deep Agent.
|
|
2179
2705
|
*
|
|
2180
|
-
*
|
|
2181
|
-
*
|
|
2182
|
-
*
|
|
2183
|
-
* -
|
|
2184
|
-
*
|
|
2185
|
-
*
|
|
2186
|
-
*
|
|
2187
|
-
* - Human-in-the-loop (humanInTheLoopMiddleware) - optional
|
|
2706
|
+
* This is the main entry point for building a production-style agent with
|
|
2707
|
+
* deepagents. It gives you a strong default runtime (filesystem, tasks,
|
|
2708
|
+
* subagents, summarization) and lets you opt into skills, memory,
|
|
2709
|
+
* human-in-the-loop interrupts, async subagents, and custom middleware.
|
|
2710
|
+
*
|
|
2711
|
+
* The runtime is intentionally opinionated: defaults work out of the box, and
|
|
2712
|
+
* when you customize behavior, the middleware ordering stays deterministic.
|
|
2188
2713
|
*
|
|
2189
2714
|
* @param params Configuration parameters for the agent
|
|
2190
|
-
* @returns
|
|
2715
|
+
* @returns Deep Agent instance with inferred state/response types
|
|
2191
2716
|
*
|
|
2192
2717
|
* @example
|
|
2193
2718
|
* ```typescript
|
|
@@ -2205,18 +2730,18 @@ interface CreateDeepAgentParams<TResponse extends SupportedResponseFormat = Supp
|
|
|
2205
2730
|
* // result.research is properly typed as string
|
|
2206
2731
|
* ```
|
|
2207
2732
|
*/
|
|
2208
|
-
declare function createDeepAgent<TResponse extends SupportedResponseFormat = SupportedResponseFormat, ContextSchema extends InteropZodObject = InteropZodObject, const TMiddleware extends readonly AgentMiddleware[] = readonly [], const TSubagents extends readonly
|
|
2209
|
-
todos: zod_v30.ZodDefault<zod_v30.ZodArray<zod_v30.ZodObject<{
|
|
2210
|
-
content: zod_v30.ZodString;
|
|
2211
|
-
status: zod_v30.ZodEnum<["pending", "in_progress", "completed"]>;
|
|
2212
|
-
}, "strip", zod_v30.ZodTypeAny, {
|
|
2733
|
+
declare function createDeepAgent<TResponse extends SupportedResponseFormat = SupportedResponseFormat, ContextSchema extends InteropZodObject = InteropZodObject, const TMiddleware extends readonly AgentMiddleware[] = readonly [], const TSubagents extends readonly AnySubAgent[] = readonly [], const TTools extends readonly (ClientTool | ServerTool)[] = readonly []>(params?: CreateDeepAgentParams<TResponse, ContextSchema, TMiddleware, TSubagents, TTools>): DeepAgent<DeepAgentTypeConfig<InferStructuredResponse<TResponse>, undefined, ContextSchema, readonly [AgentMiddleware<_$zod_v30.ZodObject<{
|
|
2734
|
+
todos: _$zod_v30.ZodDefault<_$zod_v30.ZodArray<_$zod_v30.ZodObject<{
|
|
2735
|
+
content: _$zod_v30.ZodString;
|
|
2736
|
+
status: _$zod_v30.ZodEnum<["pending", "in_progress", "completed"]>;
|
|
2737
|
+
}, "strip", _$zod_v30.ZodTypeAny, {
|
|
2213
2738
|
content: string;
|
|
2214
2739
|
status: "completed" | "in_progress" | "pending";
|
|
2215
2740
|
}, {
|
|
2216
2741
|
content: string;
|
|
2217
2742
|
status: "completed" | "in_progress" | "pending";
|
|
2218
2743
|
}>, "many">>;
|
|
2219
|
-
}, "strip", zod_v30.ZodTypeAny, {
|
|
2744
|
+
}, "strip", _$zod_v30.ZodTypeAny, {
|
|
2220
2745
|
todos: {
|
|
2221
2746
|
content: string;
|
|
2222
2747
|
status: "completed" | "in_progress" | "pending";
|
|
@@ -2226,18 +2751,18 @@ declare function createDeepAgent<TResponse extends SupportedResponseFormat = Sup
|
|
|
2226
2751
|
content: string;
|
|
2227
2752
|
status: "completed" | "in_progress" | "pending";
|
|
2228
2753
|
}[] | undefined;
|
|
2229
|
-
}>, undefined, unknown, readonly [_langchain.DynamicStructuredTool<zod_v30.ZodObject<{
|
|
2230
|
-
todos: zod_v30.ZodArray<zod_v30.ZodObject<{
|
|
2231
|
-
content: zod_v30.ZodString;
|
|
2232
|
-
status: zod_v30.ZodEnum<["pending", "in_progress", "completed"]>;
|
|
2233
|
-
}, "strip", zod_v30.ZodTypeAny, {
|
|
2754
|
+
}>, undefined, unknown, readonly [_langchain.DynamicStructuredTool<_$zod_v30.ZodObject<{
|
|
2755
|
+
todos: _$zod_v30.ZodArray<_$zod_v30.ZodObject<{
|
|
2756
|
+
content: _$zod_v30.ZodString;
|
|
2757
|
+
status: _$zod_v30.ZodEnum<["pending", "in_progress", "completed"]>;
|
|
2758
|
+
}, "strip", _$zod_v30.ZodTypeAny, {
|
|
2234
2759
|
content: string;
|
|
2235
2760
|
status: "completed" | "in_progress" | "pending";
|
|
2236
2761
|
}, {
|
|
2237
2762
|
content: string;
|
|
2238
2763
|
status: "completed" | "in_progress" | "pending";
|
|
2239
2764
|
}>, "many">;
|
|
2240
|
-
}, "strip", zod_v30.ZodTypeAny, {
|
|
2765
|
+
}, "strip", _$zod_v30.ZodTypeAny, {
|
|
2241
2766
|
todos: {
|
|
2242
2767
|
content: string;
|
|
2243
2768
|
status: "completed" | "in_progress" | "pending";
|
|
@@ -2265,17 +2790,17 @@ declare function createDeepAgent<TResponse extends SupportedResponseFormat = Sup
|
|
|
2265
2790
|
messages: _messages.ToolMessage<_messages.MessageStructure<_messages.MessageToolSet>>[];
|
|
2266
2791
|
}, string>, unknown, "write_todos">]>, AgentMiddleware<_langgraph.StateSchema<{
|
|
2267
2792
|
files: _langgraph.ReducedValue<FilesRecord | undefined, FilesRecordUpdate | undefined>;
|
|
2268
|
-
}>, undefined, unknown, (_langchain.DynamicStructuredTool<
|
|
2269
|
-
path:
|
|
2270
|
-
}, zod_v4_core0.$strip>, {
|
|
2793
|
+
}>, undefined, unknown, (_langchain.DynamicStructuredTool<z$2.ZodObject<{
|
|
2794
|
+
path: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodString>>;
|
|
2795
|
+
}, _$zod_v4_core0.$strip>, {
|
|
2271
2796
|
path: string;
|
|
2272
2797
|
}, {
|
|
2273
2798
|
path?: string | undefined;
|
|
2274
|
-
}, string, unknown, "ls"> | _langchain.DynamicStructuredTool<
|
|
2275
|
-
file_path:
|
|
2276
|
-
offset:
|
|
2277
|
-
limit:
|
|
2278
|
-
}, zod_v4_core0.$strip>, {
|
|
2799
|
+
}, string, unknown, "ls"> | _langchain.DynamicStructuredTool<z$2.ZodObject<{
|
|
2800
|
+
file_path: z$2.ZodString;
|
|
2801
|
+
offset: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodCoercedNumber<unknown>>>;
|
|
2802
|
+
limit: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodCoercedNumber<unknown>>>;
|
|
2803
|
+
}, _$zod_v4_core0.$strip>, {
|
|
2279
2804
|
file_path: string;
|
|
2280
2805
|
offset: number;
|
|
2281
2806
|
limit: number;
|
|
@@ -2283,10 +2808,17 @@ declare function createDeepAgent<TResponse extends SupportedResponseFormat = Sup
|
|
|
2283
2808
|
file_path: string;
|
|
2284
2809
|
offset?: unknown;
|
|
2285
2810
|
limit?: unknown;
|
|
2286
|
-
},
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
}
|
|
2811
|
+
}, {
|
|
2812
|
+
type: string;
|
|
2813
|
+
text: string;
|
|
2814
|
+
}[] | {
|
|
2815
|
+
type: string;
|
|
2816
|
+
mimeType: string;
|
|
2817
|
+
data: string;
|
|
2818
|
+
}[], unknown, "read_file"> | _langchain.DynamicStructuredTool<z$2.ZodObject<{
|
|
2819
|
+
file_path: z$2.ZodString;
|
|
2820
|
+
content: z$2.ZodDefault<z$2.ZodString>;
|
|
2821
|
+
}, _$zod_v4_core0.$strip>, {
|
|
2290
2822
|
file_path: string;
|
|
2291
2823
|
content: string;
|
|
2292
2824
|
}, {
|
|
@@ -2295,12 +2827,12 @@ declare function createDeepAgent<TResponse extends SupportedResponseFormat = Sup
|
|
|
2295
2827
|
}, string | _messages.ToolMessage<_messages.MessageStructure<_messages.MessageToolSet>> | _langgraph.Command<unknown, {
|
|
2296
2828
|
files: Record<string, FileData>;
|
|
2297
2829
|
messages: _messages.ToolMessage<_messages.MessageStructure<_messages.MessageToolSet>>[];
|
|
2298
|
-
}, string>, unknown, "write_file"> | _langchain.DynamicStructuredTool<
|
|
2299
|
-
file_path:
|
|
2300
|
-
old_string:
|
|
2301
|
-
new_string:
|
|
2302
|
-
replace_all:
|
|
2303
|
-
}, zod_v4_core0.$strip>, {
|
|
2830
|
+
}, string>, unknown, "write_file"> | _langchain.DynamicStructuredTool<z$2.ZodObject<{
|
|
2831
|
+
file_path: z$2.ZodString;
|
|
2832
|
+
old_string: z$2.ZodString;
|
|
2833
|
+
new_string: z$2.ZodString;
|
|
2834
|
+
replace_all: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodBoolean>>;
|
|
2835
|
+
}, _$zod_v4_core0.$strip>, {
|
|
2304
2836
|
file_path: string;
|
|
2305
2837
|
old_string: string;
|
|
2306
2838
|
new_string: string;
|
|
@@ -2313,50 +2845,50 @@ declare function createDeepAgent<TResponse extends SupportedResponseFormat = Sup
|
|
|
2313
2845
|
}, string | _messages.ToolMessage<_messages.MessageStructure<_messages.MessageToolSet>> | _langgraph.Command<unknown, {
|
|
2314
2846
|
files: Record<string, FileData>;
|
|
2315
2847
|
messages: _messages.ToolMessage<_messages.MessageStructure<_messages.MessageToolSet>>[];
|
|
2316
|
-
}, string>, unknown, "edit_file"> | _langchain.DynamicStructuredTool<
|
|
2317
|
-
pattern:
|
|
2318
|
-
path:
|
|
2319
|
-
}, zod_v4_core0.$strip>, {
|
|
2848
|
+
}, string>, unknown, "edit_file"> | _langchain.DynamicStructuredTool<z$2.ZodObject<{
|
|
2849
|
+
pattern: z$2.ZodString;
|
|
2850
|
+
path: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodString>>;
|
|
2851
|
+
}, _$zod_v4_core0.$strip>, {
|
|
2320
2852
|
pattern: string;
|
|
2321
2853
|
path: string;
|
|
2322
2854
|
}, {
|
|
2323
2855
|
pattern: string;
|
|
2324
2856
|
path?: string | undefined;
|
|
2325
|
-
}, string, unknown, "glob"> | _langchain.DynamicStructuredTool<
|
|
2326
|
-
pattern:
|
|
2327
|
-
path:
|
|
2328
|
-
glob:
|
|
2329
|
-
}, zod_v4_core0.$strip>, {
|
|
2857
|
+
}, string, unknown, "glob"> | _langchain.DynamicStructuredTool<z$2.ZodObject<{
|
|
2858
|
+
pattern: z$2.ZodString;
|
|
2859
|
+
path: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodString>>;
|
|
2860
|
+
glob: z$2.ZodDefault<z$2.ZodNullable<z$2.ZodOptional<z$2.ZodString>>>;
|
|
2861
|
+
}, _$zod_v4_core0.$strip>, {
|
|
2330
2862
|
pattern: string;
|
|
2331
2863
|
path: string;
|
|
2332
|
-
glob
|
|
2864
|
+
glob: string | null;
|
|
2333
2865
|
}, {
|
|
2334
2866
|
pattern: string;
|
|
2335
2867
|
path?: string | undefined;
|
|
2336
2868
|
glob?: string | null | undefined;
|
|
2337
|
-
}, string, unknown, "grep"> | _langchain.DynamicStructuredTool<
|
|
2338
|
-
command:
|
|
2339
|
-
}, zod_v4_core0.$strip>, {
|
|
2869
|
+
}, string, unknown, "grep"> | _langchain.DynamicStructuredTool<z$2.ZodObject<{
|
|
2870
|
+
command: z$2.ZodString;
|
|
2871
|
+
}, _$zod_v4_core0.$strip>, {
|
|
2340
2872
|
command: string;
|
|
2341
2873
|
}, {
|
|
2342
2874
|
command: string;
|
|
2343
|
-
}, string, unknown, "execute">)[]>, AgentMiddleware<undefined, undefined, unknown, readonly [_langchain.DynamicStructuredTool<
|
|
2344
|
-
description:
|
|
2345
|
-
subagent_type:
|
|
2346
|
-
}, zod_v4_core0.$strip>, {
|
|
2875
|
+
}, string, unknown, "execute">)[]>, AgentMiddleware<undefined, undefined, unknown, readonly [_langchain.DynamicStructuredTool<z$2.ZodObject<{
|
|
2876
|
+
description: z$2.ZodString;
|
|
2877
|
+
subagent_type: z$2.ZodString;
|
|
2878
|
+
}, _$zod_v4_core0.$strip>, {
|
|
2347
2879
|
description: string;
|
|
2348
2880
|
subagent_type: string;
|
|
2349
2881
|
}, {
|
|
2350
2882
|
description: string;
|
|
2351
2883
|
subagent_type: string;
|
|
2352
|
-
}, string | _langgraph.Command<unknown, Record<string, unknown>, string>, unknown, "task">]>, AgentMiddleware<
|
|
2353
|
-
_summarizationSessionId:
|
|
2354
|
-
_summarizationEvent:
|
|
2355
|
-
cutoffIndex:
|
|
2356
|
-
summaryMessage:
|
|
2357
|
-
filePath:
|
|
2358
|
-
}, zod_v4_core0.$strip>>;
|
|
2359
|
-
}, zod_v4_core0.$strip>, undefined, unknown, readonly (ClientTool | ServerTool)[]>, AgentMiddleware<undefined, undefined, unknown, readonly (ClientTool | ServerTool)[]>, ...TMiddleware, ...FlattenSubAgentMiddleware<TSubagents>], TTools, TSubagents>>;
|
|
2884
|
+
}, string | _langgraph.Command<unknown, Record<string, unknown>, string>, unknown, "task">]>, AgentMiddleware<z$2.ZodObject<{
|
|
2885
|
+
_summarizationSessionId: z$2.ZodOptional<z$2.ZodString>;
|
|
2886
|
+
_summarizationEvent: z$2.ZodOptional<z$2.ZodObject<{
|
|
2887
|
+
cutoffIndex: z$2.ZodNumber;
|
|
2888
|
+
summaryMessage: z$2.ZodCustom<_messages.HumanMessage<_messages.MessageStructure<_messages.MessageToolSet>>, _messages.HumanMessage<_messages.MessageStructure<_messages.MessageToolSet>>>;
|
|
2889
|
+
filePath: z$2.ZodNullable<z$2.ZodString>;
|
|
2890
|
+
}, _$zod_v4_core0.$strip>>;
|
|
2891
|
+
}, _$zod_v4_core0.$strip>, undefined, unknown, readonly (ClientTool | ServerTool)[]>, AgentMiddleware<undefined, undefined, unknown, readonly (ClientTool | ServerTool)[]>, ...TMiddleware, ...FlattenSubAgentMiddleware<TSubagents>], TTools, TSubagents>>;
|
|
2360
2892
|
//#endregion
|
|
2361
2893
|
//#region src/errors.d.ts
|
|
2362
2894
|
/**
|
|
@@ -2549,7 +3081,7 @@ interface AgentMemoryMiddlewareOptions {
|
|
|
2549
3081
|
* @deprecated Use `createMemoryMiddleware` from `./memory.js` instead.
|
|
2550
3082
|
* This function uses direct filesystem access which limits portability.
|
|
2551
3083
|
*/
|
|
2552
|
-
declare function createAgentMemoryMiddleware(options: AgentMemoryMiddlewareOptions): AgentMiddleware<any, undefined, unknown, readonly (_langchain_core_tools0.ClientTool | _langchain_core_tools0.ServerTool)[]>;
|
|
3084
|
+
declare function createAgentMemoryMiddleware(options: AgentMemoryMiddlewareOptions): AgentMiddleware<any, undefined, unknown, readonly (_$_langchain_core_tools0.ClientTool | _$_langchain_core_tools0.ServerTool)[]>;
|
|
2553
3085
|
//#endregion
|
|
2554
3086
|
//#region src/skills/loader.d.ts
|
|
2555
3087
|
/**
|
|
@@ -2603,5 +3135,5 @@ declare function parseSkillMetadata(skillMdPath: string, source: "user" | "proje
|
|
|
2603
3135
|
*/
|
|
2604
3136
|
declare function listSkills(options: ListSkillsOptions): SkillMetadata[];
|
|
2605
3137
|
//#endregion
|
|
2606
|
-
export { type AgentMemoryMiddlewareOptions, type BackendFactory, type BackendProtocol, type BackendRuntime, BaseSandbox, type CompiledSubAgent, CompositeBackend, ConfigurationError, type ConfigurationErrorCode, type CreateDeepAgentParams, DEFAULT_GENERAL_PURPOSE_DESCRIPTION, DEFAULT_SUBAGENT_PROMPT, type DeepAgent, type DeepAgentTypeConfig, type DefaultDeepAgentTypeConfig, type EditResult, type ExecuteResponse, type ExtractSubAgentMiddleware, type FileData, type FileDownloadResponse, type FileInfo, type FileOperationError, type FileUploadResponse, FilesystemBackend, type FilesystemMiddlewareOptions, type FlattenSubAgentMiddleware, GENERAL_PURPOSE_SUBAGENT, type GrepMatch, type InferDeepAgentSubagents, type InferDeepAgentType, type InferStructuredResponse, type InferSubAgentMiddlewareStates, type InferSubagentByName, type InferSubagentReactAgentType, LangSmithSandbox, type LangSmithSandboxOptions, type ListSkillsOptions, type SkillMetadata as LoaderSkillMetadata, LocalShellBackend, type LocalShellBackendOptions, MAX_SKILL_DESCRIPTION_LENGTH, MAX_SKILL_FILE_SIZE, MAX_SKILL_NAME_LENGTH, type MaybePromise, type MemoryMiddlewareOptions, type MergedDeepAgentState, type ResolveDeepAgentTypeConfig, type SandboxBackendProtocol, type SandboxDeleteOptions, SandboxError, type SandboxErrorCode, type SandboxGetOrCreateOptions, type SandboxInfo, type SandboxListOptions, type SandboxListResponse, type Settings, type SettingsOptions, type SkillMetadata$1 as SkillMetadata, type SkillsMiddlewareOptions, type StateAndStore, StateBackend, StoreBackend, type StoreBackendOptions, type SubAgent, type SubAgentMiddlewareOptions, type SupportedResponseFormat, TASK_SYSTEM_PROMPT, type WriteResult, computeSummarizationDefaults, createAgentMemoryMiddleware, createDeepAgent, createFilesystemMiddleware, createMemoryMiddleware, createPatchToolCallsMiddleware, createSettings, createSkillsMiddleware, createSubAgentMiddleware, createSummarizationMiddleware, filesValue, findProjectRoot, isSandboxBackend, listSkills, parseSkillMetadata, resolveBackend };
|
|
3138
|
+
export { type AgentMemoryMiddlewareOptions, type AnyBackendProtocol, type AnySubAgent, type AsyncSubAgent, type AsyncSubAgentMiddlewareOptions, type AsyncTask, type AsyncTaskStatus, type BackendFactory, type BackendProtocol, type BackendProtocolV1, type BackendProtocolV2, type BackendRuntime, BaseSandbox, type CompiledSubAgent, type CompletionCallbackOptions, CompositeBackend, ConfigurationError, type ConfigurationErrorCode, type CreateDeepAgentParams, DEFAULT_GENERAL_PURPOSE_DESCRIPTION, DEFAULT_SUBAGENT_PROMPT, type DeepAgent, type DeepAgentTypeConfig, type DefaultDeepAgentTypeConfig, type EditResult, type ExecuteResponse, type ExtractSubAgentMiddleware, type FileData, type FileDownloadResponse, type FileInfo, type FileOperationError, type FileUploadResponse, FilesystemBackend, type FilesystemMiddlewareOptions, type FlattenSubAgentMiddleware, GENERAL_PURPOSE_SUBAGENT, type GlobResult, type GrepMatch, type GrepResult, type InferDeepAgentSubagents, type InferDeepAgentType, type InferStructuredResponse, type InferSubAgentMiddlewareStates, type InferSubagentByName, type InferSubagentReactAgentType, LangSmithSandbox, type LangSmithSandboxOptions, type ListSkillsOptions, type SkillMetadata as LoaderSkillMetadata, LocalShellBackend, type LocalShellBackendOptions, type LsResult, MAX_SKILL_DESCRIPTION_LENGTH, MAX_SKILL_FILE_SIZE, MAX_SKILL_NAME_LENGTH, type MaybePromise, type MemoryMiddlewareOptions, type MergedDeepAgentState, type ReadRawResult, type ReadResult, type ResolveDeepAgentTypeConfig, type SandboxBackendProtocol, type SandboxBackendProtocolV1, type SandboxBackendProtocolV2, type SandboxDeleteOptions, SandboxError, type SandboxErrorCode, type SandboxGetOrCreateOptions, type SandboxInfo, type SandboxListOptions, type SandboxListResponse, type Settings, type SettingsOptions, type SkillMetadata$1 as SkillMetadata, type SkillsMiddlewareOptions, type StateAndStore, StateBackend, StoreBackend, type StoreBackendOptions, type SubAgent, type SubAgentMiddlewareOptions, type SupportedResponseFormat, TASK_SYSTEM_PROMPT, type WriteResult, adaptBackendProtocol, adaptSandboxProtocol, computeSummarizationDefaults, createAgentMemoryMiddleware, createAsyncSubAgentMiddleware, createCompletionCallbackMiddleware, createDeepAgent, createFilesystemMiddleware, createMemoryMiddleware, createPatchToolCallsMiddleware, createSettings, createSkillsMiddleware, createSubAgentMiddleware, createSummarizationMiddleware, filesValue, findProjectRoot, isAsyncSubAgent, isSandboxBackend, isSandboxProtocol, listSkills, parseSkillMetadata, resolveBackend };
|
|
2607
3139
|
//# sourceMappingURL=index.d.ts.map
|