deepagentsdk 0.11.1 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/elements/index.cjs +274 -0
- package/dist/adapters/elements/index.cjs.map +1 -0
- package/dist/adapters/elements/index.d.cts +122 -0
- package/dist/adapters/elements/index.d.mts +122 -0
- package/dist/adapters/elements/index.mjs +268 -0
- package/dist/adapters/elements/index.mjs.map +1 -0
- package/dist/agent-BDM-PIu8.d.mts +1500 -0
- package/dist/agent-DToEVxs-.d.cts +1500 -0
- package/dist/chunk-C5azi7Hr.cjs +67 -0
- package/dist/cli/index.cjs +3162 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/cli/index.d.cts +1 -0
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.mjs +3120 -0
- package/dist/cli/index.mjs.map +1 -0
- package/dist/file-saver-BYPKakT4.cjs +3990 -0
- package/dist/file-saver-BYPKakT4.cjs.map +1 -0
- package/dist/file-saver-Hj5so3dV.mjs +3568 -0
- package/dist/file-saver-Hj5so3dV.mjs.map +1 -0
- package/dist/index.cjs +1481 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1233 -0
- package/dist/index.d.mts +1233 -0
- package/dist/index.mjs +1381 -0
- package/dist/index.mjs.map +1 -0
- package/dist/load-BBYEnMwz.mjs +142 -0
- package/dist/load-BBYEnMwz.mjs.map +1 -0
- package/dist/load-BDxe6Cet.mjs +3 -0
- package/dist/load-BrRAKlO6.cjs +163 -0
- package/dist/load-BrRAKlO6.cjs.map +1 -0
- package/dist/load-DqllBbDc.cjs +4 -0
- package/package.json +26 -12
- package/src/adapters/elements/index.ts +0 -27
- package/src/adapters/elements/messageAdapter.ts +0 -165
- package/src/adapters/elements/statusAdapter.ts +0 -39
- package/src/adapters/elements/types.ts +0 -97
- package/src/adapters/elements/useElementsAdapter.ts +0 -261
- package/src/agent.ts +0 -1258
- package/src/backends/composite.ts +0 -273
- package/src/backends/filesystem.ts +0 -692
- package/src/backends/index.ts +0 -22
- package/src/backends/local-sandbox.ts +0 -175
- package/src/backends/persistent.ts +0 -593
- package/src/backends/sandbox.ts +0 -510
- package/src/backends/state.ts +0 -244
- package/src/backends/utils.ts +0 -287
- package/src/checkpointer/file-saver.ts +0 -98
- package/src/checkpointer/index.ts +0 -5
- package/src/checkpointer/kv-saver.ts +0 -82
- package/src/checkpointer/memory-saver.ts +0 -82
- package/src/checkpointer/types.ts +0 -125
- package/src/cli/components/ApiKeyInput.tsx +0 -300
- package/src/cli/components/FilePreview.tsx +0 -237
- package/src/cli/components/Input.tsx +0 -277
- package/src/cli/components/Message.tsx +0 -93
- package/src/cli/components/ModelSelection.tsx +0 -338
- package/src/cli/components/SlashMenu.tsx +0 -101
- package/src/cli/components/StatusBar.tsx +0 -89
- package/src/cli/components/Subagent.tsx +0 -91
- package/src/cli/components/TodoList.tsx +0 -133
- package/src/cli/components/ToolApproval.tsx +0 -70
- package/src/cli/components/ToolCall.tsx +0 -144
- package/src/cli/components/ToolCallSummary.tsx +0 -175
- package/src/cli/components/Welcome.tsx +0 -75
- package/src/cli/components/index.ts +0 -24
- package/src/cli/hooks/index.ts +0 -12
- package/src/cli/hooks/useAgent.ts +0 -933
- package/src/cli/index.tsx +0 -1066
- package/src/cli/theme.ts +0 -205
- package/src/cli/utils/model-list.ts +0 -365
- package/src/constants/errors.ts +0 -29
- package/src/constants/limits.ts +0 -195
- package/src/index.ts +0 -176
- package/src/middleware/agent-memory.ts +0 -330
- package/src/prompts.ts +0 -196
- package/src/skills/index.ts +0 -2
- package/src/skills/load.ts +0 -191
- package/src/skills/types.ts +0 -53
- package/src/tools/execute.ts +0 -167
- package/src/tools/filesystem.ts +0 -418
- package/src/tools/index.ts +0 -39
- package/src/tools/subagent.ts +0 -443
- package/src/tools/todos.ts +0 -101
- package/src/tools/web.ts +0 -567
- package/src/types/backend.ts +0 -177
- package/src/types/core.ts +0 -220
- package/src/types/events.ts +0 -430
- package/src/types/index.ts +0 -94
- package/src/types/structured-output.ts +0 -43
- package/src/types/subagent.ts +0 -96
- package/src/types.ts +0 -22
- package/src/utils/approval.ts +0 -213
- package/src/utils/events.ts +0 -416
- package/src/utils/eviction.ts +0 -181
- package/src/utils/index.ts +0 -34
- package/src/utils/model-parser.ts +0 -38
- package/src/utils/patch-tool-calls.ts +0 -233
- package/src/utils/project-detection.ts +0 -32
- package/src/utils/summarization.ts +0 -254
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,1233 @@
|
|
|
1
|
+
import { $ as createLsTool, A as TextEvent, At as CheckpointSaverOptions, B as DynamicApprovalConfig, C as FileWrittenEvent, Ct as FileInfo, D as StepStartEvent, Dt as isSandboxBackend, E as StepFinishEvent, Et as WriteResult, F as WebSearchStartEvent, G as createExecuteToolFromBackend, H as SubAgent, I as AgentMemoryOptions, J as write_todos, K as execute, L as CreateDeepAgentParams, M as ToolCallEvent, Mt as ResumeDecision, N as ToolResultEvent, Nt as ResumeOptions, O as SubagentFinishEvent, Ot as BaseCheckpointSaver, P as WebSearchFinishEvent, Q as createGrepTool, R as SummarizationConfig, S as FileWriteStartEvent, St as FileData, T as HttpRequestStartEvent, Tt as SandboxBackendProtocol, U as CreateExecuteToolOptions, V as InterruptOnConfig, W as createExecuteTool, X as createFilesystemTools, Y as createEditFileTool, Z as createGlobTool, _ as ExecuteFinishEvent, _t as BackendFactory, a as eventHasStructuredOutput, at as ls, b as FetchUrlStartEvent, bt as EditResult, c as hasStructuredOutput, ct as CreateWebToolsOptions, d as CheckpointLoadedEvent, dt as createWebSearchTool, et as createReadFileTool, f as CheckpointSavedEvent, ft as createWebTools, g as EventCallback, gt as web_search, h as ErrorEvent, ht as http_request, i as StructuredAgentResult, it as grep, j as TodosChangedEvent, jt as InterruptData, k as SubagentStartEvent, kt as Checkpoint, l as ApprovalRequestedEvent, lt as createFetchUrlTool, m as DoneEvent, mt as htmlToMarkdown, n as createDeepAgent, nt as edit_file, o as getEventOutput, ot as read_file, p as DeepAgentEvent, pt as fetch_url, q as createTodosTool, r as ModelMessage$1, rt as glob, s as getStructuredOutput, st as write_file, t as DeepAgent, tt as createWriteFileTool, u as ApprovalResponseEvent, ut as createHttpRequestTool, v as ExecuteStartEvent, vt as BackendProtocol, w as HttpRequestFinishEvent, wt as GrepMatch, x as FileEditedEvent, xt as ExecuteResponse, y as FetchUrlFinishEvent, yt as DeepAgentState, z as TodoItem } from "./agent-DToEVxs-.cjs";
|
|
2
|
+
import * as ai18 from "ai";
|
|
3
|
+
import { LanguageModel, LanguageModelMiddleware, LanguageModelMiddleware as LanguageModelMiddleware$1, ModelMessage, ToolLoopAgent, ToolSet, hasToolCall, stepCountIs, wrapLanguageModel } from "ai";
|
|
4
|
+
|
|
5
|
+
//#region src/backends/state.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Backend that stores files in shared state (ephemeral).
|
|
9
|
+
*
|
|
10
|
+
* Files persist within a single agent invocation but not across invocations.
|
|
11
|
+
* This is the default backend for Deep Agent when no backend is specified.
|
|
12
|
+
*
|
|
13
|
+
* Files are stored in memory as part of the `DeepAgentState`, making this backend
|
|
14
|
+
* fast but non-persistent. Use `FilesystemBackend` or `PersistentBackend` for
|
|
15
|
+
* cross-session persistence.
|
|
16
|
+
*
|
|
17
|
+
* @example Default usage (no backend specified)
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const agent = createDeepAgent({
|
|
20
|
+
* model: anthropic('claude-sonnet-4-20250514'),
|
|
21
|
+
* // StateBackend is used by default
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example Explicit usage
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const state: DeepAgentState = { todos: [], files: {} };
|
|
28
|
+
* const backend = new StateBackend(state);
|
|
29
|
+
* const agent = createDeepAgent({
|
|
30
|
+
* model: anthropic('claude-sonnet-4-20250514'),
|
|
31
|
+
* backend,
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare class StateBackend implements BackendProtocol {
|
|
36
|
+
private state;
|
|
37
|
+
/**
|
|
38
|
+
* Create a new StateBackend instance.
|
|
39
|
+
*
|
|
40
|
+
* @param state - The DeepAgentState object that will store the files.
|
|
41
|
+
* Files are stored in `state.files` as a Record<string, FileData>.
|
|
42
|
+
*/
|
|
43
|
+
constructor(state: DeepAgentState);
|
|
44
|
+
/**
|
|
45
|
+
* Get files from current state.
|
|
46
|
+
*/
|
|
47
|
+
private getFiles;
|
|
48
|
+
/**
|
|
49
|
+
* List files and directories in the specified directory (non-recursive).
|
|
50
|
+
*/
|
|
51
|
+
lsInfo(path: string): FileInfo[];
|
|
52
|
+
/**
|
|
53
|
+
* Read file content with line numbers.
|
|
54
|
+
*/
|
|
55
|
+
read(filePath: string, offset?: number, limit?: number): string;
|
|
56
|
+
/**
|
|
57
|
+
* Read file content as raw FileData.
|
|
58
|
+
*/
|
|
59
|
+
readRaw(filePath: string): FileData;
|
|
60
|
+
/**
|
|
61
|
+
* Create a new file with content.
|
|
62
|
+
*/
|
|
63
|
+
write(filePath: string, content: string): WriteResult;
|
|
64
|
+
/**
|
|
65
|
+
* Edit a file by replacing string occurrences.
|
|
66
|
+
*/
|
|
67
|
+
edit(filePath: string, oldString: string, newString: string, replaceAll?: boolean): EditResult;
|
|
68
|
+
/**
|
|
69
|
+
* Structured search results or error string for invalid input.
|
|
70
|
+
*/
|
|
71
|
+
grepRaw(pattern: string, path?: string, glob?: string | null): GrepMatch[] | string;
|
|
72
|
+
/**
|
|
73
|
+
* Structured glob matching returning FileInfo objects.
|
|
74
|
+
*/
|
|
75
|
+
globInfo(pattern: string, path?: string): FileInfo[];
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/backends/filesystem.d.ts
|
|
79
|
+
/**
|
|
80
|
+
* Backend that reads and writes files directly from the filesystem.
|
|
81
|
+
*
|
|
82
|
+
* Files are persisted to disk, making them available across agent invocations.
|
|
83
|
+
* This backend provides real file I/O operations with security checks to prevent
|
|
84
|
+
* directory traversal attacks.
|
|
85
|
+
*
|
|
86
|
+
* @example Basic usage
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const backend = new FilesystemBackend({ rootDir: './workspace' });
|
|
89
|
+
* const agent = createDeepAgent({
|
|
90
|
+
* model: anthropic('claude-sonnet-4-20250514'),
|
|
91
|
+
* backend,
|
|
92
|
+
* });
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* @example With custom options
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const backend = new FilesystemBackend({
|
|
98
|
+
* rootDir: './my-project',
|
|
99
|
+
* virtualMode: false,
|
|
100
|
+
* maxFileSizeMb: 50, // Allow larger files
|
|
101
|
+
* });
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
declare class FilesystemBackend implements BackendProtocol {
|
|
105
|
+
private cwd;
|
|
106
|
+
private virtualMode;
|
|
107
|
+
private maxFileSizeBytes;
|
|
108
|
+
/**
|
|
109
|
+
* Create a new FilesystemBackend instance.
|
|
110
|
+
*
|
|
111
|
+
* @param options - Configuration options
|
|
112
|
+
* @param options.rootDir - Optional root directory for file operations (default: current working directory).
|
|
113
|
+
* All file paths are resolved relative to this directory.
|
|
114
|
+
* @param options.virtualMode - Optional flag for virtual mode (default: false).
|
|
115
|
+
* When true, files are stored in memory but paths are validated against filesystem.
|
|
116
|
+
* @param options.maxFileSizeMb - Optional maximum file size in MB (default: 10).
|
|
117
|
+
* Files larger than this will be rejected.
|
|
118
|
+
*/
|
|
119
|
+
constructor(options?: {
|
|
120
|
+
rootDir?: string;
|
|
121
|
+
virtualMode?: boolean;
|
|
122
|
+
maxFileSizeMb?: number;
|
|
123
|
+
});
|
|
124
|
+
/**
|
|
125
|
+
* Resolve a file path with security checks.
|
|
126
|
+
*/
|
|
127
|
+
private resolvePath;
|
|
128
|
+
/**
|
|
129
|
+
* List files and directories in the specified directory (non-recursive).
|
|
130
|
+
*/
|
|
131
|
+
lsInfo(dirPath: string): Promise<FileInfo[]>;
|
|
132
|
+
/**
|
|
133
|
+
* Read file content with line numbers.
|
|
134
|
+
*/
|
|
135
|
+
read(filePath: string, offset?: number, limit?: number): Promise<string>;
|
|
136
|
+
/**
|
|
137
|
+
* Read file content as raw FileData.
|
|
138
|
+
*/
|
|
139
|
+
readRaw(filePath: string): Promise<FileData>;
|
|
140
|
+
/**
|
|
141
|
+
* Create a new file with content.
|
|
142
|
+
*/
|
|
143
|
+
write(filePath: string, content: string): Promise<WriteResult>;
|
|
144
|
+
/**
|
|
145
|
+
* Edit a file by replacing string occurrences.
|
|
146
|
+
*/
|
|
147
|
+
edit(filePath: string, oldString: string, newString: string, replaceAll?: boolean): Promise<EditResult>;
|
|
148
|
+
/**
|
|
149
|
+
* Structured search results or error string for invalid input.
|
|
150
|
+
*/
|
|
151
|
+
grepRaw(pattern: string, dirPath?: string, glob?: string | null): Promise<GrepMatch[] | string>;
|
|
152
|
+
/**
|
|
153
|
+
* Try to use ripgrep for fast searching.
|
|
154
|
+
*/
|
|
155
|
+
private ripgrepSearch;
|
|
156
|
+
/**
|
|
157
|
+
* Fallback regex search implementation.
|
|
158
|
+
*/
|
|
159
|
+
private regexSearch;
|
|
160
|
+
/**
|
|
161
|
+
* Structured glob matching returning FileInfo objects.
|
|
162
|
+
*/
|
|
163
|
+
globInfo(pattern: string, searchPath?: string): Promise<FileInfo[]>;
|
|
164
|
+
}
|
|
165
|
+
//#endregion
|
|
166
|
+
//#region src/backends/composite.d.ts
|
|
167
|
+
/**
|
|
168
|
+
* Backend that routes file operations to different backends based on path prefix.
|
|
169
|
+
*
|
|
170
|
+
* This enables hybrid storage strategies by routing files to different backends
|
|
171
|
+
* based on their path prefix. Useful for separating persistent and ephemeral storage,
|
|
172
|
+
* or using different storage backends for different types of files.
|
|
173
|
+
*
|
|
174
|
+
* @example Hybrid storage strategy
|
|
175
|
+
* ```typescript
|
|
176
|
+
* import { CompositeBackend, FilesystemBackend, StateBackend } from 'deepagentsdk';
|
|
177
|
+
*
|
|
178
|
+
* const state = { todos: [], files: {} };
|
|
179
|
+
* const backend = new CompositeBackend(
|
|
180
|
+
* new StateBackend(state), // Default: ephemeral storage
|
|
181
|
+
* {
|
|
182
|
+
* '/persistent/': new FilesystemBackend({ rootDir: './persistent' }), // Persistent files
|
|
183
|
+
* '/cache/': new StateBackend(state), // Cached files (ephemeral)
|
|
184
|
+
* }
|
|
185
|
+
* );
|
|
186
|
+
*
|
|
187
|
+
* const agent = createDeepAgent({
|
|
188
|
+
* model: anthropic('claude-sonnet-4-20250514'),
|
|
189
|
+
* backend,
|
|
190
|
+
* });
|
|
191
|
+
* ```
|
|
192
|
+
*
|
|
193
|
+
* @example Multiple persistent backends
|
|
194
|
+
* ```typescript
|
|
195
|
+
* const backend = new CompositeBackend(
|
|
196
|
+
* new FilesystemBackend({ rootDir: './default' }),
|
|
197
|
+
* {
|
|
198
|
+
* '/user-data/': new FilesystemBackend({ rootDir: './user-data' }),
|
|
199
|
+
* '/system/': new FilesystemBackend({ rootDir: './system' }),
|
|
200
|
+
* }
|
|
201
|
+
* );
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
declare class CompositeBackend implements BackendProtocol {
|
|
205
|
+
private defaultBackend;
|
|
206
|
+
private routes;
|
|
207
|
+
private sortedRoutes;
|
|
208
|
+
/**
|
|
209
|
+
* Create a new CompositeBackend instance.
|
|
210
|
+
*
|
|
211
|
+
* @param defaultBackend - Backend to use for paths that don't match any route prefix
|
|
212
|
+
* @param routes - Record mapping path prefixes to backends.
|
|
213
|
+
* Routes are matched by longest prefix first.
|
|
214
|
+
* Example: `{ '/persistent/': filesystemBackend, '/cache/': stateBackend }`
|
|
215
|
+
*/
|
|
216
|
+
constructor(defaultBackend: BackendProtocol, routes: Record<string, BackendProtocol>);
|
|
217
|
+
/**
|
|
218
|
+
* Determine which backend handles this key and strip prefix.
|
|
219
|
+
*/
|
|
220
|
+
private getBackendAndKey;
|
|
221
|
+
/**
|
|
222
|
+
* List files and directories in the specified directory (non-recursive).
|
|
223
|
+
*/
|
|
224
|
+
lsInfo(path: string): Promise<FileInfo[]>;
|
|
225
|
+
/**
|
|
226
|
+
* Read file content, routing to appropriate backend.
|
|
227
|
+
*/
|
|
228
|
+
read(filePath: string, offset?: number, limit?: number): Promise<string>;
|
|
229
|
+
/**
|
|
230
|
+
* Read file content as raw FileData.
|
|
231
|
+
*/
|
|
232
|
+
readRaw(filePath: string): Promise<FileData>;
|
|
233
|
+
/**
|
|
234
|
+
* Structured search results or error string for invalid input.
|
|
235
|
+
*/
|
|
236
|
+
grepRaw(pattern: string, path?: string, glob?: string | null): Promise<GrepMatch[] | string>;
|
|
237
|
+
/**
|
|
238
|
+
* Structured glob matching returning FileInfo objects.
|
|
239
|
+
*/
|
|
240
|
+
globInfo(pattern: string, path?: string): Promise<FileInfo[]>;
|
|
241
|
+
/**
|
|
242
|
+
* Create a new file, routing to appropriate backend.
|
|
243
|
+
*/
|
|
244
|
+
write(filePath: string, content: string): Promise<WriteResult>;
|
|
245
|
+
/**
|
|
246
|
+
* Edit a file, routing to appropriate backend.
|
|
247
|
+
*/
|
|
248
|
+
edit(filePath: string, oldString: string, newString: string, replaceAll?: boolean): Promise<EditResult>;
|
|
249
|
+
}
|
|
250
|
+
//#endregion
|
|
251
|
+
//#region src/backends/persistent.d.ts
|
|
252
|
+
/**
|
|
253
|
+
* Generic key-value store interface for persistent storage.
|
|
254
|
+
*
|
|
255
|
+
* Implement this interface to use any storage backend (Redis, SQLite, cloud storage, etc.)
|
|
256
|
+
* with PersistentBackend. The interface uses hierarchical namespaces for organization.
|
|
257
|
+
*
|
|
258
|
+
* @example Redis implementation
|
|
259
|
+
* ```typescript
|
|
260
|
+
* class RedisStore implements KeyValueStore {
|
|
261
|
+
* constructor(private redis: RedisClient) {}
|
|
262
|
+
*
|
|
263
|
+
* async get(namespace: string[], key: string) {
|
|
264
|
+
* const redisKey = [...namespace, key].join(':');
|
|
265
|
+
* const data = await this.redis.get(redisKey);
|
|
266
|
+
* return data ? JSON.parse(data) : undefined;
|
|
267
|
+
* }
|
|
268
|
+
*
|
|
269
|
+
* async put(namespace: string[], key: string, value: Record<string, unknown>) {
|
|
270
|
+
* const redisKey = [...namespace, key].join(':');
|
|
271
|
+
* await this.redis.set(redisKey, JSON.stringify(value));
|
|
272
|
+
* }
|
|
273
|
+
*
|
|
274
|
+
* async delete(namespace: string[], key: string) {
|
|
275
|
+
* const redisKey = [...namespace, key].join(':');
|
|
276
|
+
* await this.redis.del(redisKey);
|
|
277
|
+
* }
|
|
278
|
+
*
|
|
279
|
+
* async list(namespace: string[]) {
|
|
280
|
+
* const prefix = [...namespace].join(':') + ':';
|
|
281
|
+
* const keys = await this.redis.keys(prefix + '*');
|
|
282
|
+
* const results = [];
|
|
283
|
+
* for (const key of keys) {
|
|
284
|
+
* const data = await this.redis.get(key);
|
|
285
|
+
* if (data) {
|
|
286
|
+
* const relativeKey = key.substring(prefix.length);
|
|
287
|
+
* results.push({ key: relativeKey, value: JSON.parse(data) });
|
|
288
|
+
* }
|
|
289
|
+
* }
|
|
290
|
+
* return results;
|
|
291
|
+
* }
|
|
292
|
+
* }
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
295
|
+
interface KeyValueStore {
|
|
296
|
+
/**
|
|
297
|
+
* Get a value by key from the store.
|
|
298
|
+
* @param namespace - Hierarchical namespace array (e.g., ["project1", "filesystem"])
|
|
299
|
+
* @param key - The key to retrieve (file path in the case of PersistentBackend)
|
|
300
|
+
* @returns The stored value as a record, or undefined if not found
|
|
301
|
+
*/
|
|
302
|
+
get(namespace: string[], key: string): Promise<Record<string, unknown> | undefined>;
|
|
303
|
+
/**
|
|
304
|
+
* Store a value by key in the store.
|
|
305
|
+
* @param namespace - Hierarchical namespace array
|
|
306
|
+
* @param key - The key to store (file path in the case of PersistentBackend)
|
|
307
|
+
* @param value - The value to store (must be serializable to JSON)
|
|
308
|
+
*/
|
|
309
|
+
put(namespace: string[], key: string, value: Record<string, unknown>): Promise<void>;
|
|
310
|
+
/**
|
|
311
|
+
* Delete a value by key from the store.
|
|
312
|
+
* @param namespace - Hierarchical namespace array
|
|
313
|
+
* @param key - The key to delete (file path in the case of PersistentBackend)
|
|
314
|
+
*/
|
|
315
|
+
delete(namespace: string[], key: string): Promise<void>;
|
|
316
|
+
/**
|
|
317
|
+
* List all keys and values in a namespace.
|
|
318
|
+
* @param namespace - Hierarchical namespace array
|
|
319
|
+
* @returns Array of items with key and value pairs directly in this namespace
|
|
320
|
+
* (not including sub-namespaces)
|
|
321
|
+
*/
|
|
322
|
+
list(namespace: string[]): Promise<Array<{
|
|
323
|
+
key: string;
|
|
324
|
+
value: Record<string, unknown>;
|
|
325
|
+
}>>;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Simple in-memory implementation of KeyValueStore.
|
|
329
|
+
*
|
|
330
|
+
* Useful for testing or single-session persistence. Data is stored in a Map
|
|
331
|
+
* and does not persist across application restarts.
|
|
332
|
+
*
|
|
333
|
+
* @example Basic usage
|
|
334
|
+
* ```typescript
|
|
335
|
+
* const store = new InMemoryStore();
|
|
336
|
+
* const backend = new PersistentBackend({ store });
|
|
337
|
+
* ```
|
|
338
|
+
*
|
|
339
|
+
* @example For testing
|
|
340
|
+
* ```typescript
|
|
341
|
+
* const store = new InMemoryStore();
|
|
342
|
+
* // ... run tests ...
|
|
343
|
+
* store.clear(); // Clean up after tests
|
|
344
|
+
* ```
|
|
345
|
+
*/
|
|
346
|
+
declare class InMemoryStore implements KeyValueStore {
|
|
347
|
+
private data;
|
|
348
|
+
private makeKey;
|
|
349
|
+
private parseKey;
|
|
350
|
+
get(namespace: string[], key: string): Promise<Record<string, unknown> | undefined>;
|
|
351
|
+
put(namespace: string[], key: string, value: Record<string, unknown>): Promise<void>;
|
|
352
|
+
delete(namespace: string[], key: string): Promise<void>;
|
|
353
|
+
list(namespace: string[]): Promise<Array<{
|
|
354
|
+
key: string;
|
|
355
|
+
value: Record<string, unknown>;
|
|
356
|
+
}>>;
|
|
357
|
+
/**
|
|
358
|
+
* Clear all data (useful for testing).
|
|
359
|
+
*/
|
|
360
|
+
clear(): void;
|
|
361
|
+
/**
|
|
362
|
+
* Get the number of stored items.
|
|
363
|
+
*/
|
|
364
|
+
size(): number;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Options for creating a PersistentBackend.
|
|
368
|
+
*/
|
|
369
|
+
interface PersistentBackendOptions {
|
|
370
|
+
/**
|
|
371
|
+
* **Required.** The key-value store implementation to use.
|
|
372
|
+
*
|
|
373
|
+
* You can use the built-in `InMemoryStore` for testing, or implement `KeyValueStore`
|
|
374
|
+
* for custom storage (Redis, SQLite, etc.).
|
|
375
|
+
*
|
|
376
|
+
* @see {@link KeyValueStore} for the interface definition
|
|
377
|
+
* @see {@link InMemoryStore} for a simple in-memory implementation
|
|
378
|
+
*/
|
|
379
|
+
store: KeyValueStore;
|
|
380
|
+
/**
|
|
381
|
+
* Optional namespace prefix for isolation (e.g., project ID, user ID).
|
|
382
|
+
*
|
|
383
|
+
* This allows multiple agents or projects to share the same store without conflicts.
|
|
384
|
+
* Files are stored under `[namespace]/filesystem/` in the key-value store.
|
|
385
|
+
*
|
|
386
|
+
* Default: "default"
|
|
387
|
+
*/
|
|
388
|
+
namespace?: string;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Backend that stores files in a persistent key-value store.
|
|
392
|
+
*
|
|
393
|
+
* This provides cross-conversation file persistence that survives between agent sessions.
|
|
394
|
+
* Files are stored in the provided key-value store, allowing you to use any storage backend
|
|
395
|
+
* (Redis, SQLite, cloud storage, etc.) by implementing the `KeyValueStore` interface.
|
|
396
|
+
*
|
|
397
|
+
* @example Using InMemoryStore (for testing or single-session persistence)
|
|
398
|
+
* ```typescript
|
|
399
|
+
* import { createDeepAgent } from 'deepagentsdk';
|
|
400
|
+
* import { PersistentBackend, InMemoryStore } from 'deepagentsdk';
|
|
401
|
+
* import { anthropic } from '@ai-sdk/anthropic';
|
|
402
|
+
*
|
|
403
|
+
* const store = new InMemoryStore();
|
|
404
|
+
* const backend = new PersistentBackend({ store });
|
|
405
|
+
* const agent = createDeepAgent({
|
|
406
|
+
* model: anthropic('claude-sonnet-4-20250514'),
|
|
407
|
+
* backend,
|
|
408
|
+
* });
|
|
409
|
+
* ```
|
|
410
|
+
*
|
|
411
|
+
* @example With custom namespace for project isolation
|
|
412
|
+
* ```typescript
|
|
413
|
+
* import { createDeepAgent } from 'deepagentsdk';
|
|
414
|
+
* import { PersistentBackend, InMemoryStore } from 'deepagentsdk';
|
|
415
|
+
* import { anthropic } from '@ai-sdk/anthropic';
|
|
416
|
+
*
|
|
417
|
+
* const store = new InMemoryStore();
|
|
418
|
+
* const backend = new PersistentBackend({
|
|
419
|
+
* store,
|
|
420
|
+
* namespace: 'project-123', // Isolate files for this project
|
|
421
|
+
* });
|
|
422
|
+
* const agent = createDeepAgent({
|
|
423
|
+
* model: anthropic('claude-sonnet-4-20250514'),
|
|
424
|
+
* backend,
|
|
425
|
+
* });
|
|
426
|
+
* ```
|
|
427
|
+
*
|
|
428
|
+
* @example Custom KeyValueStore implementation (Redis)
|
|
429
|
+
* ```typescript
|
|
430
|
+
* import { createDeepAgent } from 'deepagentsdk';
|
|
431
|
+
* import { PersistentBackend, type KeyValueStore } from 'deepagentsdk';
|
|
432
|
+
* import { anthropic } from '@ai-sdk/anthropic';
|
|
433
|
+
* import { createClient } from 'redis';
|
|
434
|
+
*
|
|
435
|
+
* class RedisStore implements KeyValueStore {
|
|
436
|
+
* constructor(private redis: ReturnType<typeof createClient>) {}
|
|
437
|
+
*
|
|
438
|
+
* async get(namespace: string[], key: string) {
|
|
439
|
+
* const redisKey = [...namespace, key].join(':');
|
|
440
|
+
* const data = await this.redis.get(redisKey);
|
|
441
|
+
* return data ? JSON.parse(data) : undefined;
|
|
442
|
+
* }
|
|
443
|
+
*
|
|
444
|
+
* async put(namespace: string[], key: string, value: Record<string, unknown>) {
|
|
445
|
+
* const redisKey = [...namespace, key].join(':');
|
|
446
|
+
* await this.redis.set(redisKey, JSON.stringify(value));
|
|
447
|
+
* }
|
|
448
|
+
*
|
|
449
|
+
* async delete(namespace: string[], key: string) {
|
|
450
|
+
* const redisKey = [...namespace, key].join(':');
|
|
451
|
+
* await this.redis.del(redisKey);
|
|
452
|
+
* }
|
|
453
|
+
*
|
|
454
|
+
* async list(namespace: string[]) {
|
|
455
|
+
* const prefix = [...namespace].join(':') + ':';
|
|
456
|
+
* const keys = await this.redis.keys(prefix + '*');
|
|
457
|
+
* const results = [];
|
|
458
|
+
* for (const key of keys) {
|
|
459
|
+
* const data = await this.redis.get(key);
|
|
460
|
+
* if (data) {
|
|
461
|
+
* const relativeKey = key.substring(prefix.length);
|
|
462
|
+
* results.push({ key: relativeKey, value: JSON.parse(data) });
|
|
463
|
+
* }
|
|
464
|
+
* }
|
|
465
|
+
* return results;
|
|
466
|
+
* }
|
|
467
|
+
* }
|
|
468
|
+
*
|
|
469
|
+
* const redis = createClient();
|
|
470
|
+
* await redis.connect();
|
|
471
|
+
*
|
|
472
|
+
* const backend = new PersistentBackend({
|
|
473
|
+
* store: new RedisStore(redis),
|
|
474
|
+
* namespace: 'production'
|
|
475
|
+
* });
|
|
476
|
+
*
|
|
477
|
+
* const agent = createDeepAgent({
|
|
478
|
+
* model: anthropic('claude-sonnet-4-20250514'),
|
|
479
|
+
* backend,
|
|
480
|
+
* });
|
|
481
|
+
* ```
|
|
482
|
+
*/
|
|
483
|
+
declare class PersistentBackend implements BackendProtocol {
|
|
484
|
+
private store;
|
|
485
|
+
private namespacePrefix;
|
|
486
|
+
/**
|
|
487
|
+
* Create a new PersistentBackend instance.
|
|
488
|
+
*
|
|
489
|
+
* @param options - Configuration options
|
|
490
|
+
* @param options.store - The key-value store implementation to use
|
|
491
|
+
* @param options.namespace - Optional namespace prefix for file isolation
|
|
492
|
+
*/
|
|
493
|
+
constructor(options: PersistentBackendOptions);
|
|
494
|
+
/**
|
|
495
|
+
* Get the namespace for store operations.
|
|
496
|
+
*/
|
|
497
|
+
protected getNamespace(): string[];
|
|
498
|
+
/**
|
|
499
|
+
* Convert a store value to FileData format.
|
|
500
|
+
*/
|
|
501
|
+
private convertToFileData;
|
|
502
|
+
/**
|
|
503
|
+
* Convert FileData to a value suitable for store.put().
|
|
504
|
+
*/
|
|
505
|
+
private convertFromFileData;
|
|
506
|
+
/**
|
|
507
|
+
* List files and directories in the specified directory (non-recursive).
|
|
508
|
+
*/
|
|
509
|
+
lsInfo(path: string): Promise<FileInfo[]>;
|
|
510
|
+
/**
|
|
511
|
+
* Read file content with line numbers.
|
|
512
|
+
*/
|
|
513
|
+
read(filePath: string, offset?: number, limit?: number): Promise<string>;
|
|
514
|
+
/**
|
|
515
|
+
* Read file content as raw FileData.
|
|
516
|
+
*/
|
|
517
|
+
readRaw(filePath: string): Promise<FileData>;
|
|
518
|
+
/**
|
|
519
|
+
* Create a new file with content.
|
|
520
|
+
*/
|
|
521
|
+
write(filePath: string, content: string): Promise<WriteResult>;
|
|
522
|
+
/**
|
|
523
|
+
* Edit a file by replacing string occurrences.
|
|
524
|
+
*/
|
|
525
|
+
edit(filePath: string, oldString: string, newString: string, replaceAll?: boolean): Promise<EditResult>;
|
|
526
|
+
/**
|
|
527
|
+
* Structured search results or error string for invalid input.
|
|
528
|
+
*/
|
|
529
|
+
grepRaw(pattern: string, path?: string, glob?: string | null): Promise<GrepMatch[] | string>;
|
|
530
|
+
/**
|
|
531
|
+
* Structured glob matching returning FileInfo objects.
|
|
532
|
+
*/
|
|
533
|
+
globInfo(pattern: string, path?: string): Promise<FileInfo[]>;
|
|
534
|
+
/**
|
|
535
|
+
* Delete a file.
|
|
536
|
+
*/
|
|
537
|
+
deleteFile(filePath: string): Promise<{
|
|
538
|
+
error?: string;
|
|
539
|
+
}>;
|
|
540
|
+
}
|
|
541
|
+
//#endregion
|
|
542
|
+
//#region src/backends/sandbox.d.ts
|
|
543
|
+
/**
|
|
544
|
+
* Abstract base class for sandbox backends.
|
|
545
|
+
*
|
|
546
|
+
* Implements all file operations using shell commands via execute().
|
|
547
|
+
* Subclasses only need to implement execute() and id.
|
|
548
|
+
*
|
|
549
|
+
* @example Creating a custom sandbox backend
|
|
550
|
+
* ```typescript
|
|
551
|
+
* class MyCloudSandbox extends BaseSandbox {
|
|
552
|
+
* readonly id = 'my-cloud-123';
|
|
553
|
+
*
|
|
554
|
+
* async execute(command: string): Promise<ExecuteResponse> {
|
|
555
|
+
* // Call your cloud provider's API
|
|
556
|
+
* const result = await myCloudApi.runCommand(command);
|
|
557
|
+
* return {
|
|
558
|
+
* output: result.stdout + result.stderr,
|
|
559
|
+
* exitCode: result.exitCode,
|
|
560
|
+
* truncated: false,
|
|
561
|
+
* };
|
|
562
|
+
* }
|
|
563
|
+
* }
|
|
564
|
+
* ```
|
|
565
|
+
*/
|
|
566
|
+
declare abstract class BaseSandbox implements SandboxBackendProtocol {
|
|
567
|
+
/**
|
|
568
|
+
* Execute a shell command in the sandbox.
|
|
569
|
+
* Must be implemented by subclasses.
|
|
570
|
+
*/
|
|
571
|
+
abstract execute(command: string): Promise<ExecuteResponse>;
|
|
572
|
+
/**
|
|
573
|
+
* Unique identifier for this sandbox instance.
|
|
574
|
+
* Must be implemented by subclasses.
|
|
575
|
+
*/
|
|
576
|
+
abstract readonly id: string;
|
|
577
|
+
/**
|
|
578
|
+
* List files and directories in a path.
|
|
579
|
+
*/
|
|
580
|
+
lsInfo(path: string): Promise<FileInfo[]>;
|
|
581
|
+
/**
|
|
582
|
+
* Read file content with line numbers.
|
|
583
|
+
*/
|
|
584
|
+
read(filePath: string, offset?: number, limit?: number): Promise<string>;
|
|
585
|
+
/**
|
|
586
|
+
* Read raw file data.
|
|
587
|
+
*/
|
|
588
|
+
readRaw(filePath: string): Promise<FileData>;
|
|
589
|
+
/**
|
|
590
|
+
* Write content to a new file.
|
|
591
|
+
*/
|
|
592
|
+
write(filePath: string, content: string): Promise<WriteResult>;
|
|
593
|
+
/**
|
|
594
|
+
* Edit a file by replacing string occurrences.
|
|
595
|
+
*/
|
|
596
|
+
edit(filePath: string, oldString: string, newString: string, replaceAll?: boolean): Promise<EditResult>;
|
|
597
|
+
/**
|
|
598
|
+
* Search for pattern in files.
|
|
599
|
+
*/
|
|
600
|
+
grepRaw(pattern: string, path?: string, glob?: string | null): Promise<GrepMatch[] | string>;
|
|
601
|
+
/**
|
|
602
|
+
* Find files matching glob pattern.
|
|
603
|
+
*/
|
|
604
|
+
globInfo(pattern: string, path?: string): Promise<FileInfo[]>;
|
|
605
|
+
}
|
|
606
|
+
//#endregion
|
|
607
|
+
//#region src/backends/local-sandbox.d.ts
|
|
608
|
+
/**
|
|
609
|
+
* Options for LocalSandbox.
|
|
610
|
+
*/
|
|
611
|
+
interface LocalSandboxOptions {
|
|
612
|
+
/**
|
|
613
|
+
* Working directory for command execution.
|
|
614
|
+
* All file paths in sandbox operations are relative to this directory.
|
|
615
|
+
* @default process.cwd()
|
|
616
|
+
*/
|
|
617
|
+
cwd?: string;
|
|
618
|
+
/**
|
|
619
|
+
* Timeout in milliseconds for command execution.
|
|
620
|
+
* Commands that exceed this timeout will be terminated.
|
|
621
|
+
* @default 30000 (30 seconds)
|
|
622
|
+
*/
|
|
623
|
+
timeout?: number;
|
|
624
|
+
/**
|
|
625
|
+
* Additional environment variables to set for command execution.
|
|
626
|
+
* These are merged with the current process environment.
|
|
627
|
+
*/
|
|
628
|
+
env?: Record<string, string>;
|
|
629
|
+
/**
|
|
630
|
+
* Maximum output size in bytes before truncation.
|
|
631
|
+
* @default 1048576 (1MB)
|
|
632
|
+
*/
|
|
633
|
+
maxOutputSize?: number;
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* Local sandbox that executes commands using Node.js child_process.
|
|
637
|
+
*
|
|
638
|
+
* All commands are executed in a bash shell with the specified working directory.
|
|
639
|
+
* Inherits all file operations (read, write, edit, ls, grep, glob) from BaseSandbox.
|
|
640
|
+
*
|
|
641
|
+
* @example Basic usage
|
|
642
|
+
* ```typescript
|
|
643
|
+
* import { LocalSandbox } from 'deepagentsdk';
|
|
644
|
+
*
|
|
645
|
+
* const sandbox = new LocalSandbox({ cwd: './workspace' });
|
|
646
|
+
*
|
|
647
|
+
* // Execute commands
|
|
648
|
+
* const result = await sandbox.execute('ls -la');
|
|
649
|
+
* console.log(result.output);
|
|
650
|
+
*
|
|
651
|
+
* // File operations
|
|
652
|
+
* await sandbox.write('./src/index.ts', 'console.log("hello")');
|
|
653
|
+
* const content = await sandbox.read('./src/index.ts');
|
|
654
|
+
* ```
|
|
655
|
+
*
|
|
656
|
+
* @example With timeout and environment
|
|
657
|
+
* ```typescript
|
|
658
|
+
* const sandbox = new LocalSandbox({
|
|
659
|
+
* cwd: './workspace',
|
|
660
|
+
* timeout: 60000, // 60 seconds
|
|
661
|
+
* env: {
|
|
662
|
+
* NODE_ENV: 'development',
|
|
663
|
+
* DEBUG: '*',
|
|
664
|
+
* },
|
|
665
|
+
* });
|
|
666
|
+
* ```
|
|
667
|
+
*
|
|
668
|
+
* @example Error handling
|
|
669
|
+
* ```typescript
|
|
670
|
+
* const result = await sandbox.execute('npm test');
|
|
671
|
+
* if (result.exitCode !== 0) {
|
|
672
|
+
* console.error('Tests failed:', result.output);
|
|
673
|
+
* }
|
|
674
|
+
* ```
|
|
675
|
+
*/
|
|
676
|
+
declare class LocalSandbox extends BaseSandbox {
|
|
677
|
+
private readonly cwd;
|
|
678
|
+
private readonly timeout;
|
|
679
|
+
private readonly env;
|
|
680
|
+
private readonly maxOutputSize;
|
|
681
|
+
private readonly _id;
|
|
682
|
+
/**
|
|
683
|
+
* Create a new LocalSandbox instance.
|
|
684
|
+
*
|
|
685
|
+
* @param options - Configuration options for the sandbox
|
|
686
|
+
*/
|
|
687
|
+
constructor(options?: LocalSandboxOptions);
|
|
688
|
+
/**
|
|
689
|
+
* Unique identifier for this sandbox instance.
|
|
690
|
+
* Format: `local-{timestamp}-{random}`
|
|
691
|
+
*/
|
|
692
|
+
get id(): string;
|
|
693
|
+
/**
|
|
694
|
+
* Execute a shell command in the local filesystem.
|
|
695
|
+
*
|
|
696
|
+
* Commands are executed using bash with the configured working directory
|
|
697
|
+
* and environment variables. Output is captured from both stdout and stderr.
|
|
698
|
+
*
|
|
699
|
+
* @param command - Shell command to execute
|
|
700
|
+
* @returns ExecuteResponse with output, exit code, and truncation status
|
|
701
|
+
*
|
|
702
|
+
* @example
|
|
703
|
+
* ```typescript
|
|
704
|
+
* const result = await sandbox.execute('echo "Hello" && ls -la');
|
|
705
|
+
* console.log(result.output);
|
|
706
|
+
* console.log('Exit code:', result.exitCode);
|
|
707
|
+
* ```
|
|
708
|
+
*/
|
|
709
|
+
execute(command: string): Promise<ExecuteResponse>;
|
|
710
|
+
}
|
|
711
|
+
//#endregion
|
|
712
|
+
//#region src/tools/subagent.d.ts
|
|
713
|
+
/**
|
|
714
|
+
* Options for creating the subagent tool.
|
|
715
|
+
*/
|
|
716
|
+
interface CreateSubagentToolOptions {
|
|
717
|
+
/** Default model for subagents (AI SDK LanguageModel instance) */
|
|
718
|
+
defaultModel: LanguageModel;
|
|
719
|
+
/** Default tools available to all subagents */
|
|
720
|
+
defaultTools?: ToolSet;
|
|
721
|
+
/** List of custom subagent specifications */
|
|
722
|
+
subagents?: SubAgent[];
|
|
723
|
+
/** Whether to include the general-purpose agent */
|
|
724
|
+
includeGeneralPurposeAgent?: boolean;
|
|
725
|
+
/** Backend for filesystem operations */
|
|
726
|
+
backend?: BackendProtocol | BackendFactory;
|
|
727
|
+
/** Custom description for the task tool */
|
|
728
|
+
taskDescription?: string | null;
|
|
729
|
+
/** Optional callback for emitting events */
|
|
730
|
+
onEvent?: EventCallback;
|
|
731
|
+
/** Interrupt config to pass to subagents */
|
|
732
|
+
interruptOn?: InterruptOnConfig;
|
|
733
|
+
/** Parent agent options to pass through to subagents */
|
|
734
|
+
parentGenerationOptions?: CreateDeepAgentParams["generationOptions"];
|
|
735
|
+
parentAdvancedOptions?: CreateDeepAgentParams["advancedOptions"];
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Create the task tool for spawning subagents using ToolLoopAgent.
|
|
739
|
+
*/
|
|
740
|
+
declare function createSubagentTool(state: DeepAgentState, options: CreateSubagentToolOptions): ai18.Tool<{
|
|
741
|
+
description: string;
|
|
742
|
+
subagent_type: string;
|
|
743
|
+
}, string>;
|
|
744
|
+
//#endregion
|
|
745
|
+
//#region src/prompts.d.ts
|
|
746
|
+
/**
|
|
747
|
+
* System prompts for Deep Agent.
|
|
748
|
+
*/
|
|
749
|
+
declare const BASE_PROMPT = "In order to complete the objective that the user asks of you, you have access to a number of standard tools.";
|
|
750
|
+
declare const TODO_SYSTEM_PROMPT = "## `write_todos` (task planning)\n\nYou have access to a `write_todos` tool to help you manage and plan tasks. Use this tool whenever you are working on a complex task.\n\n### When to Use This Tool\n\nUse proactively for:\n1. Complex multi-step tasks (3+ distinct steps)\n2. Non-trivial tasks requiring careful planning\n3. After receiving new instructions - capture requirements as todos\n4. After completing tasks - mark complete and add follow-ups\n5. When starting new tasks - mark as in_progress (ideally only one at a time)\n\n### When NOT to Use\n\nSkip for:\n1. Single, straightforward tasks\n2. Trivial tasks with no organizational benefit\n3. Tasks completable in < 3 trivial steps\n4. Purely conversational/informational requests\n\n### Task States and Management\n\n1. **Task States:**\n - pending: Not yet started\n - in_progress: Currently working on\n - completed: Finished successfully\n - cancelled: No longer needed\n\n2. **Task Management:**\n - Update status in real-time\n - Mark complete IMMEDIATELY after finishing\n - Only ONE task in_progress at a time\n - Complete current tasks before starting new ones";
|
|
751
|
+
declare const FILESYSTEM_SYSTEM_PROMPT = "## Virtual Filesystem\n\nYou have access to a virtual filesystem. All file paths must start with a /.\n\n- ls: list files in a directory (requires absolute path)\n- read_file: read a file from the filesystem\n- write_file: write to a file in the filesystem\n- edit_file: edit a file in the filesystem\n- glob: find files matching a pattern (e.g., \"**/*.py\")\n- grep: search for text within files";
|
|
752
|
+
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\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\n- Whenever possible, parallelize the work that you do. Whenever you have independent steps to complete - kick off tasks (subagents) in parallel to accomplish them faster.\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.";
|
|
753
|
+
/**
|
|
754
|
+
* Get the task tool description with available subagent types.
|
|
755
|
+
*/
|
|
756
|
+
declare function getTaskToolDescription(subagentDescriptions: string[]): string;
|
|
757
|
+
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.";
|
|
758
|
+
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.";
|
|
759
|
+
declare const EXECUTE_SYSTEM_PROMPT = "## `execute` (shell command execution)\n\nYou have access to an `execute` tool to run shell commands in the sandbox environment.\n\n### When to Use This Tool\n\nUse for:\n- Running build commands (npm install, npm run build, bun install)\n- Running tests (npm test, bun test, pytest)\n- Executing scripts (node script.js, python script.py)\n- Installing dependencies\n- Checking system state (ls, cat, pwd, which)\n- Any shell command that helps accomplish the task\n\n### Important Notes\n\n1. **Exit Codes**: Always check the exit code to determine success\n - 0 = success\n - non-zero = failure\n - null = possibly timed out\n\n2. **Command Chaining**:\n - Use `&&` to chain commands that depend on each other\n - Use `;` to run commands sequentially regardless of success\n\n3. **Timeouts**: Long-running commands may timeout\n\n4. **Working Directory**: Commands run in the sandbox's working directory";
|
|
760
|
+
//#endregion
|
|
761
|
+
//#region src/utils/patch-tool-calls.d.ts
|
|
762
|
+
/**
|
|
763
|
+
* Patch dangling tool calls in a message array.
|
|
764
|
+
*
|
|
765
|
+
* Scans for assistant messages with tool_calls that don't have corresponding
|
|
766
|
+
* tool result messages, and adds synthetic "cancelled" responses.
|
|
767
|
+
*
|
|
768
|
+
* @param messages - Array of messages to patch
|
|
769
|
+
* @returns New array with patched messages (original array is not modified)
|
|
770
|
+
*
|
|
771
|
+
* @example
|
|
772
|
+
* ```typescript
|
|
773
|
+
* const messages = [
|
|
774
|
+
* { role: "user", content: "Hello" },
|
|
775
|
+
* { role: "assistant", content: [{ type: "tool-call", toolCallId: "1", toolName: "search" }] },
|
|
776
|
+
* // Missing tool result for tool call "1"
|
|
777
|
+
* { role: "user", content: "Never mind" },
|
|
778
|
+
* ];
|
|
779
|
+
*
|
|
780
|
+
* const patched = patchToolCalls(messages);
|
|
781
|
+
* // patched now includes a synthetic tool result for the dangling call
|
|
782
|
+
* ```
|
|
783
|
+
*/
|
|
784
|
+
declare function patchToolCalls(messages: ModelMessage[]): ModelMessage[];
|
|
785
|
+
/**
|
|
786
|
+
* Check if messages have any dangling tool calls.
|
|
787
|
+
*
|
|
788
|
+
* @param messages - Array of messages to check
|
|
789
|
+
* @returns True if there are dangling tool calls
|
|
790
|
+
*/
|
|
791
|
+
declare function hasDanglingToolCalls(messages: ModelMessage[]): boolean;
|
|
792
|
+
//#endregion
|
|
793
|
+
//#region src/utils/eviction.d.ts
|
|
794
|
+
/**
|
|
795
|
+
* Default token limit before evicting a tool result.
|
|
796
|
+
* Approximately 20,000 tokens (~80KB of text).
|
|
797
|
+
*/
|
|
798
|
+
declare const DEFAULT_EVICTION_TOKEN_LIMIT = 20000;
|
|
799
|
+
/**
|
|
800
|
+
* Estimate the number of tokens in a string.
|
|
801
|
+
* Uses a simple character-based approximation.
|
|
802
|
+
*/
|
|
803
|
+
declare function estimateTokens(text: string): number;
|
|
804
|
+
/**
|
|
805
|
+
* Check if a tool result should be evicted based on size.
|
|
806
|
+
*/
|
|
807
|
+
declare function shouldEvict(result: string, tokenLimit?: number): boolean;
|
|
808
|
+
/**
|
|
809
|
+
* Options for evicting a tool result.
|
|
810
|
+
*/
|
|
811
|
+
interface EvictOptions {
|
|
812
|
+
/** The tool result content */
|
|
813
|
+
result: string;
|
|
814
|
+
/** The tool call ID (used for filename) */
|
|
815
|
+
toolCallId: string;
|
|
816
|
+
/** The tool name */
|
|
817
|
+
toolName: string;
|
|
818
|
+
/** Backend to write the evicted content to */
|
|
819
|
+
backend: BackendProtocol;
|
|
820
|
+
/** Token limit before eviction (default: 20000) */
|
|
821
|
+
tokenLimit?: number;
|
|
822
|
+
}
|
|
823
|
+
/**
|
|
824
|
+
* Result of an eviction operation.
|
|
825
|
+
*/
|
|
826
|
+
interface EvictResult {
|
|
827
|
+
/** Whether the result was evicted */
|
|
828
|
+
evicted: boolean;
|
|
829
|
+
/** The content to return (either original or truncated message) */
|
|
830
|
+
content: string;
|
|
831
|
+
/** Path where content was evicted to (if evicted) */
|
|
832
|
+
evictedPath?: string;
|
|
833
|
+
}
|
|
834
|
+
/**
|
|
835
|
+
* Evict a large tool result to the filesystem.
|
|
836
|
+
*
|
|
837
|
+
* If the result exceeds the token limit, writes it to a file and
|
|
838
|
+
* returns a truncated message with the file path.
|
|
839
|
+
*
|
|
840
|
+
* @param options - Eviction options
|
|
841
|
+
* @returns Eviction result with content and metadata
|
|
842
|
+
*
|
|
843
|
+
* @example
|
|
844
|
+
* ```typescript
|
|
845
|
+
* const result = await evictToolResult({
|
|
846
|
+
* result: veryLongString,
|
|
847
|
+
* toolCallId: "call_123",
|
|
848
|
+
* toolName: "grep",
|
|
849
|
+
* backend: filesystemBackend,
|
|
850
|
+
* });
|
|
851
|
+
*
|
|
852
|
+
* if (result.evicted) {
|
|
853
|
+
* console.log(`Content saved to ${result.evictedPath}`);
|
|
854
|
+
* }
|
|
855
|
+
* ```
|
|
856
|
+
*/
|
|
857
|
+
declare function evictToolResult(options: EvictOptions): Promise<EvictResult>;
|
|
858
|
+
/**
|
|
859
|
+
* Create a tool result wrapper that automatically evicts large results.
|
|
860
|
+
*
|
|
861
|
+
* @param backend - Backend or factory for filesystem operations
|
|
862
|
+
* @param state - Current agent state (for factory backends)
|
|
863
|
+
* @param tokenLimit - Token limit before eviction
|
|
864
|
+
* @returns Function that wraps tool results with eviction
|
|
865
|
+
*/
|
|
866
|
+
declare function createToolResultWrapper(backend: BackendProtocol | BackendFactory, state: DeepAgentState, tokenLimit?: number): (result: string, toolCallId: string, toolName: string) => Promise<string>;
|
|
867
|
+
//#endregion
|
|
868
|
+
//#region src/utils/summarization.d.ts
|
|
869
|
+
/**
|
|
870
|
+
* Default token threshold before triggering summarization.
|
|
871
|
+
* 170k tokens is a safe threshold for most models.
|
|
872
|
+
*/
|
|
873
|
+
declare const DEFAULT_SUMMARIZATION_THRESHOLD = 170000;
|
|
874
|
+
/**
|
|
875
|
+
* Default number of recent messages to keep intact.
|
|
876
|
+
*/
|
|
877
|
+
declare const DEFAULT_KEEP_MESSAGES = 6;
|
|
878
|
+
/**
|
|
879
|
+
* Options for summarization.
|
|
880
|
+
*/
|
|
881
|
+
interface SummarizationOptions {
|
|
882
|
+
/** Model to use for summarization (AI SDK LanguageModel instance) */
|
|
883
|
+
model: LanguageModel;
|
|
884
|
+
/** Token threshold to trigger summarization (default: 170000) */
|
|
885
|
+
tokenThreshold?: number;
|
|
886
|
+
/** Number of recent messages to keep intact (default: 6) */
|
|
887
|
+
keepMessages?: number;
|
|
888
|
+
/** Generation options to pass through */
|
|
889
|
+
generationOptions?: any;
|
|
890
|
+
/** Advanced options to pass through */
|
|
891
|
+
advancedOptions?: any;
|
|
892
|
+
}
|
|
893
|
+
/**
|
|
894
|
+
* Result of summarization check.
|
|
895
|
+
*/
|
|
896
|
+
interface SummarizationResult {
|
|
897
|
+
/** Whether summarization was needed */
|
|
898
|
+
summarized: boolean;
|
|
899
|
+
/** The processed messages (either original or with summary) */
|
|
900
|
+
messages: ModelMessage$1[];
|
|
901
|
+
/** Token count before processing */
|
|
902
|
+
tokensBefore?: number;
|
|
903
|
+
/** Token count after processing */
|
|
904
|
+
tokensAfter?: number;
|
|
905
|
+
}
|
|
906
|
+
/**
|
|
907
|
+
* Estimate total tokens in a messages array.
|
|
908
|
+
*/
|
|
909
|
+
declare function estimateMessagesTokens(messages: ModelMessage$1[]): number;
|
|
910
|
+
/**
|
|
911
|
+
* Summarize older messages when approaching token limits.
|
|
912
|
+
*
|
|
913
|
+
* This function checks if the total tokens in the messages exceed the threshold.
|
|
914
|
+
* If so, it summarizes older messages while keeping recent ones intact.
|
|
915
|
+
*
|
|
916
|
+
* @param messages - Array of conversation messages
|
|
917
|
+
* @param options - Summarization options
|
|
918
|
+
* @returns Processed messages with optional summary
|
|
919
|
+
*
|
|
920
|
+
* @example
|
|
921
|
+
* ```typescript
|
|
922
|
+
* import { anthropic } from '@ai-sdk/anthropic';
|
|
923
|
+
*
|
|
924
|
+
* const result = await summarizeIfNeeded(messages, {
|
|
925
|
+
* model: anthropic('claude-haiku-4-5-20251001'),
|
|
926
|
+
* tokenThreshold: 170000,
|
|
927
|
+
* keepMessages: 6,
|
|
928
|
+
* });
|
|
929
|
+
*
|
|
930
|
+
* if (result.summarized) {
|
|
931
|
+
* console.log(`Reduced from ${result.tokensBefore} to ${result.tokensAfter} tokens`);
|
|
932
|
+
* }
|
|
933
|
+
* ```
|
|
934
|
+
*/
|
|
935
|
+
declare function summarizeIfNeeded(messages: ModelMessage$1[], options: SummarizationOptions): Promise<SummarizationResult>;
|
|
936
|
+
/**
|
|
937
|
+
* Check if messages need summarization without performing it.
|
|
938
|
+
*/
|
|
939
|
+
declare function needsSummarization(messages: ModelMessage$1[], tokenThreshold?: number): boolean;
|
|
940
|
+
//#endregion
|
|
941
|
+
//#region src/checkpointer/memory-saver.d.ts
|
|
942
|
+
/**
|
|
943
|
+
* In-memory checkpoint saver.
|
|
944
|
+
*
|
|
945
|
+
* Stores checkpoints in a Map. Data is lost when the process exits.
|
|
946
|
+
* Useful for testing or single-session applications.
|
|
947
|
+
*
|
|
948
|
+
* @example
|
|
949
|
+
* ```typescript
|
|
950
|
+
* const saver = new MemorySaver();
|
|
951
|
+
* const agent = createDeepAgent({
|
|
952
|
+
* model: anthropic('claude-sonnet-4-20250514'),
|
|
953
|
+
* checkpointer: saver,
|
|
954
|
+
* });
|
|
955
|
+
* ```
|
|
956
|
+
*/
|
|
957
|
+
declare class MemorySaver implements BaseCheckpointSaver {
|
|
958
|
+
private checkpoints;
|
|
959
|
+
private namespace;
|
|
960
|
+
constructor(options?: CheckpointSaverOptions);
|
|
961
|
+
private getKey;
|
|
962
|
+
save(checkpoint: Checkpoint): Promise<void>;
|
|
963
|
+
load(threadId: string): Promise<Checkpoint | undefined>;
|
|
964
|
+
list(): Promise<string[]>;
|
|
965
|
+
delete(threadId: string): Promise<void>;
|
|
966
|
+
exists(threadId: string): Promise<boolean>;
|
|
967
|
+
/**
|
|
968
|
+
* Clear all checkpoints (useful for testing).
|
|
969
|
+
*/
|
|
970
|
+
clear(): void;
|
|
971
|
+
/**
|
|
972
|
+
* Get the number of stored checkpoints.
|
|
973
|
+
*/
|
|
974
|
+
size(): number;
|
|
975
|
+
}
|
|
976
|
+
//#endregion
|
|
977
|
+
//#region src/checkpointer/file-saver.d.ts
|
|
978
|
+
/**
|
|
979
|
+
* Options for FileSaver.
|
|
980
|
+
*/
|
|
981
|
+
interface FileSaverOptions {
|
|
982
|
+
/** Directory to store checkpoint files */
|
|
983
|
+
dir: string;
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* File-based checkpoint saver.
|
|
987
|
+
*
|
|
988
|
+
* Stores checkpoints as JSON files in a directory. Each thread gets
|
|
989
|
+
* its own file named `{threadId}.json`.
|
|
990
|
+
*
|
|
991
|
+
* @example
|
|
992
|
+
* ```typescript
|
|
993
|
+
* const saver = new FileSaver({ dir: './.checkpoints' });
|
|
994
|
+
* const agent = createDeepAgent({
|
|
995
|
+
* model: anthropic('claude-sonnet-4-20250514'),
|
|
996
|
+
* checkpointer: saver,
|
|
997
|
+
* });
|
|
998
|
+
* ```
|
|
999
|
+
*/
|
|
1000
|
+
declare class FileSaver implements BaseCheckpointSaver {
|
|
1001
|
+
private dir;
|
|
1002
|
+
constructor(options: FileSaverOptions);
|
|
1003
|
+
private getFilePath;
|
|
1004
|
+
save(checkpoint: Checkpoint): Promise<void>;
|
|
1005
|
+
load(threadId: string): Promise<Checkpoint | undefined>;
|
|
1006
|
+
list(): Promise<string[]>;
|
|
1007
|
+
delete(threadId: string): Promise<void>;
|
|
1008
|
+
exists(threadId: string): Promise<boolean>;
|
|
1009
|
+
}
|
|
1010
|
+
//#endregion
|
|
1011
|
+
//#region src/checkpointer/kv-saver.d.ts
|
|
1012
|
+
/**
|
|
1013
|
+
* Options for KeyValueStoreSaver.
|
|
1014
|
+
*/
|
|
1015
|
+
interface KeyValueStoreSaverOptions extends CheckpointSaverOptions {
|
|
1016
|
+
/** The KeyValueStore implementation to use */
|
|
1017
|
+
store: KeyValueStore;
|
|
1018
|
+
}
|
|
1019
|
+
/**
|
|
1020
|
+
* Checkpoint saver using KeyValueStore interface.
|
|
1021
|
+
*
|
|
1022
|
+
* This adapter allows using any KeyValueStore implementation (Redis,
|
|
1023
|
+
* database, cloud storage, etc.) for checkpoint storage.
|
|
1024
|
+
*
|
|
1025
|
+
* @example
|
|
1026
|
+
* ```typescript
|
|
1027
|
+
* import { InMemoryStore } from 'deepagentsdk';
|
|
1028
|
+
*
|
|
1029
|
+
* const store = new InMemoryStore();
|
|
1030
|
+
* const saver = new KeyValueStoreSaver({ store });
|
|
1031
|
+
* const agent = createDeepAgent({
|
|
1032
|
+
* model: anthropic('claude-sonnet-4-20250514'),
|
|
1033
|
+
* checkpointer: saver,
|
|
1034
|
+
* });
|
|
1035
|
+
* ```
|
|
1036
|
+
*
|
|
1037
|
+
* @example With Redis
|
|
1038
|
+
* ```typescript
|
|
1039
|
+
* const redisStore = new RedisStore(redisClient); // Your implementation
|
|
1040
|
+
* const saver = new KeyValueStoreSaver({ store: redisStore });
|
|
1041
|
+
* ```
|
|
1042
|
+
*/
|
|
1043
|
+
declare class KeyValueStoreSaver implements BaseCheckpointSaver {
|
|
1044
|
+
private store;
|
|
1045
|
+
private namespace;
|
|
1046
|
+
constructor(options: KeyValueStoreSaverOptions);
|
|
1047
|
+
save(checkpoint: Checkpoint): Promise<void>;
|
|
1048
|
+
load(threadId: string): Promise<Checkpoint | undefined>;
|
|
1049
|
+
list(): Promise<string[]>;
|
|
1050
|
+
delete(threadId: string): Promise<void>;
|
|
1051
|
+
exists(threadId: string): Promise<boolean>;
|
|
1052
|
+
}
|
|
1053
|
+
//#endregion
|
|
1054
|
+
//#region src/skills/types.d.ts
|
|
1055
|
+
/**
|
|
1056
|
+
* Metadata extracted from SKILL.md frontmatter.
|
|
1057
|
+
*/
|
|
1058
|
+
interface SkillMetadata {
|
|
1059
|
+
/**
|
|
1060
|
+
* Unique skill name (kebab-case, e.g., 'web-research')
|
|
1061
|
+
*/
|
|
1062
|
+
name: string;
|
|
1063
|
+
/**
|
|
1064
|
+
* Short description of what the skill does
|
|
1065
|
+
*/
|
|
1066
|
+
description: string;
|
|
1067
|
+
/**
|
|
1068
|
+
* Absolute path to the SKILL.md file
|
|
1069
|
+
*/
|
|
1070
|
+
path: string;
|
|
1071
|
+
/**
|
|
1072
|
+
* Source of the skill ('user' or 'project')
|
|
1073
|
+
* Project skills override user skills with same name
|
|
1074
|
+
*/
|
|
1075
|
+
source: 'user' | 'project';
|
|
1076
|
+
}
|
|
1077
|
+
/**
|
|
1078
|
+
* Options for skill loading
|
|
1079
|
+
*/
|
|
1080
|
+
interface SkillLoadOptions {
|
|
1081
|
+
/**
|
|
1082
|
+
* User-level skills directory (e.g., ~/.deepagents/skills/)
|
|
1083
|
+
*/
|
|
1084
|
+
userSkillsDir?: string;
|
|
1085
|
+
/**
|
|
1086
|
+
* Project-level skills directory (e.g., ./.deepagents/skills/)
|
|
1087
|
+
*/
|
|
1088
|
+
projectSkillsDir?: string;
|
|
1089
|
+
/**
|
|
1090
|
+
* Optional agent ID for loading agent-specific skills.
|
|
1091
|
+
* When provided, looks for skills in ~/.deepagents/{agentId}/skills/
|
|
1092
|
+
* and .deepagents/skills/ (project-level, shared across agents).
|
|
1093
|
+
*/
|
|
1094
|
+
agentId?: string;
|
|
1095
|
+
/**
|
|
1096
|
+
* Optional working directory for detecting project root.
|
|
1097
|
+
* Only used when agentId is provided.
|
|
1098
|
+
*/
|
|
1099
|
+
workingDirectory?: string;
|
|
1100
|
+
}
|
|
1101
|
+
//#endregion
|
|
1102
|
+
//#region src/skills/load.d.ts
|
|
1103
|
+
/**
|
|
1104
|
+
* Parse YAML frontmatter from a SKILL.md file.
|
|
1105
|
+
*
|
|
1106
|
+
* Expected format:
|
|
1107
|
+
* ---
|
|
1108
|
+
* name: skill-name
|
|
1109
|
+
* description: What this skill does
|
|
1110
|
+
* ---
|
|
1111
|
+
*
|
|
1112
|
+
* # Skill Content
|
|
1113
|
+
* ...
|
|
1114
|
+
*/
|
|
1115
|
+
declare function parseSkillMetadata(skillMdPath: string, source: 'user' | 'project'): Promise<SkillMetadata | null>;
|
|
1116
|
+
/**
|
|
1117
|
+
* List all skills from user and project directories.
|
|
1118
|
+
* Project skills override user skills with the same name.
|
|
1119
|
+
*
|
|
1120
|
+
* Supports two modes:
|
|
1121
|
+
* 1. Legacy mode: Use userSkillsDir and projectSkillsDir directly (deprecated)
|
|
1122
|
+
* 2. Agent mode: Use agentId to load from ~/.deepagents/{agentId}/skills/ and .deepagents/skills/
|
|
1123
|
+
*/
|
|
1124
|
+
declare function listSkills(options: SkillLoadOptions): Promise<SkillMetadata[]>;
|
|
1125
|
+
//#endregion
|
|
1126
|
+
//#region src/middleware/agent-memory.d.ts
|
|
1127
|
+
/**
|
|
1128
|
+
* Configuration options for agent memory middleware.
|
|
1129
|
+
*/
|
|
1130
|
+
interface AgentMemoryOptions$1 {
|
|
1131
|
+
/**
|
|
1132
|
+
* Unique identifier for the agent (e.g., "code-architect", "research-agent").
|
|
1133
|
+
* Used to locate agent-specific memory at ~/.deepagents/{agentId}/agent.md
|
|
1134
|
+
*/
|
|
1135
|
+
agentId: string;
|
|
1136
|
+
/**
|
|
1137
|
+
* Optional working directory for project-level memory detection.
|
|
1138
|
+
* Defaults to process.cwd().
|
|
1139
|
+
*/
|
|
1140
|
+
workingDirectory?: string;
|
|
1141
|
+
/**
|
|
1142
|
+
* Optional custom path for user-level .deepagents directory.
|
|
1143
|
+
* Defaults to os.homedir() + '/.deepagents'.
|
|
1144
|
+
*
|
|
1145
|
+
* Useful for testing or custom deployment environments.
|
|
1146
|
+
*
|
|
1147
|
+
* @example
|
|
1148
|
+
* ```typescript
|
|
1149
|
+
* userDeepagentsDir: '/custom/path/.deepagents'
|
|
1150
|
+
* // Will look for memory at: /custom/path/.deepagents/{agentId}/agent.md
|
|
1151
|
+
* ```
|
|
1152
|
+
*/
|
|
1153
|
+
userDeepagentsDir?: string;
|
|
1154
|
+
/**
|
|
1155
|
+
* Optional callback to request user approval for creating project-level .deepagents/ directory.
|
|
1156
|
+
* If not provided, project memory will be silently skipped if directory doesn't exist.
|
|
1157
|
+
*
|
|
1158
|
+
* @param projectPath - Absolute path to the detected git root
|
|
1159
|
+
* @returns Promise<boolean> - true if user approves, false otherwise
|
|
1160
|
+
*/
|
|
1161
|
+
requestProjectApproval?: (projectPath: string) => Promise<boolean>;
|
|
1162
|
+
}
|
|
1163
|
+
/**
|
|
1164
|
+
* Create agent memory middleware for AI SDK v6.
|
|
1165
|
+
*
|
|
1166
|
+
* This middleware loads agent memory from:
|
|
1167
|
+
* 1. User-level: ~/.deepagents/{agentId}/agent.md (personality, preferences)
|
|
1168
|
+
* 2. Project-level: [git-root]/.deepagents/agent.md (project-specific context)
|
|
1169
|
+
* 3. Additional files: Any other .md files in the user-level directory
|
|
1170
|
+
*
|
|
1171
|
+
* The memory is injected into the system prompt before each model call, teaching
|
|
1172
|
+
* the agent when and how to read/update its own memory using filesystem tools.
|
|
1173
|
+
*
|
|
1174
|
+
* @param options - Configuration for agent memory
|
|
1175
|
+
* @param options.agentId - Unique identifier for the agent (e.g., "code-architect")
|
|
1176
|
+
* @param options.workingDirectory - Optional working directory for project detection (defaults to process.cwd())
|
|
1177
|
+
* @param options.userDeepagentsDir - Optional custom path for user-level .deepagents directory (defaults to ~/.deepagents)
|
|
1178
|
+
* @param options.requestProjectApproval - Optional callback to request approval before creating project .deepagents/ directory
|
|
1179
|
+
* @returns AI SDK v6 middleware
|
|
1180
|
+
*
|
|
1181
|
+
* @example Basic usage
|
|
1182
|
+
* ```typescript
|
|
1183
|
+
* import { createDeepAgent } from 'deepagentsdk';
|
|
1184
|
+
* import { createAgentMemoryMiddleware } from 'deepagentsdk/middleware';
|
|
1185
|
+
* import { anthropic } from '@ai-sdk/anthropic';
|
|
1186
|
+
*
|
|
1187
|
+
* const memoryMiddleware = createAgentMemoryMiddleware({
|
|
1188
|
+
* agentId: 'code-architect',
|
|
1189
|
+
* });
|
|
1190
|
+
*
|
|
1191
|
+
* const agent = createDeepAgent({
|
|
1192
|
+
* model: anthropic('claude-sonnet-4-5'),
|
|
1193
|
+
* middleware: memoryMiddleware,
|
|
1194
|
+
* });
|
|
1195
|
+
* ```
|
|
1196
|
+
*
|
|
1197
|
+
* @example With project approval callback
|
|
1198
|
+
* ```typescript
|
|
1199
|
+
* const memoryMiddleware = createAgentMemoryMiddleware({
|
|
1200
|
+
* agentId: 'code-architect',
|
|
1201
|
+
* requestProjectApproval: async (projectPath) => {
|
|
1202
|
+
* console.log(`Create .deepagents/ in ${projectPath}? (y/n)`);
|
|
1203
|
+
* // ... get user input
|
|
1204
|
+
* return userSaidYes;
|
|
1205
|
+
* }
|
|
1206
|
+
* });
|
|
1207
|
+
* ```
|
|
1208
|
+
*
|
|
1209
|
+
* @example With custom user directory path
|
|
1210
|
+
* ```typescript
|
|
1211
|
+
* const memoryMiddleware = createAgentMemoryMiddleware({
|
|
1212
|
+
* agentId: 'code-architect',
|
|
1213
|
+
* userDeepagentsDir: '/custom/path/.deepagents',
|
|
1214
|
+
* // Memory will be loaded from:
|
|
1215
|
+
* // - /custom/path/.deepagents/code-architect/agent.md
|
|
1216
|
+
* // - [git-root]/.deepagents/agent.md (project-level)
|
|
1217
|
+
* });
|
|
1218
|
+
* ```
|
|
1219
|
+
*/
|
|
1220
|
+
declare function createAgentMemoryMiddleware(options: AgentMemoryOptions$1): LanguageModelMiddleware$1;
|
|
1221
|
+
//#endregion
|
|
1222
|
+
//#region src/utils/project-detection.d.ts
|
|
1223
|
+
/**
|
|
1224
|
+
* Find the git root by walking up the directory tree.
|
|
1225
|
+
* Returns null if no .git directory is found.
|
|
1226
|
+
*
|
|
1227
|
+
* @param startPath - Starting directory (defaults to process.cwd())
|
|
1228
|
+
* @returns Absolute path to git root, or null if not in a git repository
|
|
1229
|
+
*/
|
|
1230
|
+
declare function findGitRoot(startPath?: string): Promise<string | null>;
|
|
1231
|
+
//#endregion
|
|
1232
|
+
export { type AgentMemoryOptions, type ApprovalRequestedEvent, type ApprovalResponseEvent, BASE_PROMPT, type BackendFactory, type BackendProtocol, BaseCheckpointSaver, BaseSandbox, Checkpoint, type CheckpointLoadedEvent, type CheckpointSavedEvent, CheckpointSaverOptions, CompositeBackend, type CreateDeepAgentParams, type CreateExecuteToolOptions, type CreateSubagentToolOptions, type CreateWebToolsOptions, DEFAULT_EVICTION_TOKEN_LIMIT, DEFAULT_GENERAL_PURPOSE_DESCRIPTION, DEFAULT_KEEP_MESSAGES, DEFAULT_SUBAGENT_PROMPT, DEFAULT_SUMMARIZATION_THRESHOLD, DeepAgent, type DeepAgentEvent, type DeepAgentState, type DoneEvent, type DynamicApprovalConfig, EXECUTE_SYSTEM_PROMPT, type EditResult, type ErrorEvent, type EventCallback, type EvictOptions, type EvictResult, type ExecuteFinishEvent, type ExecuteResponse, type ExecuteStartEvent, FILESYSTEM_SYSTEM_PROMPT, type FetchUrlFinishEvent, type FetchUrlStartEvent, type FileData, type FileEditedEvent, type FileInfo, FileSaver, FileSaverOptions, type FileWriteStartEvent, type FileWrittenEvent, FilesystemBackend, type GrepMatch, type HttpRequestFinishEvent, type HttpRequestStartEvent, InMemoryStore, InterruptData, type InterruptOnConfig, type KeyValueStore, KeyValueStoreSaver, KeyValueStoreSaverOptions, type LanguageModelMiddleware, LocalSandbox, type LocalSandboxOptions, MemorySaver, PersistentBackend, type PersistentBackendOptions, ResumeDecision, ResumeOptions, type SandboxBackendProtocol, type SkillLoadOptions, type SkillMetadata, StateBackend, type StepFinishEvent, type StepStartEvent, type StructuredAgentResult, type SubAgent, type SubagentFinishEvent, type SubagentStartEvent, type SummarizationConfig, type SummarizationOptions, type SummarizationResult, TASK_SYSTEM_PROMPT, TODO_SYSTEM_PROMPT, type TextEvent, type TodoItem, type TodosChangedEvent, type ToolCallEvent, ToolLoopAgent, type ToolResultEvent, type WebSearchFinishEvent, type WebSearchStartEvent, type WriteResult, createAgentMemoryMiddleware, createDeepAgent, createEditFileTool, createExecuteTool, createExecuteToolFromBackend, createFetchUrlTool, createFilesystemTools, createGlobTool, createGrepTool, createHttpRequestTool, createLsTool, createReadFileTool, createSubagentTool, createTodosTool, createToolResultWrapper, createWebSearchTool, createWebTools, createWriteFileTool, edit_file, estimateMessagesTokens, estimateTokens, eventHasStructuredOutput, evictToolResult, execute, fetch_url, findGitRoot, getEventOutput, getStructuredOutput, getTaskToolDescription, glob, grep, hasDanglingToolCalls, hasStructuredOutput, hasToolCall, htmlToMarkdown, http_request, isSandboxBackend, listSkills, ls, needsSummarization, parseSkillMetadata, patchToolCalls, read_file, shouldEvict, stepCountIs, summarizeIfNeeded, web_search, wrapLanguageModel, write_file, write_todos };
|
|
1233
|
+
//# sourceMappingURL=index.d.cts.map
|