deepagents 1.16.4 → 1.17.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.
@@ -1,21 +1,22 @@
1
1
  import { AIMessage, HumanMessage, SystemMessage, ToolMessage, anthropicPromptCachingMiddleware, bedrockPromptCachingMiddleware, context, countTokensApproximately, createAgent, createMiddleware, humanInTheLoopMiddleware, modelRefusalMiddleware, todoListMiddleware, tool } from "langchain";
2
2
  import { omitPayload } from "@langchain/core/tracers/tracer_langchain";
3
3
  import { ContextOverflowError, ModelRefusalError } from "@langchain/core/errors";
4
- import { Command, Overwrite, REMOVE_ALL_MESSAGES, ReducedValue, StateSchema, getConfig, getCurrentTaskInput, getStore, isCommand, isGraphBubbleUp } from "@langchain/langgraph";
4
+ import { Command, DeltaValue, MessagesDeltaValue, Overwrite, REMOVE_ALL_MESSAGES, ReducedValue, StateSchema, getConfig, getCurrentTaskInput, getStore, isCommand, isGraphBubbleUp } from "@langchain/langgraph";
5
5
  import { z } from "zod/v4";
6
6
  import micromatch from "micromatch";
7
7
  import { createHash } from "node:crypto";
8
8
  import { AIMessage as AIMessage$1, BaseMessage, HumanMessage as HumanMessage$1, RemoveMessage, SystemMessage as SystemMessage$1, ToolMessage as ToolMessage$1, addNotificationMetadata, coerceMessageLikeToMessage, getBufferString, getNotificationMetadata } from "@langchain/core/messages";
9
+ import { Runnable, RunnableBinding } from "@langchain/core/runnables";
9
10
  import * as z$2 from "zod";
10
11
  import { z as z$1 } from "zod";
11
12
  import { initChatModel } from "langchain/chat_models/universal";
13
+ import { schemaMetaRegistry } from "@langchain/langgraph/zod";
14
+ import { getInteropZodObjectShape, isInteropZodObject, isInteropZodSchema, isZodSchemaV4 } from "@langchain/core/utils/types";
12
15
  import yaml from "yaml";
13
- import { Runnable, RunnableBinding } from "@langchain/core/runnables";
14
16
  import { isLangChainTool } from "@langchain/core/tools";
15
17
  import { isOpenAITool } from "@langchain/core/language_models/base";
16
18
  import { convertToOpenAIFunction } from "@langchain/core/utils/function_calling";
17
19
  import { toJsonSchema } from "@langchain/core/utils/json_schema";
18
- import { isInteropZodSchema } from "@langchain/core/utils/types";
19
20
  import { Client } from "@langchain/langgraph-sdk";
20
21
  import { getCurrentRunTree } from "langsmith/traceable";
21
22
  import { Client as Client$1 } from "langsmith";
@@ -34,6 +35,20 @@ function setRealpath(target, fn) {
34
35
  configurable: true
35
36
  });
36
37
  }
38
+ // src/backends/pin.ts
39
+ const PIN = Symbol.for("deepagents.pin");
40
+ function getPin(backend) {
41
+ if (typeof backend !== "object" || backend === null) return;
42
+ const fn = backend[PIN];
43
+ return typeof fn === "function" ? fn : void 0;
44
+ }
45
+ function setPin(target, fn) {
46
+ Object.defineProperty(target, PIN, {
47
+ value: fn,
48
+ enumerable: false,
49
+ configurable: true
50
+ });
51
+ }
37
52
  // src/backends/utils.ts
