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