deepagents 1.9.0 → 1.10.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/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _langchain from "langchain";
2
- import { AgentMiddleware, AgentMiddleware as AgentMiddleware$1, AgentTypeConfig, CreateAgentParams, HumanMessage, InferMiddlewareStates, InterruptOnConfig, ProviderStrategy, ReactAgent, ResponseFormat, ResponseFormatUndefined, Runtime, StructuredTool, SystemMessage, ToolMessage, ToolRuntime, ToolStrategy } from "langchain";
2
+ import { AgentMiddleware, AgentMiddleware as AgentMiddleware$1, AgentRunStream, AgentTypeConfig, CreateAgentParams, HumanMessage, InferMiddlewareStates, InterruptOnConfig, ProviderStrategy, ReactAgent, ResponseFormat, ResponseFormatUndefined, Runtime, StructuredTool, SystemMessage, ToolCallStreamUnion, ToolMessage, ToolRuntime, ToolStrategy } from "langchain";
3
3
  import * as _langgraph from "@langchain/langgraph";
4
- import { AnnotationRoot, Command, ReducedValue, StateSchema } from "@langchain/langgraph";
4
+ import { AnnotationRoot, ChatModelStream, Command, Namespace, NativeStreamTransformer, ReducedValue, StateSchema, StreamTransformer } from "@langchain/langgraph";
5
5
  import { z } from "zod/v4";
6
6
  import * as _messages from "@langchain/core/messages";
7
7
  import * as z$2 from "zod";
@@ -672,7 +672,74 @@ type BackendFactory = (runtime: BackendRuntime) => MaybePromise<AnyBackendProtoc
672
672
  */
673
673
  declare function resolveBackend(backend: AnyBackendProtocol | BackendFactory, runtime: BackendRuntime | ToolRuntime): Promise<BackendProtocolV2>;
674
674
  //#endregion
675
+ //#region src/permissions/types.d.ts
676
+ /**
677
+ * The filesystem operations a permission rule can govern.
678
+ */
679
+ type FilesystemOperation = "read" | "write";
680
+ /**
681
+ * Whether a matched rule permits or blocks the operation.
682
+ */
683
+ type PermissionMode = "allow" | "deny";
684
+ /**
685
+ * A single filesystem permission rule.
686
+ *
687
+ * Rules are evaluated in declaration order; the first rule whose
688
+ * `operations` includes the requested operation AND whose `paths`
689
+ * glob-matches the target path determines the outcome. If no rule
690
+ * matches, access is **allowed** (permissive default).
691
+ *
692
+ * All `paths` must be absolute glob patterns (start with `/`, no `..` or `~`).
693
+ * Supports `**` (any depth), `*` (within one segment), and `{a,b}` brace expansion.
694
+ * Paths are validated when passed to {@link createFilesystemMiddleware}.
695
+ */
696
+ interface FilesystemPermission {
697
+ /**
698
+ * The operations this rule applies to.
699
+ */
700
+ operations: readonly FilesystemOperation[];
701
+ /**
702
+ * Absolute glob patterns for paths this rule matches.
703
+ * Must start with `/`; must not contain `..` or `~`.
704
+ * Supports `**` (any depth), `*` (within one segment), and `{a,b}` brace expansion.
705
+ */
706
+ paths: string[];
707
+ /**
708
+ * Whether matching paths are permitted or blocked. Defaults to `"allow"`.
709
+ */
710
+ mode?: PermissionMode;
711
+ }
712
+ //#endregion
675
713
  //#region src/middleware/fs.d.ts
714
+ /**
715
+ * Tools that should be excluded from the large result eviction logic.
716
+ *
717
+ * This array contains tools that should NOT have their results evicted to the filesystem
718
+ * when they exceed token limits. Tools are excluded for different reasons:
719
+ *
720
+ * 1. Tools with built-in truncation (ls, glob, grep):
721
+ * These tools truncate their own output when it becomes too large. When these tools
722
+ * produce truncated output due to many matches, it typically indicates the query
723
+ * needs refinement rather than full result preservation. In such cases, the truncated
724
+ * matches are potentially more like noise and the LLM should be prompted to narrow
725
+ * its search criteria instead.
726
+ *
727
+ * 2. Tools with problematic truncation behavior (read_file):
728
+ * read_file is tricky to handle as the failure mode here is single long lines
729
+ * (e.g., imagine a jsonl file with very long payloads on each line). If we try to
730
+ * truncate the result of read_file, the agent may then attempt to re-read the
731
+ * truncated file using read_file again, which won't help.
732
+ *
733
+ * 3. Tools that never exceed limits (edit_file, write_file):
734
+ * These tools return minimal confirmation messages and are never expected to produce
735
+ * output large enough to exceed token limits, so checking them would be unnecessary.
736
+ */
737
+ /**
738
+ * All tool names registered by FilesystemMiddleware.
739
+ * This is the single source of truth — used by createDeepAgent to detect
740
+ * collisions with user-supplied tools at construction time.
741
+ */
742
+ declare const FILESYSTEM_TOOL_NAMES: readonly ["ls", "read_file", "write_file", "edit_file", "glob", "grep", "execute"];
676
743
  /**
677
744
  * Type for the files state record.
678
745
  */
@@ -695,6 +762,22 @@ interface FilesystemMiddlewareOptions {
695
762
  toolTokenLimitBeforeEvict?: number | null;
696
763
  /** Optional token limit before evicting a HumanMessage to the filesystem (default: 50000 tokens, ~200KB) */
697
764
  humanMessageTokenLimitBeforeEvict?: number | null;
765
+ /**
766
+ * Filesystem permission rules enforced on every tool call.
767
+ *
768
+ * Rules are evaluated in declaration order; first match wins; permissive
769
+ * default. Applies to `ls`, `read_file`, `write_file`, `edit_file`,
770
+ * `glob`, and `grep`.
771
+ *
772
+ * **Note on `execute`**: permissions are not enforced on `execute` because
773
+ * shell commands can access any path regardless of path-based rules. Using
774
+ * permissions with an execution-capable backend (one where `isSandboxBackend`
775
+ * returns `true`) throws a `ConfigurationError` unless the backend is a
776
+ * `CompositeBackend` and every permission path is scoped to a route prefix.
777
+ *
778
+ * When omitted or empty, all filesystem operations are permitted.
779
+ */
780
+ permissions?: FilesystemPermission[];
698
781
  }