38
53
  /**
39
54
  * Shared utility functions for memory backend implementations.
@@ -667,6 +682,8 @@ function adaptBackendProtocol(backend) {
667
682
  }
668
683
  const realpath = getRealpath(backend);
669
684
  if (realpath !== void 0) setRealpath(adapted, realpath);
685
+ const pin = getPin(backend);
686
+ if (pin !== void 0) setPin(adapted, pin);
670
687
  const resolveBackendForPath = backend.resolveBackendForPath;
671
688
  if (typeof resolveBackendForPath === "function") Object.defineProperty(adapted, "resolveBackendForPath", {
672
689
  value: (path) => resolveBackendForPath.call(backend, path),
@@ -1719,6 +1736,7 @@ var CompositeBackend = class {
1719
1736
  this.routes = Object.fromEntries(Object.entries(routes).map(([k, v]) => [k.endsWith("/") ? k : `${k}/`, isSandboxProtocol(v) ? adaptSandboxProtocol(v) : adaptBackendProtocol(v)]));
1720
1737
  this.sortedRoutes = Object.entries(this.routes).sort((a, b) => b[0].length - a[0].length);
1721
1738
  setRealpath(this, (path) => this.resolveRealPath(path));
1739
+ setPin(this, (path, options, authorize, operation) => this.runPinned(path, options, authorize, operation));
1722
1740
  }
1723
1741
  /** Delegates to default backend's id if it is a sandbox, otherwise empty string. */
