deepagents 1.9.1 → 1.10.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 +363 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +273 -15
- package/dist/index.d.ts +273 -15
- package/dist/index.js +354 -10
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AIMessage, HumanMessage, SystemMessage, ToolMessage, anthropicPromptCachingMiddleware, context, countTokensApproximately, createAgent, createMiddleware, humanInTheLoopMiddleware, todoListMiddleware, tool } from "langchain";
|
|
2
|
-
import { Command, REMOVE_ALL_MESSAGES, ReducedValue, StateSchema, getConfig, getCurrentTaskInput, getStore, isCommand } from "@langchain/langgraph";
|
|
2
|
+
import { ChatModelStreamImpl, Command, REMOVE_ALL_MESSAGES, ReducedValue, StateSchema, StreamChannel, getConfig, getCurrentTaskInput, getStore, isCommand } from "@langchain/langgraph";
|
|
3
3
|
import { z } from "zod/v4";
|
|
4
4
|
import micromatch from "micromatch";
|
|
5
5
|
import path, { basename } from "path";
|
|
@@ -2438,6 +2438,13 @@ function createPatchToolCallsMiddleware() {
|
|
|
2438
2438
|
if (!needsPatch) return;
|
|
2439
2439
|
return { messages: [new RemoveMessage({ id: REMOVE_ALL_MESSAGES }), ...patchedMessages] };
|
|
2440
2440
|
},
|
|
2441
|
+
/**
|
|
2442
|
+
* Also patch in wrapModelCall as a safety net.
|
|
2443
|
+
* This handles edge cases where:
|
|
2444
|
+
* - HITL rejects a tool call during graph resume
|
|
2445
|
+
* - The state update from beforeAgent might not be applied in time
|
|
2446
|
+
* - The model would otherwise receive dangling tool_call_ids
|
|
2447
|
+
*/
|
|
2441
2448
|
wrapModelCall: async (request, handler) => {
|
|
2442
2449
|
const messages = request.messages;
|
|
2443
2450
|
if (!messages || messages.length === 0) return handler(request);
|
|
@@ -2539,6 +2546,10 @@ const filesValue = new ReducedValue(z$1.record(z$1.string(), FileDataSchema).def
|
|
|
2539
2546
|
* State schema for memory middleware.
|
|
2540
2547
|
*/
|
|
2541
2548
|
const MemoryStateSchema = new StateSchema({
|
|
2549
|
+
/**
|
|
2550
|
+
* Dict mapping source paths to their loaded content.
|
|
2551
|
+
* Marked as private so it's not included in the final agent state.
|
|
2552
|
+
*/
|
|
2542
2553
|
memoryContents: z$1.record(z$1.string(), z$1.string()).optional(),
|
|
2543
2554
|
files: filesValue
|
|
2544
2555
|
});
|
|
@@ -3247,7 +3258,9 @@ const CALLBACK_THREAD_ID_KEY = "callbackThreadId";
|
|
|
3247
3258
|
* and read by `CompletionCallbackMiddleware` when sending callback
|
|
3248
3259
|
* notifications.
|
|
3249
3260
|
*/
|
|
3250
|
-
const CompletionCallbackStateSchema = z$2.object({
|
|
3261
|
+
const CompletionCallbackStateSchema = z$2.object({
|
|
3262
|
+
/** The callback thread ID. Used to address the notification. */
|
|
3263
|
+
[CALLBACK_THREAD_ID_KEY]: z$2.string().optional() });
|
|
3251
3264
|
/**
|
|
3252
3265
|
* Build headers for the callback LangGraph server.
|
|
3253
3266
|
*
|
|
@@ -3365,12 +3378,25 @@ function createCompletionCallbackMiddleware(options) {
|
|
|
3365
3378
|
return createMiddleware({
|
|
3366
3379
|
name: "CompletionCallbackMiddleware",
|
|
3367
3380
|
stateSchema: CompletionCallbackStateSchema,
|
|
3381
|
+
/**
|
|
3382
|
+
* After-agent hook: fires when the subagent completes successfully.
|
|
3383
|
+
*
|
|
3384
|
+
* Extracts the last message as a summary and sends it to the callback
|
|
3385
|
+
* thread.
|
|
3386
|
+
*/
|
|
3368
3387
|
async afterAgent(state, runtime) {
|
|
3369
3388
|
const callbackThreadId = state[CALLBACK_THREAD_ID_KEY];
|
|
3370
3389
|
if (callbackThreadId == null) throw new Error(`Missing required state key '${CALLBACK_THREAD_ID_KEY}'`);
|
|
3371
3390
|
const taskId = getTaskId(runtime);
|
|
3372
3391
|
await sendNotification(callbackThreadId, formatNotification(`Completed. Result: ${extractLastMessage(state, typeof taskId === "string" ? taskId : void 0)}`, runtime));
|
|
3373
3392
|
},
|
|
3393
|
+
/**
|
|
3394
|
+
* Wrap model calls to catch errors and notify the callback thread.
|
|
3395
|
+
*
|
|
3396
|
+
* If a model call raises an exception, a generic error message is
|
|
3397
|
+
* reported to the callback thread before re-raising. The actual error
|
|
3398
|
+
* details are not leaked to the callback agent.
|
|
3399
|
+
*/
|
|
3374
3400
|
async wrapModelCall(request, handler) {
|
|
3375
3401
|
try {
|
|
3376
3402
|
return await handler(request);
|
|
@@ -3504,15 +3530,22 @@ Summary:`;
|
|
|
3504
3530
|
* list on subsequent calls.
|
|
3505
3531
|
*/
|
|
3506
3532
|
const SummarizationEventSchema = z$1.object({
|
|
3533
|
+
/**
|
|
3534
|
+
* The index in the state messages list where summarization occurred.
|
|
3535
|
+
* Messages before this index have been summarized. */
|
|
3507
3536
|
cutoffIndex: z$1.number(),
|
|
3537
|
+
/** The HumanMessage containing the summary. */
|
|
3508
3538
|
summaryMessage: z$1.instanceof(HumanMessage),
|
|
3539
|
+
/** Path where the conversation history was offloaded, or null if offload failed. */
|
|
3509
3540
|
filePath: z$1.string().nullable()
|
|
3510
3541
|
});
|
|
3511
3542
|
/**
|
|
3512
3543
|
* State schema for summarization middleware.
|
|
3513
3544
|
*/
|
|
3514
3545
|
const SummarizationStateSchema = z$1.object({
|
|
3546
|
+
/** Session ID for history file naming */
|
|
3515
3547
|
_summarizationSessionId: z$1.string().optional(),
|
|
3548
|
+
/** Most recent summarization event (private state, not visible to agent) */
|
|
3516
3549
|
_summarizationEvent: SummarizationEventSchema.optional()
|
|
3517
3550
|
});
|
|
3518
3551
|
/**
|
|
@@ -6392,7 +6425,7 @@ var BaseSandbox = class {
|
|
|
6392
6425
|
* ```typescript
|
|
6393
6426
|
* import { LangSmithSandbox, createDeepAgent } from "deepagents";
|
|
6394
6427
|
*
|
|
6395
|
-
* const sandbox = await LangSmithSandbox.create({
|
|
6428
|
+
* const sandbox = await LangSmithSandbox.create({ snapshotId: "your-snapshot-id" });
|
|
6396
6429
|
*
|
|
6397
6430
|
* const agent = createDeepAgent({ model, backend: sandbox });
|
|
6398
6431
|
*
|
|
@@ -6516,6 +6549,41 @@ var LangSmithSandbox = class LangSmithSandbox extends BaseSandbox {
|
|
|
6516
6549
|
this.#isRunning = false;
|
|
6517
6550
|
}
|
|
6518
6551
|
/**
|
|
6552
|
+
* Start a stopped sandbox and wait until it is ready.
|
|
6553
|
+
*
|
|
6554
|
+
* After calling this, `isRunning` will be `true` and the sandbox
|
|
6555
|
+
* can be used for command execution and file operations again.
|
|
6556
|
+
*
|
|
6557
|
+
* @param options - Start options (timeout, signal).
|
|
6558
|
+
*/
|
|
6559
|
+
async start(options = {}) {
|
|
6560
|
+
await this.#sandbox.start(options);
|
|
6561
|
+
this.#isRunning = true;
|
|
6562
|
+
}
|
|
6563
|
+
/**
|
|
6564
|
+
* Stop the sandbox without deleting it.
|
|
6565
|
+
*
|
|
6566
|
+
* Sandbox files are preserved and the sandbox can be restarted later
|
|
6567
|
+
* with `start()`. After calling this, `isRunning` will be `false`.
|
|
6568
|
+
*/
|
|
6569
|
+
async stop() {
|
|
6570
|
+
await this.#sandbox.stop();
|
|
6571
|
+
this.#isRunning = false;
|
|
6572
|
+
}
|
|
6573
|
+
/**
|
|
6574
|
+
* Capture a snapshot from this running sandbox.
|
|
6575
|
+
*
|
|
6576
|
+
* Snapshots can be used to create new sandboxes via
|
|
6577
|
+
* `LangSmithSandbox.create({ snapshotId })`.
|
|
6578
|
+
*
|
|
6579
|
+
* @param name - Name for the snapshot.
|
|
6580
|
+
* @param options - Capture options (checkpoint, timeout).
|
|
6581
|
+
* @returns The created Snapshot in "ready" status.
|
|
6582
|
+
*/
|
|
6583
|
+
async captureSnapshot(name, options = {}) {
|
|
6584
|
+
return this.#sandbox.captureSnapshot(name, options);
|
|
6585
|
+
}
|
|
6586
|
+
/**
|
|
6519
6587
|
* Create and return a new LangSmithSandbox in one step.
|
|
6520
6588
|
*
|
|
6521
6589
|
* This is the recommended way to create a sandbox — no need to import
|
|
@@ -6523,7 +6591,10 @@ var LangSmithSandbox = class LangSmithSandbox extends BaseSandbox {
|
|
|
6523
6591
|
*
|
|
6524
6592
|
* @example
|
|
6525
6593
|
* ```typescript
|
|
6526
|
-
* const sandbox = await LangSmithSandbox.create({
|
|
6594
|
+
* const sandbox = await LangSmithSandbox.create({
|
|
6595
|
+
* snapshotId: "abc-123",
|
|
6596
|
+
* });
|
|
6597
|
+
*
|
|
6527
6598
|
* try {
|
|
6528
6599
|
* const agent = createDeepAgent({ model, backend: sandbox });
|
|
6529
6600
|
* await agent.invoke({ messages: [...] });
|
|
@@ -6532,10 +6603,14 @@ var LangSmithSandbox = class LangSmithSandbox extends BaseSandbox {
|
|
|
6532
6603
|
* }
|
|
6533
6604
|
* ```
|
|
6534
6605
|
*/
|
|
6535
|
-
static async create(options
|
|
6536
|
-
const { templateName
|
|
6606
|
+
static async create(options) {
|
|
6607
|
+
const { templateName, apiKey = process.env.LANGSMITH_API_KEY, defaultTimeout, snapshotId, ...createSandboxOptions } = options;
|
|
6608
|
+
if (snapshotId && templateName) throw new Error("snapshotId and templateName are mutually exclusive. Pass only one creation source.");
|
|
6609
|
+
if (!snapshotId && !templateName) throw new Error("Either snapshotId or templateName is required. snapshotId is recommended — template-based creation is deprecated.");
|
|
6610
|
+
const sandboxOptions = { ...createSandboxOptions };
|
|
6611
|
+
if (templateName) sandboxOptions.snapshotName = templateName;
|
|
6537
6612
|
return new LangSmithSandbox({
|
|
6538
|
-
sandbox: await new SandboxClient({ apiKey }).createSandbox(
|
|
6613
|
+
sandbox: await new SandboxClient({ apiKey }).createSandbox(snapshotId, sandboxOptions),
|
|
6539
6614
|
defaultTimeout
|
|
6540
6615
|
});
|
|
6541
6616
|
}
|
|
@@ -6622,6 +6697,271 @@ function createCacheBreakpointMiddleware() {
|
|
|
6622
6697
|
});
|
|
6623
6698
|
}
|
|
6624
6699
|
//#endregion
|
|
6700
|
+
//#region src/stream.ts
|
|
6701
|
+
/**
|
|
6702
|
+
* Deep Agent streaming support (experimental).
|
|
6703
|
+
*
|
|
6704
|
+
* Provides:
|
|
6705
|
+
* - `DeepAgentRunStream` — type overlay that adds `.subagents` to the
|
|
6706
|
+
* `AgentRunStream` shape
|
|
6707
|
+
* - `createSubagentTransformer` — a `__native` transformer whose
|
|
6708
|
+
* projection (`subagents`) lands directly on the `GraphRunStream`
|
|
6709
|
+
* instance via langgraph-core's native transformer support
|
|
6710
|
+
*
|
|
6711
|
+
* See protocol proposal §15 (In-Process Streaming Interface) and §16
|
|
6712
|
+
* (Native Stream Transformers).
|
|
6713
|
+
*/
|
|
6714
|
+
function hasPrefix(ns, prefix) {
|
|
6715
|
+
if (prefix.length > ns.length) return false;
|
|
6716
|
+
for (let i = 0; i < prefix.length; i += 1) if (ns[i] !== prefix[i]) return false;
|
|
6717
|
+
return true;
|
|
6718
|
+
}
|
|
6719
|
+
/**
|
|
6720
|
+
* Native transformer that correlates `task` tool calls into
|
|
6721
|
+
* {@link SubagentRunStream} objects and routes child-namespace
|
|
6722
|
+
* `tools` and `messages` events into per-subagent channels.
|
|
6723
|
+
*
|
|
6724
|
+
* Marked `__native: true` — the `subagents` projection key lands
|
|
6725
|
+
* directly on the `GraphRunStream` instance as `run.subagents`.
|
|
6726
|
+
*/
|
|
6727
|
+
function createSubagentTransformer(path) {
|
|
6728
|
+
return () => {
|
|
6729
|
+
const subagentsLog = StreamChannel.local();
|
|
6730
|
+
const pendingByCallId = /* @__PURE__ */ new Map();
|
|
6731
|
+
const pendingByNamespaceSegment = /* @__PURE__ */ new Map();
|
|
6732
|
+
const latestValuesByNamespaceSegment = /* @__PURE__ */ new Map();
|
|
6733
|
+
const subagentsByName = /* @__PURE__ */ new Map();
|
|
6734
|
+
/** Maps tools-node namespace segment to subagent name. */
|
|
6735
|
+
const toolsNodeToName = /* @__PURE__ */ new Map();
|
|
6736
|
+
const childToolCalls = /* @__PURE__ */ new Map();
|
|
6737
|
+
/** Active ChatModelStreamImpl per subagent (keyed by subagent name). */
|
|
6738
|
+
const activeMessages = /* @__PURE__ */ new Map();
|
|
6739
|
+
function deletePendingSubagent(pending) {
|
|
6740
|
+
pendingByCallId.delete(pending.callId);
|
|
6741
|
+
for (const [segment, entry] of pendingByNamespaceSegment) if (entry === pending) {
|
|
6742
|
+
pendingByNamespaceSegment.delete(segment);
|
|
6743
|
+
latestValuesByNamespaceSegment.delete(segment);
|
|
6744
|
+
}
|
|
6745
|
+
}
|
|
6746
|
+
function subagentSegment(ns) {
|
|
6747
|
+
return ns.length === path.length + 1 ? ns[path.length] : void 0;
|
|
6748
|
+
}
|
|
6749
|
+
function getOrCreateSubagentLogs(name) {
|
|
6750
|
+
let logs = subagentsByName.get(name);
|
|
6751
|
+
if (!logs) {
|
|
6752
|
+
logs = {
|
|
6753
|
+
messagesLog: StreamChannel.local(),
|
|
6754
|
+
toolCallsLog: StreamChannel.local(),
|
|
6755
|
+
nestedSubagentsLog: StreamChannel.local()
|
|
6756
|
+
};
|
|
6757
|
+
subagentsByName.set(name, logs);
|
|
6758
|
+
}
|
|
6759
|
+
return logs;
|
|
6760
|
+
}
|
|
6761
|
+
return {
|
|
6762
|
+
__native: true,
|
|
6763
|
+
init: () => ({ subagents: subagentsLog }),
|
|
6764
|
+
process(event) {
|
|
6765
|
+
if (!hasPrefix(event.params.namespace, path)) return true;
|
|
6766
|
+
const ns = event.params.namespace;
|
|
6767
|
+
const depth = ns.length - path.length;
|
|
6768
|
+
if (depth <= 1 && event.method === "tools") {
|
|
6769
|
+
const data = event.params.data;
|
|
6770
|
+
const toolCallId = data.tool_call_id;
|
|
6771
|
+
const toolName = data.tool_name;
|
|
6772
|
+
if (toolName === "task" && data.event === "tool-started") {
|
|
6773
|
+
const rawInput = data.input;
|
|
6774
|
+
const input = typeof rawInput === "string" ? JSON.parse(rawInput) : rawInput ?? {};
|
|
6775
|
+
const subagentName = input.subagent_type ?? "unknown";
|
|
6776
|
+
const taskDescription = input.description ?? "";
|
|
6777
|
+
let resolveTaskInput;
|
|
6778
|
+
let resolveOutput;
|
|
6779
|
+
let rejectOutput;
|
|
6780
|
+
const taskInput = new Promise((res) => {
|
|
6781
|
+
resolveTaskInput = res;
|
|
6782
|
+
});
|
|
6783
|
+
const output = new Promise((res, rej) => {
|
|
6784
|
+
resolveOutput = res;
|
|
6785
|
+
rejectOutput = rej;
|
|
6786
|
+
});
|
|
6787
|
+
const pending = {
|
|
6788
|
+
name: subagentName,
|
|
6789
|
+
callId: toolCallId,
|
|
6790
|
+
resolveTaskInput,
|
|
6791
|
+
resolveOutput,
|
|
6792
|
+
rejectOutput
|
|
6793
|
+
};
|
|
6794
|
+
if (toolCallId) pendingByCallId.set(toolCallId, pending);
|
|
6795
|
+
resolveTaskInput(taskDescription);
|
|
6796
|
+
if (depth === 1) {
|
|
6797
|
+
toolsNodeToName.set(ns[path.length], subagentName);
|
|
6798
|
+
pendingByNamespaceSegment.set(ns[path.length], pending);
|
|
6799
|
+
}
|
|
6800
|
+
if (toolCallId) {
|
|
6801
|
+
const taskSegment = `tools:${toolCallId}`;
|
|
6802
|
+
toolsNodeToName.set(taskSegment, subagentName);
|
|
6803
|
+
pendingByNamespaceSegment.set(taskSegment, pending);
|
|
6804
|
+
}
|
|
6805
|
+
const logs = getOrCreateSubagentLogs(subagentName);
|
|
6806
|
+
subagentsLog.push({
|
|
6807
|
+
name: subagentName,
|
|
6808
|
+
taskInput,
|
|
6809
|
+
output,
|
|
6810
|
+
messages: logs.messagesLog,
|
|
6811
|
+
toolCalls: logs.toolCallsLog,
|
|
6812
|
+
subagents: logs.nestedSubagentsLog
|
|
6813
|
+
});
|
|
6814
|
+
}
|
|
6815
|
+
if (toolName === "task" && toolCallId) {
|
|
6816
|
+
const pending = pendingByCallId.get(toolCallId);
|
|
6817
|
+
if (pending) {
|
|
6818
|
+
if (data.event === "tool-finished") {
|
|
6819
|
+
pending.resolveOutput(data.output);
|
|
6820
|
+
deletePendingSubagent(pending);
|
|
6821
|
+
} else if (data.event === "tool-error") {
|
|
6822
|
+
const message = data.message ?? "unknown error";
|
|
6823
|
+
pending.rejectOutput(new Error(message));
|
|
6824
|
+
deletePendingSubagent(pending);
|
|
6825
|
+
}
|
|
6826
|
+
}
|
|
6827
|
+
}
|
|
6828
|
+
}
|
|
6829
|
+
const segment = subagentSegment(ns);
|
|
6830
|
+
const pending = segment ? pendingByNamespaceSegment.get(segment) : void 0;
|
|
6831
|
+
if (pending) {
|
|
6832
|
+
if (event.method === "values") latestValuesByNamespaceSegment.set(segment, event.params.data);
|
|
6833
|
+
else if (event.method === "lifecycle") {
|
|
6834
|
+
const data = event.params.data;
|
|
6835
|
+
if (data.event === "completed" || data.event === "interrupted") {
|
|
6836
|
+
pending.resolveOutput(latestValuesByNamespaceSegment.get(segment));
|
|
6837
|
+
deletePendingSubagent(pending);
|
|
6838
|
+
} else if (data.event === "failed") {
|
|
6839
|
+
pending.rejectOutput(/* @__PURE__ */ new Error(`Subagent ${pending.name} failed`));
|
|
6840
|
+
deletePendingSubagent(pending);
|
|
6841
|
+
}
|
|
6842
|
+
}
|
|
6843
|
+
}
|
|
6844
|
+
if (depth >= 2) {
|
|
6845
|
+
const parentSegment = ns[path.length];
|
|
6846
|
+
const subagentName = toolsNodeToName.get(parentSegment);
|
|
6847
|
+
const logs = subagentName ? subagentsByName.get(subagentName) : void 0;
|
|
6848
|
+
if (logs && subagentName) {
|
|
6849
|
+
if (event.method === "tools") {
|
|
6850
|
+
const data = event.params.data;
|
|
6851
|
+
const toolCallId = data.tool_call_id;
|
|
6852
|
+
const toolName = data.tool_name;
|
|
6853
|
+
if (data.event === "tool-started") {
|
|
6854
|
+
let resolveOutput;
|
|
6855
|
+
let rejectOutput;
|
|
6856
|
+
let resolveStatus;
|
|
6857
|
+
let resolveError;
|
|
6858
|
+
const output = new Promise((res, rej) => {
|
|
6859
|
+
resolveOutput = res;
|
|
6860
|
+
rejectOutput = rej;
|
|
6861
|
+
});
|
|
6862
|
+
const status = new Promise((res) => {
|
|
6863
|
+
resolveStatus = res;
|
|
6864
|
+
});
|
|
6865
|
+
const error = new Promise((res) => {
|
|
6866
|
+
resolveError = res;
|
|
6867
|
+
});
|
|
6868
|
+
childToolCalls.set(toolCallId, {
|
|
6869
|
+
resolveOutput,
|
|
6870
|
+
rejectOutput,
|
|
6871
|
+
resolveStatus,
|
|
6872
|
+
resolveError
|
|
6873
|
+
});
|
|
6874
|
+
const rawInput = data.input;
|
|
6875
|
+
const parsedInput = typeof rawInput === "string" ? JSON.parse(rawInput) : rawInput;
|
|
6876
|
+
logs.toolCallsLog.push({
|
|
6877
|
+
name: toolName ?? "unknown",
|
|
6878
|
+
callId: toolCallId,
|
|
6879
|
+
input: parsedInput,
|
|
6880
|
+
output,
|
|
6881
|
+
status,
|
|
6882
|
+
error
|
|
6883
|
+
});
|
|
6884
|
+
}
|
|
6885
|
+
const pending = toolCallId ? childToolCalls.get(toolCallId) : void 0;
|
|
6886
|
+
if (pending) {
|
|
6887
|
+
if (data.event === "tool-finished") {
|
|
6888
|
+
pending.resolveOutput(data.output);
|
|
6889
|
+
pending.resolveStatus("finished");
|
|
6890
|
+
pending.resolveError(void 0);
|
|
6891
|
+
childToolCalls.delete(toolCallId);
|
|
6892
|
+
} else if (data.event === "tool-error") {
|
|
6893
|
+
const message = data.message ?? "unknown error";
|
|
6894
|
+
pending.rejectOutput(new Error(message));
|
|
6895
|
+
pending.resolveStatus("error");
|
|
6896
|
+
pending.resolveError(message);
|
|
6897
|
+
childToolCalls.delete(toolCallId);
|
|
6898
|
+
}
|
|
6899
|
+
}
|
|
6900
|
+
}
|
|
6901
|
+
if (event.method === "messages") {
|
|
6902
|
+
const data = event.params.data;
|
|
6903
|
+
if (data.event === "message-start") {
|
|
6904
|
+
const eventsLog = StreamChannel.local();
|
|
6905
|
+
const stream = new ChatModelStreamImpl(eventsLog);
|
|
6906
|
+
eventsLog.push(data);
|
|
6907
|
+
activeMessages.set(subagentName, {
|
|
6908
|
+
stream,
|
|
6909
|
+
eventsLog
|
|
6910
|
+
});
|
|
6911
|
+
logs.messagesLog.push(stream);
|
|
6912
|
+
} else if (data.event === "message-finish") {
|
|
6913
|
+
const active = activeMessages.get(subagentName);
|
|
6914
|
+
if (active) {
|
|
6915
|
+
active.eventsLog.push(data);
|
|
6916
|
+
active.eventsLog.close();
|
|
6917
|
+
activeMessages.delete(subagentName);
|
|
6918
|
+
}
|
|
6919
|
+
} else activeMessages.get(subagentName)?.eventsLog.push(data);
|
|
6920
|
+
}
|
|
6921
|
+
}
|
|
6922
|
+
}
|
|
6923
|
+
return true;
|
|
6924
|
+
},
|
|
6925
|
+
finalize() {
|
|
6926
|
+
for (const pending of pendingByCallId.values()) pending.resolveOutput(void 0);
|
|
6927
|
+
pendingByCallId.clear();
|
|
6928
|
+
for (const pending of childToolCalls.values()) {
|
|
6929
|
+
pending.resolveOutput(void 0);
|
|
6930
|
+
pending.resolveStatus("finished");
|
|
6931
|
+
pending.resolveError(void 0);
|
|
6932
|
+
}
|
|
6933
|
+
childToolCalls.clear();
|
|
6934
|
+
for (const active of activeMessages.values()) active.eventsLog.fail(/* @__PURE__ */ new Error("run finalized before message completed"));
|
|
6935
|
+
activeMessages.clear();
|
|
6936
|
+
subagentsLog.close();
|
|
6937
|
+
for (const logs of subagentsByName.values()) {
|
|
6938
|
+
logs.toolCallsLog.close();
|
|
6939
|
+
logs.messagesLog.close();
|
|
6940
|
+
logs.nestedSubagentsLog.close();
|
|
6941
|
+
}
|
|
6942
|
+
},
|
|
6943
|
+
fail(err) {
|
|
6944
|
+
for (const pending of pendingByCallId.values()) pending.rejectOutput(err);
|
|
6945
|
+
pendingByCallId.clear();
|
|
6946
|
+
for (const pending of childToolCalls.values()) {
|
|
6947
|
+
pending.rejectOutput(err);
|
|
6948
|
+
pending.resolveStatus("error");
|
|
6949
|
+
pending.resolveError(err instanceof Error ? err.message : String(err));
|
|
6950
|
+
}
|
|
6951
|
+
childToolCalls.clear();
|
|
6952
|
+
for (const active of activeMessages.values()) active.eventsLog.fail(err);
|
|
6953
|
+
activeMessages.clear();
|
|
6954
|
+
subagentsLog.fail(err);
|
|
6955
|
+
for (const logs of subagentsByName.values()) {
|
|
6956
|
+
logs.toolCallsLog.fail(err);
|
|
6957
|
+
logs.messagesLog.fail(err);
|
|
6958
|
+
logs.nestedSubagentsLog.fail(err);
|
|
6959
|
+
}
|
|
6960
|
+
}
|
|
6961
|
+
};
|
|
6962
|
+
};
|
|
6963
|
+
}
|
|
6964
|
+
//#endregion
|
|
6625
6965
|
//#region src/agent.ts
|
|
6626
6966
|
const BASE_AGENT_PROMPT = context`
|
|
6627
6967
|
You are a Deep Agent, an AI assistant that helps users accomplish tasks using tools. You respond with text and tool calls. The user can see your responses and tool outputs in real time.
|
|
@@ -6707,7 +7047,7 @@ function isAnthropicModel(model) {
|
|
|
6707
7047
|
* ```
|
|
6708
7048
|
*/
|
|
6709
7049
|
function createDeepAgent(params = {}) {
|
|
6710
|
-
const { model = "anthropic:claude-sonnet-4-6", tools = [], systemPrompt, middleware: customMiddleware = [], subagents = [], responseFormat, contextSchema, checkpointer, store, backend = (config) => new StateBackend(config), interruptOn, name, memory, skills, permissions = [] } = params;
|
|
7050
|
+
const { model = "anthropic:claude-sonnet-4-6", tools = [], systemPrompt, middleware: customMiddleware = [], subagents = [], responseFormat, contextSchema, checkpointer, store, backend = (config) => new StateBackend(config), interruptOn, name, memory, skills, permissions = [], streamTransformers = [] } = params;
|
|
6711
7051
|
const collidingTools = tools.map((t) => t.name).filter((n) => typeof n === "string" && BUILTIN_TOOL_NAMES.has(n));
|
|
6712
7052
|
if (collidingTools.length > 0) throw new ConfigurationError(`Tool name(s) [${collidingTools.join(", ")}] conflict with built-in tools. Rename your custom tools to avoid this.`, "TOOL_NAME_COLLISION");
|
|
6713
7053
|
const anthropicModel = isAnthropicModel(model);
|
|
@@ -6802,6 +7142,7 @@ function createDeepAgent(params = {}) {
|
|
|
6802
7142
|
* - Middleware: AllMiddleware (built-in + custom + subagent middleware for state inference)
|
|
6803
7143
|
* - Tools: TTools
|
|
6804
7144
|
* - Subagents: TSubagents (for type-safe streaming)
|
|
7145
|
+
* - StreamTransformers: TStreamTransformers
|
|
6805
7146
|
*/
|
|
6806
7147
|
return createAgent({
|
|
6807
7148
|
model,
|
|
@@ -6824,7 +7165,8 @@ function createDeepAgent(params = {}) {
|
|
|
6824
7165
|
contextSchema,
|
|
6825
7166
|
checkpointer,
|
|
6826
7167
|
store,
|
|
6827
|
-
name
|
|
7168
|
+
name,
|
|
7169
|
+
streamTransformers: [createSubagentTransformer([]), ...streamTransformers]
|
|
6828
7170
|
}).withConfig({
|
|
6829
7171
|
recursionLimit: 1e4,
|
|
6830
7172
|
metadata: {
|
|
@@ -6964,7 +7306,9 @@ function createSettings(options = {}) {
|
|
|
6964
7306
|
* State schema for agent memory middleware.
|
|
6965
7307
|
*/
|
|
6966
7308
|
const AgentMemoryStateSchema = z$1.object({
|
|
7309
|
+
/** Personal preferences from ~/.deepagents/{agent}/ (applies everywhere) */
|
|
6967
7310
|
userMemory: z$1.string().optional(),
|
|
7311
|
+
/** Project-specific context (loaded from project root) */
|
|
6968
7312
|
projectMemory: z$1.string().optional()
|
|
6969
7313
|
});
|
|
6970
7314
|
/**
|
|
@@ -7344,6 +7688,6 @@ function listSkills(options) {
|
|
|
7344
7688
|
return Array.from(allSkills.values());
|
|
7345
7689
|
}
|
|
7346
7690
|
//#endregion
|
|
7347
|
-
export { BaseSandbox, CompositeBackend, ConfigurationError, DEFAULT_GENERAL_PURPOSE_DESCRIPTION, DEFAULT_SUBAGENT_PROMPT, FilesystemBackend, GENERAL_PURPOSE_SUBAGENT, LangSmithSandbox, LocalShellBackend, MAX_SKILL_DESCRIPTION_LENGTH, MAX_SKILL_FILE_SIZE, MAX_SKILL_NAME_LENGTH, SandboxError, StateBackend, StoreBackend, TASK_SYSTEM_PROMPT, adaptBackendProtocol, adaptSandboxProtocol, computeSummarizationDefaults, createAgentMemoryMiddleware, createAsyncSubAgentMiddleware, createCompletionCallbackMiddleware, createDeepAgent, createFilesystemMiddleware, createMemoryMiddleware, createPatchToolCallsMiddleware, createSettings, createSkillsMiddleware, createSubAgentMiddleware, createSummarizationMiddleware, filesValue, findProjectRoot, isAsyncSubAgent, isSandboxBackend, isSandboxProtocol, listSkills, parseSkillMetadata, resolveBackend };
|
|
7691
|
+
export { BaseSandbox, CompositeBackend, ConfigurationError, DEFAULT_GENERAL_PURPOSE_DESCRIPTION, DEFAULT_SUBAGENT_PROMPT, FilesystemBackend, GENERAL_PURPOSE_SUBAGENT, LangSmithSandbox, LocalShellBackend, MAX_SKILL_DESCRIPTION_LENGTH, MAX_SKILL_FILE_SIZE, MAX_SKILL_NAME_LENGTH, SandboxError, StateBackend, StoreBackend, TASK_SYSTEM_PROMPT, adaptBackendProtocol, adaptSandboxProtocol, computeSummarizationDefaults, createAgentMemoryMiddleware, createAsyncSubAgentMiddleware, createCompletionCallbackMiddleware, createDeepAgent, createFilesystemMiddleware, createMemoryMiddleware, createPatchToolCallsMiddleware, createSettings, createSkillsMiddleware, createSubAgentMiddleware, createSubagentTransformer, createSummarizationMiddleware, filesValue, findProjectRoot, isAsyncSubAgent, isSandboxBackend, isSandboxProtocol, listSkills, parseSkillMetadata, resolveBackend };
|
|
7348
7692
|
|
|
7349
7693
|
//# sourceMappingURL=index.js.map
|