699
782
  /**
700
783
  * Create filesystem middleware with all tools and features.
@@ -817,10 +900,10 @@ declare class StateBackend implements BackendProtocolV2 {
817
900
  * Get files from current state.
818
901
  *
819
902
  * In legacy mode, reads from the injected {@link BackendRuntime}.
820
- * In zero-arg mode, reads from the LangGraph execution context via
821
- * {@link getCurrentTaskInput}.
903
+ * In zero-arg mode, reads via {@link PREGEL_READ_KEY} with fresh=true,
904
+ * which applies any pending task writes through the reducer before returning.
822
905
  */
823
- private getFiles;
906
+ private get files();
824
907
  /**
825
908
  * Push a files state update through LangGraph's internal send channel.
826
909
  *
@@ -900,32 +983,76 @@ declare class StateBackend implements BackendProtocolV2 {
900
983
  }
901
984
  //#endregion
902
985
  //#region src/backends/store.d.ts
986
+ /**
987
+ * Context provided to dynamic namespace factory functions.
988
+ */
989
+ interface StoreBackendContext<StateT = unknown> {
990
+ /**
991
+ * Current graph state, when available.
992
+ *
993
+ * In legacy factory mode this is the injected runtime state. In zero-arg mode
994
+ * this is read from the current LangGraph execution context.
995
+ */
996
+ state: StateT;
997
+ /**
998
+ * Runnable config, when available.
999
+ *
1000
+ * This mirrors the Python implementation's access to config metadata for
1001
+ * namespace resolution.
1002
+ */
1003
+ config?: {
1004
+ metadata?: Record<string, unknown>;
1005
+ configurable?: Record<string, unknown>;
1006
+ };
1007
+ /**
1008
+ * Legacy assistant identifier, resolved from config metadata first and then
1009
+ * from the injected runtime for backwards compatibility.
1010
+ */
1011
+ assistantId?: string;
1012
+ }
1013
+ type StoreBackendNamespaceFactory<StateT = unknown> = (context: StoreBackendContext<StateT>) => string[];
903
1014
  /**
904
1015
  * Options for StoreBackend constructor.
905
1016
  */
