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