1724
1742
  get id() {
@@ -1760,6 +1778,22 @@ var CompositeBackend = class {
1760
1778
  return realpath === void 0 ? path : await realpath(path);
1761
1779
  }
1762
1780
  /**
1781
+ * Pin via the backend that owns `path`, re-adding the route prefix to the
1782
+ * real path it authorizes. Runs `operation` unpinned when that backend has
1783
+ * no pin hook.
1784
+ */
1785
+ runPinned(path, options, authorize, operation) {
1786
+ for (const [routePrefix, backend] of this.sortedRoutes) if (this.isPathWithinRoute(path, routePrefix)) {
1787
+ const pin = getPin(backend);
1788
+ if (pin === void 0) return operation();
1789
+ const prefix = routePrefix.slice(0, -1);
1790
+ const suffix = path.substring(routePrefix.length);
1791
+ return pin(suffix ? "/" + suffix : "/", options, (realPath) => authorize(prefix + realPath), operation);
1792
+ }
1793
+ const pin = getPin(this.default);
1794
+ return pin === void 0 ? operation() : pin(path, options, authorize, operation);
1795
+ }
1796
+ /**
1763
1797
  * Determine which backend handles this key and strip prefix.
1764
1798
  *
1765
1799
  * @param key - Original file path
@@ -2565,11 +2599,15 @@ async function resolveRealPath(backend, canonical) {
2565
2599
  /**
2566
2600
  * Check whether `path` is permitted under `rules` for `operation`.
2567
2601
  *
2568
- * Returns the canonical path to hand the backend, or an error string to
2569
- * surface to the model. The decision covers every form of the target: the
2570
- * lexical canonical path (dot and empty segments dropped) and, when the
2571
- * backend has a realpath hook, the symlink-resolved path it would actually
2572
- * touch. A deny on either blocks the call.
2602
+ * Returns the canonical path, the `target` to hand the backend for a
2603
+ * single-file operation, or an error string to surface to the model. The
2604
+ * decision covers every form of the target: the lexical canonical path (dot
2605
+ * and empty segments dropped) and, when the backend has a realpath hook, the
2606
+ * symlink-resolved path it would actually touch. A deny on either blocks the
2607
+ * call.
2608
+ *
2609
+ * `target` is the path with its parent resolved once and checked, so a
2610
+ * symlink swapped after the check cannot redirect the operation.
2573
2611
  *
2574
2612
  * Never throws: an invalid path (non-absolute, or containing `..` or `~`), one
2575
2613
  * the backend cannot resolve, or a denied one is a recoverable tool error, not
@@ -2578,18 +2616,64 @@ async function resolveRealPath(backend, canonical) {
2578
2616
  * @internal
2579
2617
  */
2580
2618
  async function checkPermission(backend, rules, operation, path) {
2581
- if (rules.length === 0) return { path };
2619
+ if (rules.length === 0) return {
2620
+ path,
2621
+ target: path
2622
+ };
2582
2623
  let canonical;
2624
+ let target;
2583
2625
  let real;
2584
2626
  try {
2585
2627
  canonical = validatePath(path);
2586
2628
  if (decidePathAccess(rules, operation, canonical) === "deny") return { error: `Error: permission denied for ${operation} on ${canonical}` };
2587
- real = await resolveRealPath(backend, canonical);
2629
+ target = await resolveParentRealPath(backend, canonical);
2630
+ real = await resolveRealPath(backend, target);
2588
2631
  } catch (error) {
2589
2632
  return { error: `Error: ${getErrorMessage$1(error)}` };
2590
2633
  }
2634
+ if (crossesRoute(backend, canonical, target)) return { error: `Error: ${canonical} resolves to ${target}, which is served by a different backend` };
2591
2635
  if (real !== canonical && decidePathAccess(rules, operation, real) === "deny") return { error: `Error: permission denied for ${operation} on ${canonical} (resolves to ${real})` };
2592
- return { path: canonical };
2636
+ return {
2637
+ path: canonical,
2638
+ target
2639
+ };
2640
+ }
2641
+ /**
2642
+ * Run a single-path `operation` on `target` through the backend's pin hook when
2643
+ * rules are configured and the backend has one, so the final decision is made
2644
+ * on the directory the operation actually uses. `isDenied` receives the real
2645
+ * path. Without a hook, `operation` runs on the path `checkPermission` resolved.
2646
+ *
2647
+ * Errors raised here, rather than by `operation`, start with `errorPrefix` so
2648
+ * they match how the calling tool formats backend errors.
2649
+ */
2650
+ async function runBoundToTarget(backend, rules, target, options, isDenied, operation) {
2651
+ const pin = rules.length > 0 ? getPin(backend) : void 0;
2652
+ if (pin === void 0) return operation();
2653
+ const { create, describe, errorPrefix } = options;
2654
+ let operationStarted = false;
2655
+ try {
2656
+ return await pin(target, { create }, (realPath) => {
2657
+ const real = validatePath(realPath);
2658
+ return isDenied(real) ? `${errorPrefix}permission denied for ${describe} (resolves to ${real})` : void 0;
2659
+ }, () => {
2660
+ operationStarted = true;
2661
+ return operation();
2662
+ });
2663
+ } catch (error) {
2664
+ if (operationStarted) throw error;
2665
+ return { error: `${errorPrefix}${describe} failed: ${getErrorMessage$1(error)}` };
2666
+ }
2667
+ }
2668
+ /**
2669
+ * Whether `target` is served by a different `CompositeBackend` route than
2670
+ * `requested`. Symlink resolution must not move an operation to another
2671
+ * backend.
2672
+ */
2673
+ function crossesRoute(backend, requested, target) {
2674
+ const resolveBackendForPath = backend.resolveBackendForPath;
2675
+ if (typeof resolveBackendForPath !== "function" || requested === target) return false;
2676
+ return resolveBackendForPath.call(backend, requested)[0] !== resolveBackendForPath.call(backend, target)[0];
2593
2677
  }
2594
2678
  /**
2595
2679
  * Build an error {@link ToolMessage} for a denied path or a failed backend
@@ -2763,10 +2847,11 @@ function parentPath(path) {
2763
2847
  return `/${parts.slice(0, -1).join("/")}`;
2764
2848
  }
2765
2849
  /**
2766
- * Resolve the path a delete of `target` would actually remove. Backends unlink
2767
- * a symlink leaf rather than following it, so only the parent is resolved.
2850
+ * Resolve symlinks in the parent of `target`, keeping its leaf as given.
2851
+ * Backends refuse to follow (or, for delete, unlink) a symlinked leaf, so this
2852
+ * is the path a single-file operation actually touches.
2768
2853
  */
2769
- async function resolveDeleteRealPath(backend, target) {
2854
+ async function resolveParentRealPath(backend, target) {
2770
2855
  const parts = posixParts(target);
2771
2856
  if (parts.length === 0) return resolveRealPath(backend, target);
2772
2857
  return validatePath(`${await resolveRealPath(backend, parentPath(target))}/${parts[parts.length - 1]}`);
@@ -2933,7 +3018,11 @@ function createReadFileTool(backend, options) {
2933
3018
  if (permission.error !== void 0) return toolError(runtime, "read_file", permission.error);
2934
3019
  const { file_path, offset: requestedOffset = 0, limit: requestedLimit = 100 } = input;
2935
3020
  const { offset, limit } = normalizeReadPagination(requestedOffset, requestedLimit);
2936
- const readResult = await resolvedBackend.read(permission.path, offset, limit);
3021
+ const readResult = await runBoundToTarget(resolvedBackend, permissions, permission.target, {
3022
+ create: false,
3023
+ describe: `read on ${permission.path}`,
3024
+ errorPrefix: ""
3025
+ }, (real) => decidePathAccess(permissions, "read", real) === "deny", async () => resolvedBackend.read(permission.target, offset, limit));
2937
3026
  if (readResult.error) return toolError(runtime, "read_file", `Error: ${readResult.error}`);
2938
3027
  const mimeType = readResult.mimeType ?? getMimeType(file_path);
2939
3028
  if (!isTextMimeType(mimeType)) {
@@ -3017,7 +3106,11 @@ function createWriteFileTool(backend, options) {
3017
3106
  const permission = await checkPermission(resolvedBackend, permissions, "write", input.file_path);
3018
3107
  if (permission.error !== void 0) return toolError(runtime, "write_file", permission.error);
3019
3108
  const { file_path, content } = input;
3020
- const result = await resolvedBackend.write(permission.path, content);
3109
+ const result = await runBoundToTarget(resolvedBackend, permissions, permission.target, {
3110
+ create: true,
3111
+ describe: `write on ${permission.path}`,
3112
+ errorPrefix: "Error: "
3113
+ }, (real) => decidePathAccess(permissions, "write", real) === "deny", async () => resolvedBackend.write(permission.target, content));
3021
3114
  if (result.error) return toolError(runtime, "write_file", result.error);
3022
3115
  const message = new ToolMessage({
3023
3116
  content: `Successfully wrote to '${file_path}'`,
@@ -3049,7 +3142,11 @@ function createEditFileTool(backend, options) {
3049
3142
  const permission = await checkPermission(resolvedBackend, permissions, "write", input.file_path);
3050
3143
  if (permission.error !== void 0) return toolError(runtime, "edit_file", permission.error);
3051
3144
  const { file_path, old_string, new_string, replace_all = false } = input;
3052
- const result = await resolvedBackend.edit(permission.path, old_string, new_string, replace_all);
3145
+ const result = await runBoundToTarget(resolvedBackend, permissions, permission.target, {
3146
+ create: false,
3147
+ describe: `write on ${permission.path}`,
3148
+ errorPrefix: "Error: "
3149
+ }, (real) => decidePathAccess(permissions, "write", real) === "deny", async () => resolvedBackend.edit(permission.target, old_string, new_string, replace_all));
3053
3150
  if (result.error) return toolError(runtime, "edit_file", result.error);
3054
3151
  const message = new ToolMessage({
3055
3152
  content: `Successfully replaced ${result.occurrences} occurrence(s) in '${file_path}'`,
@@ -3089,22 +3186,29 @@ function createDeleteTool(backend, options) {
3089
3186
  const hasDescendants = await deleteTargetMayHaveDescendants(resolvedBackend, validatedPath, permissions.length > 0);
3090
3187
  const denyingPatterns = findDeleteDenyPatterns(permissions, validatedPath, hasDescendants);
3091
3188
  if (denyingPatterns.length > 0) return toolError(runtime, "delete", `Error: permission denied for write on ${validatedPath} (matches deny rule(s): ${denyingPatterns.join(", ")})`);
3189
+ let deleteTarget = validatedPath;
3092
3190
  if (permissions.length > 0) {
3093
3191
  let realTarget;
3094
3192
  try {
3095
- realTarget = await resolveDeleteRealPath(resolvedBackend, validatedPath);
3193
+ realTarget = await resolveParentRealPath(resolvedBackend, validatedPath);
3096
3194
  } catch (error) {
3097
3195
  return toolError(runtime, "delete", `Error: ${getErrorMessage$1(error)}`);
3098
3196
  }
3197
+ if (crossesRoute(resolvedBackend, validatedPath, realTarget)) return toolError(runtime, "delete", `Error: ${validatedPath} resolves to ${realTarget}, which is served by a different backend`);
3099
3198
  if (realTarget !== validatedPath) {
3100
3199
  if (findDeleteDenyPatterns(permissions, realTarget, hasDescendants).length > 0) return toolError(runtime, "delete", `Error: permission denied for write on ${validatedPath} (resolves to ${realTarget})`);
3101
3200
  }
3201
+ deleteTarget = realTarget;
3102
3202
  }
3103
3203
  if (!supportsDelete(resolvedBackend)) return toolError(runtime, "delete", `Error: deletion is not available for '${validatedPath}'.`);
3104
- const result = await resolvedBackend.delete(validatedPath);
3204
+ const result = await runBoundToTarget(resolvedBackend, permissions, deleteTarget, {
3205
+ create: false,
3206
+ describe: `write on ${validatedPath}`,
3207
+ errorPrefix: "Error: "
3208
+ }, (real) => findDeleteDenyPatterns(permissions, real, hasDescendants).length > 0, async () => resolvedBackend.delete(deleteTarget));
3105
3209
  if (result.error) return toolError(runtime, "delete", result.error);
3106
3210
  const message = new ToolMessage({
3107
- content: `Deleted ${result.path ?? validatedPath}`,
3211
+ content: `Deleted ${result.path === void 0 || result.path === deleteTarget ? validatedPath : result.path}`,
3108
3212
  tool_call_id: runtime.toolCall?.id,
3109
3213
  name: "delete",
3110
3214
  metadata: result.metadata
@@ -4540,7 +4644,7 @@ const INVALID_TOOL_MESSAGE_BLOCK_TYPES = [
4540
4644
  /**
4541
4645
  * Create Command with filtered state update from subagent result
4542
4646
  */
4543
- function returnCommandWithStateUpdate(result, toolCallId) {
4647
+ function returnCommandWithStateUpdate(result, toolCallId, checkpointNs) {
4544
4648
  const stateUpdate = filterStateForSubagent(result);
4545
4649
  let content;
4546
4650
  const refusal = refusalIn(result.messages?.at(-1));
@@ -4564,10 +4668,66 @@ function returnCommandWithStateUpdate(result, toolCallId) {
4564
4668
  messages: [new ToolMessage({
4565
4669
  content,
4566
4670
  tool_call_id: toolCallId,
4567
- name: "task"
4671
+ name: "task",
4672
+ ...checkpointNs ? { artifact: { checkpoint_ns: checkpointNs } } : {}
4568
4673
  })]
4569
4674
  } });
4570
4675
  }
4676
+ function isCompiledGraph(value) {
4677
+ return typeof value === "object" && value !== null && "lg_is_pregel" in value && value.lg_is_pregel === true;
4678
+ }
4679
+ /**
4680
+ * Whether `value` is a plain `RunnableBinding`, such as `withListeners`
4681
+ * returns, and not a subclass. A subclass can override `invoke` with behaviour
4682
+ * that streaming its inner graph would skip, such as the `RunnableRetry` from
4683
+ * `withRetry`.
4684
+ */
4685
+ function isPlainRunnableBinding(value) {
4686
+ return value?.constructor === RunnableBinding;
4687
+ }
4688
+ /**
4689
+ * The compiled graph behind a subagent: the subagent itself, the `graph` of a
4690
+ * `createAgent` agent, or the graph a plain `RunnableBinding` wraps.
4691
+ * `undefined` for any other runnable.
4692
+ */
4693
+ function getCompiledGraph(subagent) {
4694
+ const unwrapped = isPlainRunnableBinding(subagent) ? subagent.bound : subagent;
4695
+ if (isCompiledGraph(unwrapped)) return unwrapped;
4696
+ const graph = unwrapped.graph;
4697
+ return isCompiledGraph(graph) ? graph : void 0;
4698
+ }
4699
+ /**
4700
+ * Invoke a subagent, returning its final state and the namespace it
4701
+ * checkpointed under.
4702
+ *
4703
+ * A compiled subagent is streamed rather than invoked so its checkpoint events
4704
+ * report the namespace it saved under. LangGraph changes that namespace from
4705
+ * the `task` call's own for a second run in the same step (`<namespace>|1`)
4706
+ * and for `checkpointer: true` (task ids removed). No checkpoint event means
4707
+ * nothing was saved. Any other runnable is invoked and assumed to save under
4708
+ * the `task` call's namespace.
4709
+ */
4710
+ async function runSubagent(subagent, state, config) {
4711
+ const graph = getCompiledGraph(subagent);
4712
+ if (graph === void 0) return {
4713
+ result: await subagent.invoke(state, config),
4714
+ checkpointNs: config.configurable?.checkpoint_ns
4715
+ };
4716
+ let result = {};
4717
+ let checkpointNs;
4718
+ const options = {
4719
+ ...config,
4720
+ streamMode: ["values", "checkpoints"],
4721
+ outputKeys: graph.outputChannels
4722
+ };
4723
+ const stream = await subagent.stream(state, options);
4724
+ for await (const [mode, chunk] of stream) if (mode === "values") result = chunk;
4725
+ else checkpointNs ??= chunk.config.configurable?.checkpoint_ns;
4726
+ return {
4727
+ result,
4728
+ checkpointNs
4729
+ };
4730
+ }
4571
4731
  /** Drop the trailing in-flight AIMessage with unresolved tool_calls. */
4572
4732
  function stripInFlightAIMessage(messages) {
4573
4733
  const last = messages.at(-1);
@@ -4755,8 +4915,9 @@ function createTaskTool(options) {
4755
4915
  }
4756
4916
  };
4757
4917
  let result;
4918
+ let checkpointNs;
4758
4919
  try {
4759
- result = await subagent.invoke(subagentState, subagentConfig);
4920
+ ({result, checkpointNs} = await runSubagent(subagent, subagentState, subagentConfig));
4760
4921
  } catch (error) {
4761
4922
  const notice = refusalNoticeFor(error);
4762
4923
  if (notice === void 0) throw error;
@@ -4776,7 +4937,7 @@ function createTaskTool(options) {
4776
4937
  }
4777
4938
  return content;
4778
4939
  }
4779
- return returnCommandWithStateUpdate(result, config.toolCall.id);
4940
+ return returnCommandWithStateUpdate(result, config.toolCall.id, checkpointNs);
4780
4941
  }
4781
4942
  const taskToolSchema = z.object({
4782
4943
  description: z.string().describe("The task to execute with the selected agent"),
@@ -4967,6 +5128,45 @@ function createPatchToolCallsMiddleware() {
4967
5128
  * This module provides pre-configured ReducedValue instances that can be
4968
5129
  * reused across different state schemas, similar to LangGraph's messagesValue.
4969
5130
  */
5131
+ const deltaFields = { messages: new DeltaValue(MessagesDeltaValue.valueSchema, {
5132
+ inputSchema: MessagesDeltaValue.inputSchema,
5133
+ reducer: MessagesDeltaValue.reducer,
5134
+ snapshotFrequency: 50,
5135
+ jsonSchemaExtra: MessagesDeltaValue.jsonSchemaExtra
5136
+ }) };
5137
+ const defaultStateSchema = new StateSchema(deltaFields);
5138
+ /**
5139
+ * The state schema of a deep agent or subagent: the caller's fields, plus the
5140
+ * delta channels for every key the caller leaves out.
5141
+ *
5142
+ * A zod schema is copied field by field the way LangChain's `createAgent` reads
5143
+ * one, keeping reducers registered on zod v4 fields, because a StateSchema
5144
+ * cannot hold a zod object. Anything else `createAgent` ignores, so it is
5145
+ * ignored here too. This follows `createAgentState` in langchain 1.6.0
5146
+ * (`dist/agents/annotation.js`); recheck it when langchain changes how it
5147
+ * reads a state schema.
5148
+ */
5149
+ function deepAgentStateSchema(stateSchema) {
5150
+ if (StateSchema.isInstance(stateSchema)) return new StateSchema({
5151
+ ...deltaFields,
5152
+ ...stateSchema.fields
5153
+ });
5154
+ if (!isInteropZodObject(stateSchema)) return defaultStateSchema;
5155
+ const fields = {};
5156
+ for (const [key, field] of Object.entries(getInteropZodObjectShape(stateSchema))) {
5157
+ const reducer = isZodSchemaV4(field) ? schemaMetaRegistry.get(field)?.reducer : void 0;
5158
+ if (reducer === void 0) fields[key] = field;
5159
+ else if (reducer.schema === void 0) fields[key] = new ReducedValue(field, { reducer: reducer.fn });
5160
+ else fields[key] = new ReducedValue(field, {
5161
+ inputSchema: reducer.schema,
5162
+ reducer: reducer.fn
5163
+ });
5164
+ }
5165
+ return new StateSchema({
5166
+ ...deltaFields,
5167
+ ...fields
5168
+ });
5169
+ }
4970
5170
  /**
4971
5171
  * Shared ReducedValue for file data state management.
4972
5172
  *
@@ -7056,24 +7256,45 @@ function describeAsyncSubAgent(spec) {
7056
7256
  return `- ${spec.name}: ${spec.description}${suffix}`;
7057
7257
  }
7058
7258
  /**
7259
+ * Streaming for the runs this middleware starts on this deployment.
7260
+ *
7261
+ * An app that shows a subagent's thread, or the parent's thread after a
7262
+ * notification, joins runs it didn't start, and a join gets only what the run
7263
+ * streams. Like an app's own runs, these stream tokens and subgraphs, and keep
7264
+ * their events for a late join.
7265
+ */
7266
+ const STREAM_OPTIONS = {
7267
+ streamMode: [
7268
+ "values",
7269
+ "updates",
7270
+ "messages-tuple",
7271
+ "custom"
7272
+ ],
7273
+ streamSubgraphs: true,
7274
+ streamResumable: true
7275
+ };
7276
+ /**
7059
7277
  * The `runs.create` options that link a run to this agent and set the subagent's webhook.
7060
7278
  *
7061
- * A subagent on this deployment runs with this agent's context. The Agent Server
7062
- * takes `context` or `configurable`, not both, so the parent reference then goes
7063
- * through the thread's metadata.
7279
+ * A subagent on this deployment runs with this agent's context, and streams with
7280
+ * `STREAM_OPTIONS`. The Agent Server takes `context` or `configurable`, not both,
7281
+ * so the parent reference then goes through the thread's metadata.
7064
7282
  */
7065
7283
  function runOptions(spec, runtime) {
7066
- const webhook = spec.webhook ? { webhook: spec.webhook } : {};
7284
+ const options = {
7285
+ ...spec.url ? {} : STREAM_OPTIONS,
7286
+ ...spec.webhook ? { webhook: spec.webhook } : {}
7287
+ };
7067
7288
  const context = spec.url ? void 0 : forwardedContext(runtime.context);
7068
7289
  if (context) return {
7069
- ...webhook,
7290
+ ...options,
7070
7291
  context
7071
7292
  };
7072
7293
  const reference = referenceFor(spec, runtime.config);
7073
7294
  return Object.keys(reference).length > 0 ? {
7074
- ...webhook,
7295
+ ...options,
7075
7296
  config: { configurable: { [PARENT_KEY]: reference } }
7076
- } : webhook;
7297
+ } : options;
7077
7298
  }
7078
7299
  /** A run context as JSON data for another run, without deepagents' parent reference. */
7079
7300
  function forwardedContext(context) {
@@ -7275,6 +7496,7 @@ async function awakeParent(parentThreadId, assistantId, update, context) {
7275
7496
  await client.runs.create(parentThreadId, assistantId, {
7276
7497
  input: { messages: [notificationMessage(update)] },
7277
7498
  multitaskStrategy: "reject",
7499
+ ...STREAM_OPTIONS,
7278
7500
  ...context ? { context } : {}
7279
7501
  });
7280
7502
  } catch {}
@@ -8788,7 +9010,7 @@ function createDeepAgent(params = {}) {
8788
9010
  return createAgent({
8789
9011
  model,
8790
9012
  ...finalSystemPrompt !== "" && { systemPrompt: finalSystemPrompt },
8791
- stateSchema,
9013
+ stateSchema: deepAgentStateSchema(stateSchema),
8792
9014
  tools: effectiveTools,
8793
9015
  middleware,
8794
9016
  ...responseFormat !== null && { responseFormat },
@@ -10901,6 +11123,6 @@ var LangSmithSandbox = class LangSmithSandbox extends BaseSandbox {
10901
11123
  });
10902
11124
  }
10903
11125
  };
10904
- export { adaptSandboxProtocol as $, filesValue as A, createFilesystemMiddleware as B, MAX_SKILL_FILE_SIZE as C, skillsMetadataValue as D, pinnedSkillsValue as E, SUBAGENT_RESPONSE_FORMAT_CONFIG_KEY as F, scrubUnsupportedMultimodalContent as G, MULTIMODAL_BLOCK_TYPES as H, createSubAgent as I, applyGrepMaxCount as J, StateBackend as K, createSubAgentMiddleware as L, DEFAULT_GENERAL_PURPOSE_DESCRIPTION as M, DEFAULT_SUBAGENT_PROMPT as N, ConfigurationError as O, GENERAL_PURPOSE_SUBAGENT as P, adaptBackendProtocol as Q, computeSummarizationDefaults as R, MAX_SKILL_DESCRIPTION_LENGTH as S, createSkillsMiddleware as T, createUnsupportedContentMiddleware as U, CompositeBackend as V, multimodalBlockSupported as W, isSandboxProtocol as X, isSandboxBackend as Y, resolveBackend as Z, createHarnessProfile as _, ASYNC_TASK_SYSTEM_PROMPT as a, setRealpath as at, isAsyncSubAgent as b, TASK_SYSTEM_PROMPT as c, registerHarnessProfile as d, checkEmptyContent as et, generalPurposeSubagentConfigSchema as f, EMPTY_HARNESS_PROFILE as g, serializeProfile as h, StoreBackend as i, performStringReplacement as it, createPatchToolCallsMiddleware as j, createMemoryMiddleware as k, createDeepAgent as l, parseHarnessProfileConfig as m, BaseSandbox as n, isTextMimeType as nt, BASE_AGENT_PROMPT as o, harnessProfileConfigSchema as p, SandboxError as q, ContextHubBackend as r, normalizeReadPagination as rt, EXECUTION_SYSTEM_PROMPT as s, LangSmithSandbox as t, getMimeType as tt, getHarnessProfile as u, REQUIRED_MIDDLEWARE_NAMES as v, MAX_SKILL_NAME_LENGTH as w, createCompletionCallbackMiddleware as x, createAsyncSubAgentMiddleware as y, createSummarizationMiddleware as z };
11126
+ export { adaptSandboxProtocol as $, filesValue as A, createFilesystemMiddleware as B, MAX_SKILL_FILE_SIZE as C, skillsMetadataValue as D, pinnedSkillsValue as E, SUBAGENT_RESPONSE_FORMAT_CONFIG_KEY as F, scrubUnsupportedMultimodalContent as G, MULTIMODAL_BLOCK_TYPES as H, createSubAgent as I, applyGrepMaxCount as J, StateBackend as K, createSubAgentMiddleware as L, DEFAULT_GENERAL_PURPOSE_DESCRIPTION as M, DEFAULT_SUBAGENT_PROMPT as N, ConfigurationError as O, GENERAL_PURPOSE_SUBAGENT as P, adaptBackendProtocol as Q, computeSummarizationDefaults as R, MAX_SKILL_DESCRIPTION_LENGTH as S, createSkillsMiddleware as T, createUnsupportedContentMiddleware as U, CompositeBackend as V, multimodalBlockSupported as W, isSandboxProtocol as X, isSandboxBackend as Y, resolveBackend as Z, createHarnessProfile as _, ASYNC_TASK_SYSTEM_PROMPT as a, setPin as at, isAsyncSubAgent as b, TASK_SYSTEM_PROMPT as c, registerHarnessProfile as d, checkEmptyContent as et, generalPurposeSubagentConfigSchema as f, EMPTY_HARNESS_PROFILE as g, serializeProfile as h, StoreBackend as i, performStringReplacement as it, createPatchToolCallsMiddleware as j, createMemoryMiddleware as k, createDeepAgent as l, parseHarnessProfileConfig as m, BaseSandbox as n, isTextMimeType as nt, BASE_AGENT_PROMPT as o, setRealpath as ot, harnessProfileConfigSchema as p, SandboxError as q, ContextHubBackend as r, normalizeReadPagination as rt, EXECUTION_SYSTEM_PROMPT as s, LangSmithSandbox as t, getMimeType as tt, getHarnessProfile as u, REQUIRED_MIDDLEWARE_NAMES as v, MAX_SKILL_NAME_LENGTH as w, createCompletionCallbackMiddleware as x, createAsyncSubAgentMiddleware as y, createSummarizationMiddleware as z };
10905
11127
 
10906
- //# sourceMappingURL=langsmith-DfobOVRO.js.map
11128
+ //# sourceMappingURL=langsmith-DYAFTn0y.js.map