906
- interface StoreBackendOptions extends BackendOptions {
1017
+ interface StoreBackendOptions<StateT = unknown> extends BackendOptions {
1018
+ /**
1019
+ * Explicit store instance to use for persistence.
1020
+ *
1021
+ * This mirrors the Python API and allows constructing a backend directly with
1022
+ * a store instance, e.g. `new StoreBackend({ store })`.
1023
+ *
1024
+ * When omitted, the backend uses the legacy injected runtime store or the
1025
+ * LangGraph execution-context store.
1026
+ */
1027
+ store?: BaseStore;
907
1028
  /**
908
1029
  * Custom namespace for store operations.
909
1030
  *
910
- * Determines where files are stored in the LangGraph store, enabling
911
- * user-scoped, org-scoped, or any custom isolation pattern.
1031
+ * Accepts either a static namespace array or a factory that derives the
1032
+ * namespace from the current backend context.
912
1033
  *
913
- * If not provided, falls back to legacy behavior using assistantId from {@link BackendRuntime}.
1034
+ * If not provided, falls back to legacy assistant-id detection from config
1035
+ * metadata, then the injected runtime's `assistantId`, and finally
1036
+ * `["filesystem"]`.
914
1037
  *
915
1038
  * @example
916
1039
  * ```typescript
917
- * // User-scoped storage
918
- * new StoreBackend(runtime, {
1040
+ * // Static namespace
1041
+ * new StoreBackend({
919
1042
  * namespace: ["memories", orgId, userId, "filesystem"],
920
1043
  * });
921
1044
  *
922
- * // Org-scoped storage
923
- * new StoreBackend(runtime, {
924
- * namespace: ["memories", orgId, "filesystem"],
1045
+ * // Dynamic namespace
1046
+ * new StoreBackend({
1047
+ * namespace: ({ state }) => [
1048
+ * "memories",
1049
+ * (state as { userId: string }).userId,
1050
+ * "filesystem",
1051
+ * ],
925
1052
  * });
926
1053
  * ```
927
1054
  */
928
- namespace?: string[];
1055
+ namespace?: string[] | StoreBackendNamespaceFactory<StateT>;
929
1056
  }
930
1057
  /**
931
1058
  * Backend that stores files in LangGraph's BaseStore (persistent).
@@ -939,6 +1066,7 @@ interface StoreBackendOptions extends BackendOptions {
939
1066
  */
940
1067
  declare class StoreBackend implements BackendProtocolV2 {
941
1068
  private stateAndStore;
1069
+ private storeOverride;
942
1070
  private _namespace;
943
1071
  private fileFormat;
944
1072
  constructor(options?: StoreBackendOptions);
@@ -957,15 +1085,28 @@ declare class StoreBackend implements BackendProtocolV2 {
957
1085
  * @throws Error if no store is available in either mode
958
1086
  */
959
1087
  private getStore;
1088
+ /**
1089
+ * Get the current graph state when available.
1090
+ */
1091
+ private getState;
1092
+ /**
1093
+ * Get the most relevant runnable config for namespace resolution.
1094
+ */
1095
+ private getNamespaceConfig;
1096
+ /**
1097
+ * Legacy assistant-id detection compatible with both Python and the
1098
+ * historical TypeScript `assistantId` runtime property.
1099
+ */
1100
+ private getLegacyAssistantId;
960
1101
  /**
961
1102
  * Get the namespace for store operations.
962
1103
  *
963
1104
  * Resolution order:
964
- * 1. Explicit namespace from constructor options (both modes)
965
- * 2. Legacy mode: `[assistantId, "filesystem"]` fallback from {@link StateAndStore}
966
- * 3. Zero-arg mode without namespace: `["filesystem"]` with a deprecation warning
967
- * nudging callers to pass an explicit namespace
968
- * 4. Legacy mode without assistantId: `["filesystem"]`
1105
+ * 1. Explicit namespace from constructor options
1106
+ * 2. Namespace factory resolved from the current backend context
1107
+ * 3. Assistant ID from runtime config / LangGraph config metadata
1108
+ * 4. Legacy `assistantId` from the injected runtime
1109
+ * 5. `["filesystem"]`
969
1110
  */
970
1111
  protected getNamespace(): string[];
971
1112
  /**
@@ -1187,6 +1328,15 @@ declare class CompositeBackend implements BackendProtocolV2 {
1187
1328
  constructor(defaultBackend: AnyBackendProtocol, routes: Record<string, AnyBackendProtocol>);
1188
1329
  /** Delegates to default backend's id if it is a sandbox, otherwise empty string. */
1189
1330
  get id(): string;
1331
+ /** Route prefixes registered on this backend (e.g. `["/workspace"]`). */
1332
+ get routePrefixes(): string[];
1333
+ /**
1334
+ * Type guard — returns true if `backend` is a {@link CompositeBackend}.
1335
+ *
1336
+ * Uses duck-typing on `routePrefixes` so it works across module boundaries
1337
+ * where `instanceof` may fail.
1338
+ */
1339
+ static isInstance(backend: unknown): backend is CompositeBackend;
1190
1340
  /**
1191
1341
  * Determine which backend handles this key and strip prefix.
1192
1342
  *
@@ -1579,6 +1729,8 @@ interface LangSmithSandboxCreateOptions extends Omit<CreateSandboxOptions, "name
1579
1729
  *
1580
1730
  * Use the static `LangSmithSandbox.create()` factory for the simplest setup,
1581
1731
  * or construct directly with an existing `Sandbox` instance.
1732
+ *
1733
+ * @experimental This feature is experimental, and breaking changes are expected.
1582
1734
  */
1583
1735
  declare class LangSmithSandbox extends BaseSandbox {
1584
1736
  #private;
@@ -1797,6 +1949,27 @@ interface SubAgent {
1797
1949
  * ```
1798
1950
  */
1799
1951
  responseFormat?: CreateAgentParams["responseFormat"];
1952
+ /**
1953
+ * Filesystem permission rules for this subagent.
1954
+ *
1955
+ * When specified, these rules **replace** the parent agent's permissions
1956
+ * for all tool calls made by this subagent. When omitted, the subagent
1957
+ * inherits the parent agent's permissions.
1958
+ *
1959
+ * Subagent permissions are a full replacement, not a merge.
1960
+ *
1961
+ * @example
1962
+ * ```ts
1963
+ * // Parent denies /restricted/**; this subagent can read it.
1964
+ * const reader: SubAgent = {
1965
+ * name: "reader",
1966
+ * permissions: [
1967
+ * { operations: ["read"], paths: ["/restricted/**"] },
1968
+ * ],
1969
+ * };
1970
+ * ```
1971
+ */
1972
+ permissions?: FilesystemPermission[];
1800
1973
  }
1801
1974
  /**
1802
1975
  * Base specification for the general-purpose subagent.
@@ -2030,6 +2203,11 @@ interface SkillMetadata$1 {
2030
2203
  * - Space-delimited list of tool names
2031
2204
  */
2032
2205
  allowedTools?: string[];
2206
+ /**
2207
+ * Path to a JS/TS entrypoint file for a QuickJS REPL module, relative to the skill
2208
+ * directory.
2209
+ */
2210
+ module?: string;
2033
2211
  }
2034
2212
  /**
2035
2213
  * Options for the skills middleware.
@@ -2078,6 +2256,7 @@ declare function createSkillsMiddleware(options: SkillsMiddlewareOptions): Agent
2078
2256
  compatibility?: string | null | undefined;
2079
2257
  metadata?: Record<string, string> | undefined;
2080
2258
  allowedTools?: string[] | undefined;
2259
+ module?: string | undefined;
2081
2260
  }[] | undefined, {
2082
2261
  name: string;
2083
2262
  description: string;
@@ -2086,6 +2265,7 @@ declare function createSkillsMiddleware(options: SkillsMiddlewareOptions): Agent
2086
2265
  compatibility?: string | null | undefined;
2087
2266
  metadata?: Record<string, string> | undefined;
2088
2267
  allowedTools?: string[] | undefined;
2268
+ module?: string | undefined;
2089
2269
  }[] | undefined>;
2090
2270
  files: ReducedValue<FilesRecord | undefined, FilesRecordUpdate | undefined>;
2091
2271
  }>, undefined, unknown, readonly (_$_langchain_core_tools0.ClientTool | _$_langchain_core_tools0.ServerTool)[]>;
@@ -2189,8 +2369,9 @@ interface SummarizationMiddlewareOptions {
2189
2369
  /**
2190
2370
  * The language model to use for generating summaries.
2191
2371
  * Can be a model string (e.g., "gpt-4o-mini") or a language model instance.
2372
+ * If omitted, middleware will use the active request model.
2192
2373
  */
2193
- model: string | BaseChatModel | BaseLanguageModel;
2374
+ model?: string | BaseChatModel | BaseLanguageModel;
2194
2375
  /**
2195
2376
  * Backend instance or factory for persisting conversation history.
2196
2377
  */
@@ -2323,6 +2504,19 @@ interface AsyncTask {
2323
2504
  /** ISO timestamp of the most recent status poll via the check tool. */
2324
2505
  checkedAt?: string;
2325
2506
  }
2507
+ /**
2508
+ * Task statuses that will never change.
2509
+ *
2510
+ * When listing tasks, live-status fetches are skipped for tasks whose
2511
+ * cached status is in this set, since they are guaranteed to be final.
2512
+ */
2513
+ /**
2514
+ * Names of the tools added by the async subagent middleware.
2515
+ *
2516
+ * Exported so `agent.ts` can include them in `BUILTIN_TOOL_NAMES` and
2517
+ * surface a `ConfigurationError` if a user-provided tool collides.
2518
+ */
2519
+ declare const ASYNC_TASK_TOOL_NAMES: readonly ["start_async_task", "check_async_task", "update_async_task", "cancel_async_task", "list_async_tasks"];
2326
2520
  /**
2327
2521
  * Options for creating async subagent middleware.
2328
2522
  */
@@ -2424,8 +2618,100 @@ declare function createAsyncSubAgentMiddleware(options: AsyncSubAgentMiddlewareO
2424
2618
  statusFilter?: string | null | undefined;
2425
2619
  }, string | Command<unknown, Record<string, unknown>, string>, unknown, "list_async_tasks">)[]>;
2426
2620
  //#endregion
2621
+ //#region src/stream.d.ts
2622
+ /**
2623
+ * Represents a single subagent invocation observed during a deep agent run.
2624
+ *
2625
+ * @typeParam TOutput - The subagent's output state type. Defaults to
2626
+ * `unknown`; inferred to the subagent's `MergedAgentState` for
2627
+ * `CompiledSubAgent` via {@link SubagentRunStreamUnion}.
2628
+ */
2629
+ interface SubagentRunStream<TOutput = unknown, TTools extends readonly (ClientTool | ServerTool)[] = readonly (ClientTool | ServerTool)[]> {
2630
+ readonly name: string;
2631
+ readonly taskInput: Promise<string>;
2632
+ readonly output: Promise<TOutput>;
2633
+ readonly messages: AsyncIterable<ChatModelStream>;
2634
+ readonly toolCalls: AsyncIterable<ToolCallStreamUnion<TTools>>;
2635
+ readonly subagents: AsyncIterable<SubagentRunStream>;
2636
+ }
2637
+ /**
2638
+ * Extract the output state type from a subagent spec.
2639
+ * For `CompiledSubAgent<ReactAgent<Types>>`, resolves to the agent's
2640
+ * invoke return type. Falls back to `unknown` for `SubAgent` and
2641
+ * `AsyncSubAgent`.
2642
+ */
2643
+ type SubagentOutputOf<T extends AnySubAgent> = T extends CompiledSubAgent<infer R> ? R extends ReactAgent<infer Types> ? Awaited<ReturnType<ReactAgent<Types>["invoke"]>> : unknown : unknown;
2644
+ /**
2645
+ * Extract the tools tuple from a subagent spec.
2646
+ * For `CompiledSubAgent<ReactAgent<Types>>`, resolves to `Types["Tools"]`.
2647
+ * Falls back to the default `(ClientTool | ServerTool)[]` for `SubAgent`
2648
+ * and `AsyncSubAgent`.
2649
+ */
2650
+ type SubagentToolsOf<T extends AnySubAgent> = T extends CompiledSubAgent<infer R> ? R extends ReactAgent<infer Types> ? Types["Tools"] : readonly (ClientTool | ServerTool)[] : readonly (ClientTool | ServerTool)[];
2651
+ /**
2652
+ * A typed `SubagentRunStream` variant for a single subagent spec.
2653
+ * Narrows `.name` to the literal string type, `.output` to the
2654
+ * inferred state type, and `.toolCalls` to the subagent's tools
2655
+ * when available.
2656
+ */
2657
+ type NamedSubagentRunStream<T extends AnySubAgent> = T extends {
2658
+ name: infer N extends string;
2659
+ } ? SubagentRunStream<SubagentOutputOf<T>, SubagentToolsOf<T>> & {
2660
+ readonly name: N;
2661
+ } : SubagentRunStream;
2662
+ /**
2663
+ * Discriminated union of {@link SubagentRunStream} variants, one per
2664
+ * subagent in `TSubagents`. Enables TypeScript to narrow `.output`
2665
+ * when the consumer checks `sub.name === "someSubagentName"`.
2666
+ */
2667
+ type SubagentRunStreamUnion<TSubagents extends readonly AnySubAgent[]> = { [K in keyof TSubagents]: NamedSubagentRunStream<TSubagents[K]> }[number];
2668
+ /**
2669
+ * An {@link AgentRunStream} with native deep-agent projections assigned
2670
+ * directly on the instance by `createGraphRunStream` (via `__native`
2671
+ * transformers).
2672
+ *
2673
+ * This is a pure type overlay — no runtime class exists. The
2674
+ * `subagents` property is populated at runtime by the
2675
+ * `createSubagentTransformer` registered at compile time.
2676
+ */
2677
+ type DeepAgentRunStream<TValues = Record<string, unknown>, TTools extends readonly (ClientTool | ServerTool)[] = readonly (ClientTool | ServerTool)[], TSubagents extends readonly AnySubAgent[] = readonly AnySubAgent[], TExtensions extends Record<string, unknown> = Record<string, unknown>> = AgentRunStream<TValues, TTools, TExtensions> & {
2678
+ /** Subagent invocation streams from the native SubagentTransformer. */subagents: AsyncIterable<SubagentRunStreamUnion<TSubagents>>;
2679
+ };
2680
+ interface SubagentProjection {
2681
+ subagents: AsyncIterable<SubagentRunStream>;
2682
+ }
2683
+ /**
2684
+ * Native transformer that correlates `task` tool calls into
2685
+ * {@link SubagentRunStream} objects and routes child-namespace
2686
+ * `tools` and `messages` events into per-subagent channels.
2687
+ *
2688
+ * Marked `__native: true` — the `subagents` projection key lands
2689
+ * directly on the `GraphRunStream` instance as `run.subagents`.
2690
+ */
2691
+ declare function createSubagentTransformer(path: Namespace): () => NativeStreamTransformer<SubagentProjection>;
2692
+ //#endregion
2427
2693
  //#region src/types.d.ts
2428
2694
  type AnyAnnotationRoot = AnnotationRoot<any>;
2695
+ /**
2696
+ * Literal union of all built-in deep agent tool names.
2697
+ * These are always present on the agent regardless of user-provided tools.
2698
+ */
2699
+ type DeepAgentBuiltinToolName = (typeof FILESYSTEM_TOOL_NAMES)[number] | (typeof ASYNC_TASK_TOOL_NAMES)[number] | "task" | "write_todos";
2700
+ /**
2701
+ * A placeholder StructuredTool type with a literal `name` for each
2702
+ * built-in tool. Used to thread built-in tool names into the
2703
+ * `ToolCallStreamUnion` so they appear in `run.toolCalls` alongside
2704
+ * user-provided tools.
2705
+ */
2706
+ type BuiltinToolPlaceholder<N extends string> = {
2707
+ name: N;
2708
+ } & StructuredTool$1;
2709
+ /**
2710
+ * Tuple of placeholder tool types for all built-in deep agent tools.
2711
+ * Combined with `TTypes["Tools"]` in the `DeepAgentRunStream` return type.
2712
+ */
2713
+ type DeepAgentBuiltinToolsTuple = { [K in DeepAgentBuiltinToolName]: BuiltinToolPlaceholder<K> }[DeepAgentBuiltinToolName][];
2714
+ type InferDeepAgentStreamExtensions<T extends ReadonlyArray<() => StreamTransformer<any>>> = T extends readonly [] ? Record<string, never> : T extends readonly [() => StreamTransformer<infer P>, ...infer Rest extends ReadonlyArray<() => StreamTransformer<any>>] ? P & InferDeepAgentStreamExtensions<Rest> : Record<string, unknown>;
2429
2715
  /** Any subagent specification — sync, compiled, or async. */
2430
2716
  type AnySubAgent = SubAgent | CompiledSubAgent | AsyncSubAgent;
2431
2717
  interface TypedToolStrategy<T = unknown> extends Array<ToolStrategy<any>> {
@@ -2506,7 +2792,7 @@ type InferStructuredResponse<T extends SupportedResponseFormat> = SupportedRespo
2506
2792
  * type Types = InferDeepAgentType<typeof agent, "Subagents">;
2507
2793
  * ```
2508
2794
  */
2509
- interface DeepAgentTypeConfig<TResponse extends Record<string, any> | ResponseFormatUndefined = Record<string, any> | ResponseFormatUndefined, TState extends AnyAnnotationRoot | InteropZodObject | undefined = AnyAnnotationRoot | InteropZodObject | undefined, TContext extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot | InteropZodObject, TMiddleware extends readonly AgentMiddleware[] = readonly AgentMiddleware[], TTools extends readonly (ClientTool | ServerTool)[] = readonly (ClientTool | ServerTool)[], TSubagents extends readonly AnySubAgent[] = readonly AnySubAgent[]> extends AgentTypeConfig<TResponse, TState, TContext, TMiddleware, TTools> {
2795
+ interface DeepAgentTypeConfig<TResponse extends Record<string, any> | ResponseFormatUndefined = Record<string, any> | ResponseFormatUndefined, TState extends AnyAnnotationRoot | InteropZodObject | undefined = AnyAnnotationRoot | InteropZodObject | undefined, TContext extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot | InteropZodObject, TMiddleware extends readonly AgentMiddleware[] = readonly AgentMiddleware[], TTools extends readonly (ClientTool | ServerTool)[] = readonly (ClientTool | ServerTool)[], TSubagents extends readonly AnySubAgent[] = readonly AnySubAgent[], TStreamTransformers extends ReadonlyArray<() => StreamTransformer<any>> = ReadonlyArray<() => StreamTransformer<any>>> extends AgentTypeConfig<TResponse, TState, TContext, TMiddleware, TTools, TStreamTransformers> {
2510
2796
  /** The subagents array type for type-safe streaming */
2511
2797
  Subagents: TSubagents;
2512
2798
  }
@@ -2521,6 +2807,7 @@ interface DefaultDeepAgentTypeConfig extends DeepAgentTypeConfig {
2521
2807
  Middleware: readonly AgentMiddleware[];
2522
2808
  Tools: readonly (ClientTool | ServerTool)[];
2523
2809
  Subagents: readonly AnySubAgent[];
2810
+ StreamTransformers: readonly [];
2524
2811
  }
2525
2812
  /**
2526
2813
  * DeepAgent extends ReactAgent with additional subagent type information.
@@ -2538,9 +2825,86 @@ interface DefaultDeepAgentTypeConfig extends DeepAgentTypeConfig {
2538
2825
  * type Subagents = InferDeepAgentSubagents<typeof agent>;
2539
2826
  * ```
2540
2827
  */
2541
- type DeepAgent<TTypes extends DeepAgentTypeConfig = DeepAgentTypeConfig> = ReactAgent<TTypes> & {
2542
- /** Type brand for DeepAgent type inference */readonly "~deepAgentTypes": TTypes;
2543
- };
2828
+ interface DeepAgent<TTypes extends DeepAgentTypeConfig = DeepAgentTypeConfig> extends ReactAgent<TTypes> {
2829
+ /** Type brand for DeepAgent type inference */
2830
+ readonly "~deepAgentTypes": TTypes;
2831
+ /**
2832
+ * Executes the agent with the v3 streaming interface, returning an
2833
+ * {@link DeepAgentRunStream} that provides ergonomic, typed projections for
2834
+ * messages, tool calls, subagents, and middleware events.
2835
+ *
2836
+ * Pass `version: "v3"` to opt into this projection-oriented stream. Omitting
2837
+ * `version` preserves the legacy internal LangGraph event-stream behavior
2838
+ * for compatibility with LangGraph Platform integrations.
2839
+ *
2840
+ * This v3 stream is experimental and its API may change in future releases.
2841
+ * It will become the default in a future major release.
2842
+ *
2843
+ * @param state - The initial state for the agent execution. Can be:
2844
+ * - An object containing `messages` array and any middleware-specific state properties
2845
+ * - A Command object for more advanced control flow
2846
+ *
2847
+ * @param config - Runtime configuration including:
2848
+ * @param config.version - Must be `"v3"` to use the {@link DeepAgentRunStream}
2849
+ * interface. The default legacy event stream is maintained for internal
2850
+ * integrations and should not be used for new user-facing agent streaming.
2851
+ * @param config.context - The context for the agent execution.
2852
+ * @param config.configurable - LangGraph configuration options like `thread_id`, `run_id`, etc.
2853
+ * @param config.store - The store for the agent execution for persisting state.
2854
+ * @param config.signal - An optional AbortSignal for the agent execution.
2855
+ * @param config.recursionLimit - The recursion limit for the agent execution.
2856
+ *
2857
+ * @returns A Promise that resolves to an {@link DeepAgentRunStream} providing:
2858
+ * - `run.messages` — all AI message lifecycles with streaming `.text` and `.reasoning`
2859
+ * - `run.toolCalls` — individual tool call streams with `.input`, `.output`, `.status`
2860
+ * - `run.subagents` — subagent delegation streams
2861
+ * - `run.middleware` — middleware lifecycle events (before/after agent/model)
2862
+ * - `run.values` — state snapshots (async iterable + promise-like)
2863
+ * - `run.output` — final agent state when the run completes
2864
+ * - `run.subgraphs` — child subgraph run streams
2865
+ * - `run.extensions` — merged projections from user-supplied transformers
2866
+ *
2867
+ * @example
2868
+ * ```typescript
2869
+ * const run = await agent.streamEvents(
2870
+ * {
2871
+ * messages: [{ role: "user", content: "What's the weather in Paris?" }],
2872
+ * },
2873
+ * { version: "v3" }
2874
+ * );
2875
+ *
2876
+ * // Stream all messages
2877
+ * for await (const msg of run.messages) {
2878
+ * for await (const token of msg.text) {
2879
+ * process.stdout.write(token);
2880
+ * }
2881
+ * }
2882
+ *
2883
+ * // Observe tool calls
2884
+ * for await (const call of run.toolCalls) {
2885
+ * console.log(`Tool: ${call.name}`, call.input);
2886
+ * console.log(`Result:`, await call.output);
2887
+ * }
2888
+ *
2889
+ * // Observe subagent delegations
2890
+ * for await (const subagent of run.subagents) {
2891
+ * console.log(`Subagent: ${subagent.name}`);
2892
+ *
2893
+ * for await (const msg of subagent.messages) {
2894
+ * for await (const token of msg.text) {
2895
+ * process.stdout.write(token);
2896
+ * }
2897
+ * }
2898
+ * }
2899
+ *
2900
+ * // Get final state
2901
+ * const state = await run.output;
2902
+ * ```
2903
+ */
2904
+ streamEvents: ((state: Parameters<ReactAgent<TTypes>["invoke"]>[0], config: NonNullable<Parameters<ReactAgent<TTypes>["invoke"]>[1]> & {
2905
+ version: "v3";
2906
+ }) => Promise<DeepAgentRunStream<Awaited<ReturnType<ReactAgent<TTypes>["invoke"]>>, readonly [...TTypes["Tools"], ...DeepAgentBuiltinToolsTuple], TTypes["Subagents"], InferDeepAgentStreamExtensions<TTypes["StreamTransformers"]>>>) & ReactAgent<TTypes>["streamEvents"];
2907
+ }
2544
2908
  /**
2545
2909
  * Helper type to resolve a DeepAgentTypeConfig from either:
2546
2910
  * - A DeepAgentTypeConfig directly
@@ -2620,8 +2984,9 @@ type InferSubagentReactAgentType<TSubagent extends SubAgent | CompiledSubAgent>
2620
2984
  * @typeParam TMiddleware - The middleware array type for proper type inference
2621
2985
  * @typeParam TSubagents - The subagents array type for extracting subagent middleware states
2622
2986
  * @typeParam TTools - The tools array type
2987
+ * @typeParam TStreamTransformers - Custom stream transformer factories
2623
2988
  */
2624
- interface CreateDeepAgentParams<TResponse extends SupportedResponseFormat = SupportedResponseFormat, ContextSchema extends AnnotationRoot<any> | InteropZodObject = AnnotationRoot<any>, TMiddleware extends readonly AgentMiddleware[] = readonly AgentMiddleware[], TSubagents extends readonly AnySubAgent[] = readonly AnySubAgent[], TTools extends readonly (ClientTool | ServerTool)[] = readonly (ClientTool | ServerTool)[]> {
2989
+ interface CreateDeepAgentParams<TResponse extends SupportedResponseFormat = SupportedResponseFormat, ContextSchema extends AnnotationRoot<any> | InteropZodObject = AnnotationRoot<any>, TMiddleware extends readonly AgentMiddleware[] = readonly AgentMiddleware[], TSubagents extends readonly AnySubAgent[] = readonly AnySubAgent[], TTools extends readonly (ClientTool | ServerTool)[] = readonly (ClientTool | ServerTool)[], TStreamTransformers extends ReadonlyArray<() => StreamTransformer<any>> = readonly []> {
2625
2990
  /** The model to use (model name string or LanguageModelLike instance). Defaults to claude-sonnet-4-5-20250929 */
2626
2991
  model?: BaseLanguageModel | string;
2627
2992
  /** Tools the agent should have access to */
@@ -2697,6 +3062,33 @@ interface CreateDeepAgentParams<TResponse extends SupportedResponseFormat = Supp
2697
3062
  * ```
2698
3063
  */
2699
3064
  skills?: string[];
3065
+ /**
3066
+ * Filesystem permission rules for this agent.
3067
+ *
3068
+ * Rules are evaluated in declaration order; first match wins; permissive
3069
+ * default. Applied to `ls`, `read_file`, `write_file`, `edit_file`, `glob`,
3070
+ * and `grep`. Subagents inherit these rules unless they specify their own
3071
+ * `permissions` field.
3072
+ *
3073
+ * @example
3074
+ * ```ts
3075
+ * createDeepAgent({
3076
+ * permissions: [
3077
+ * { operations: ["read"], paths: ["/workspace/**"] },
3078
+ * { operations: ["read"], paths: ["/**"], mode: "deny" },
3079
+ * ],
3080
+ * });
3081
+ * ```
3082
+ */
3083
+ permissions?: FilesystemPermission[];
3084
+ /**
3085
+ * Optional {@link StreamTransformer} factories to register with the underlying agent.
3086
+ *
3087
+ * Deepagents always registers its built-in subagent transformer; custom
3088
+ * transformers are appended after it and are exposed on `run.extensions`
3089
+ * when using `streamEvents(..., { version: "v3" })`.
3090
+ */
3091
+ streamTransformers?: TStreamTransformers;
2700
3092
  }
2701
3093
  //#endregion
2702
3094
  //#region src/agent.d.ts
@@ -2730,7 +3122,7 @@ interface CreateDeepAgentParams<TResponse extends SupportedResponseFormat = Supp
2730
3122
  * // result.research is properly typed as string
2731
3123
  * ```
2732
3124
  */
2733
- declare function createDeepAgent<TResponse extends SupportedResponseFormat = SupportedResponseFormat, ContextSchema extends InteropZodObject = InteropZodObject, const TMiddleware extends readonly AgentMiddleware[] = readonly [], const TSubagents extends readonly AnySubAgent[] = readonly [], const TTools extends readonly (ClientTool | ServerTool)[] = readonly []>(params?: CreateDeepAgentParams<TResponse, ContextSchema, TMiddleware, TSubagents, TTools>): DeepAgent<DeepAgentTypeConfig<InferStructuredResponse<TResponse>, undefined, ContextSchema, readonly [AgentMiddleware<_$zod_v30.ZodObject<{
3125
+ declare function createDeepAgent<TResponse extends SupportedResponseFormat = SupportedResponseFormat, ContextSchema extends InteropZodObject = InteropZodObject, const TMiddleware extends readonly AgentMiddleware[] = readonly [], const TSubagents extends readonly AnySubAgent[] = readonly [], const TTools extends readonly (ClientTool | ServerTool)[] = readonly [], const TStreamTransformers extends ReadonlyArray<() => StreamTransformer<any>> = readonly []>(params?: CreateDeepAgentParams<TResponse, ContextSchema, TMiddleware, TSubagents, TTools, TStreamTransformers>): DeepAgent<DeepAgentTypeConfig<InferStructuredResponse<TResponse>, undefined, ContextSchema, readonly [AgentMiddleware<_$zod_v30.ZodObject<{
2734
3126
  todos: _$zod_v30.ZodDefault<_$zod_v30.ZodArray<_$zod_v30.ZodObject<{
2735
3127
  content: _$zod_v30.ZodString;
2736
3128
  status: _$zod_v30.ZodEnum<["pending", "in_progress", "completed"]>;
@@ -2888,7 +3280,7 @@ declare function createDeepAgent<TResponse extends SupportedResponseFormat = Sup
2888
3280
  summaryMessage: z$2.ZodCustom<_messages.HumanMessage<_messages.MessageStructure<_messages.MessageToolSet>>, _messages.HumanMessage<_messages.MessageStructure<_messages.MessageToolSet>>>;
2889
3281
  filePath: z$2.ZodNullable<z$2.ZodString>;
2890
3282
  }, _$zod_v4_core0.$strip>>;
2891
- }, _$zod_v4_core0.$strip>, undefined, unknown, readonly (ClientTool | ServerTool)[]>, AgentMiddleware<undefined, undefined, unknown, readonly (ClientTool | ServerTool)[]>, ...TMiddleware, ...FlattenSubAgentMiddleware<TSubagents>], TTools, TSubagents>>;
3283
+ }, _$zod_v4_core0.$strip>, undefined, unknown, readonly (ClientTool | ServerTool)[]>, AgentMiddleware<undefined, undefined, unknown, readonly (ClientTool | ServerTool)[]>, ...TMiddleware, ...FlattenSubAgentMiddleware<TSubagents>], TTools, TSubagents, TStreamTransformers>>;
2892
3284
  //#endregion
2893
3285
  //#region src/errors.d.ts
2894
3286
  /**
@@ -3135,5 +3527,5 @@ declare function parseSkillMetadata(skillMdPath: string, source: "user" | "proje
3135
3527
  */
3136
3528
  declare function listSkills(options: ListSkillsOptions): SkillMetadata[];
3137
3529
  //#endregion
3138
- export { type AgentMemoryMiddlewareOptions, type AnyBackendProtocol, type AnySubAgent, type AsyncSubAgent, type AsyncSubAgentMiddlewareOptions, type AsyncTask, type AsyncTaskStatus, type BackendFactory, type BackendProtocol, type BackendProtocolV1, type BackendProtocolV2, type BackendRuntime, BaseSandbox, type CompiledSubAgent, type CompletionCallbackOptions, CompositeBackend, ConfigurationError, type ConfigurationErrorCode, type CreateDeepAgentParams, DEFAULT_GENERAL_PURPOSE_DESCRIPTION, DEFAULT_SUBAGENT_PROMPT, type DeepAgent, type DeepAgentTypeConfig, type DefaultDeepAgentTypeConfig, type EditResult, type ExecuteResponse, type ExtractSubAgentMiddleware, type FileData, type FileDownloadResponse, type FileInfo, type FileOperationError, type FileUploadResponse, FilesystemBackend, type FilesystemMiddlewareOptions, type FlattenSubAgentMiddleware, GENERAL_PURPOSE_SUBAGENT, type GlobResult, type GrepMatch, type GrepResult, type InferDeepAgentSubagents, type InferDeepAgentType, type InferStructuredResponse, type InferSubAgentMiddlewareStates, type InferSubagentByName, type InferSubagentReactAgentType, LangSmithSandbox, type LangSmithSandboxOptions, type ListSkillsOptions, type SkillMetadata as LoaderSkillMetadata, LocalShellBackend, type LocalShellBackendOptions, type LsResult, MAX_SKILL_DESCRIPTION_LENGTH, MAX_SKILL_FILE_SIZE, MAX_SKILL_NAME_LENGTH, type MaybePromise, type MemoryMiddlewareOptions, type MergedDeepAgentState, type ReadRawResult, type ReadResult, type ResolveDeepAgentTypeConfig, type SandboxBackendProtocol, type SandboxBackendProtocolV1, type SandboxBackendProtocolV2, type SandboxDeleteOptions, SandboxError, type SandboxErrorCode, type SandboxGetOrCreateOptions, type SandboxInfo, type SandboxListOptions, type SandboxListResponse, type Settings, type SettingsOptions, type SkillMetadata$1 as SkillMetadata, type SkillsMiddlewareOptions, type StateAndStore, StateBackend, StoreBackend, type StoreBackendOptions, type SubAgent, type SubAgentMiddlewareOptions, type SupportedResponseFormat, TASK_SYSTEM_PROMPT, type WriteResult, adaptBackendProtocol, adaptSandboxProtocol, computeSummarizationDefaults, createAgentMemoryMiddleware, createAsyncSubAgentMiddleware, createCompletionCallbackMiddleware, createDeepAgent, createFilesystemMiddleware, createMemoryMiddleware, createPatchToolCallsMiddleware, createSettings, createSkillsMiddleware, createSubAgentMiddleware, createSummarizationMiddleware, filesValue, findProjectRoot, isAsyncSubAgent, isSandboxBackend, isSandboxProtocol, listSkills, parseSkillMetadata, resolveBackend };
3530
+ export { type AgentMemoryMiddlewareOptions, type AnyBackendProtocol, type AnySubAgent, type AsyncSubAgent, type AsyncSubAgentMiddlewareOptions, type AsyncTask, type AsyncTaskStatus, type BackendFactory, type BackendProtocol, type BackendProtocolV1, type BackendProtocolV2, type BackendRuntime, BaseSandbox, type CompiledSubAgent, type CompletionCallbackOptions, CompositeBackend, ConfigurationError, type ConfigurationErrorCode, type CreateDeepAgentParams, DEFAULT_GENERAL_PURPOSE_DESCRIPTION, DEFAULT_SUBAGENT_PROMPT, type DeepAgent, type DeepAgentRunStream, type DeepAgentTypeConfig, type DefaultDeepAgentTypeConfig, type EditResult, type ExecuteResponse, type ExtractSubAgentMiddleware, type FileData, type FileDownloadResponse, type FileInfo, type FileOperationError, type FileUploadResponse, FilesystemBackend, type FilesystemMiddlewareOptions, type FilesystemOperation, type FilesystemPermission, type FlattenSubAgentMiddleware, GENERAL_PURPOSE_SUBAGENT, type GlobResult, type GrepMatch, type GrepResult, type InferDeepAgentSubagents, type InferDeepAgentType, type InferStructuredResponse, type InferSubAgentMiddlewareStates, type InferSubagentByName, type InferSubagentReactAgentType, LangSmithSandbox, type LangSmithSandboxOptions, type ListSkillsOptions, type SkillMetadata as LoaderSkillMetadata, LocalShellBackend, type LocalShellBackendOptions, type LsResult, MAX_SKILL_DESCRIPTION_LENGTH, MAX_SKILL_FILE_SIZE, MAX_SKILL_NAME_LENGTH, type MaybePromise, type MemoryMiddlewareOptions, type MergedDeepAgentState, type PermissionMode, type ReadRawResult, type ReadResult, type ResolveDeepAgentTypeConfig, type SandboxBackendProtocol, type SandboxBackendProtocolV1, type SandboxBackendProtocolV2, type SandboxDeleteOptions, SandboxError, type SandboxErrorCode, type SandboxGetOrCreateOptions, type SandboxInfo, type SandboxListOptions, type SandboxListResponse, type Settings, type SettingsOptions, type SkillMetadata$1 as SkillMetadata, type SkillsMiddlewareOptions, type StateAndStore, StateBackend, StoreBackend, type StoreBackendContext, type StoreBackendNamespaceFactory, type StoreBackendOptions, type SubAgent, type SubAgentMiddlewareOptions, type SubagentRunStream, type SupportedResponseFormat, TASK_SYSTEM_PROMPT, type WriteResult, adaptBackendProtocol, adaptSandboxProtocol, computeSummarizationDefaults, createAgentMemoryMiddleware, createAsyncSubAgentMiddleware, createCompletionCallbackMiddleware, createDeepAgent, createFilesystemMiddleware, createMemoryMiddleware, createPatchToolCallsMiddleware, createSettings, createSkillsMiddleware, createSubAgentMiddleware, createSubagentTransformer, createSummarizationMiddleware, filesValue, findProjectRoot, isAsyncSubAgent, isSandboxBackend, isSandboxProtocol, listSkills, parseSkillMetadata, resolveBackend };
3139
3531
  //# sourceMappingURL=index.d.ts.map