@librechat/agents 3.5.0 → 3.6.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.
Files changed (188) hide show
  1. package/dist/cjs/agents/AgentContext.cjs +5 -2
  2. package/dist/cjs/agents/AgentContext.cjs.map +1 -1
  3. package/dist/cjs/graphs/Graph.cjs +148 -22
  4. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  5. package/dist/cjs/graphs/MultiAgentGraph.cjs +2 -1
  6. package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
  7. package/dist/cjs/main.cjs +4 -0
  8. package/dist/cjs/run.cjs +29 -11
  9. package/dist/cjs/run.cjs.map +1 -1
  10. package/dist/cjs/stream.cjs +8 -6
  11. package/dist/cjs/stream.cjs.map +1 -1
  12. package/dist/cjs/tools/BashExecutor.cjs +8 -7
  13. package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
  14. package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +5 -4
  15. package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -1
  16. package/dist/cjs/tools/CodeExecutor.cjs +26 -7
  17. package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
  18. package/dist/cjs/tools/ProgrammaticToolCalling.cjs +7 -6
  19. package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
  20. package/dist/cjs/tools/ToolNode.cjs +33 -10
  21. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  22. package/dist/cjs/tools/ToolSearch.cjs +1 -1
  23. package/dist/cjs/tools/ToolSearch.cjs.map +1 -1
  24. package/dist/cjs/tools/runStepResume.cjs +51 -0
  25. package/dist/cjs/tools/runStepResume.cjs.map +1 -0
  26. package/dist/cjs/tools/subagent/SubagentExecutor.cjs +15 -43
  27. package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
  28. package/dist/cjs/tools/subagent/SubagentReplay.cjs +6 -1
  29. package/dist/cjs/tools/subagent/SubagentReplay.cjs.map +1 -1
  30. package/dist/cjs/utils/toolSessions.cjs +63 -0
  31. package/dist/cjs/utils/toolSessions.cjs.map +1 -0
  32. package/dist/esm/agents/AgentContext.mjs +5 -2
  33. package/dist/esm/agents/AgentContext.mjs.map +1 -1
  34. package/dist/esm/graphs/Graph.mjs +148 -22
  35. package/dist/esm/graphs/Graph.mjs.map +1 -1
  36. package/dist/esm/graphs/MultiAgentGraph.mjs +2 -1
  37. package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
  38. package/dist/esm/main.mjs +2 -2
  39. package/dist/esm/run.mjs +29 -11
  40. package/dist/esm/run.mjs.map +1 -1
  41. package/dist/esm/stream.mjs +8 -6
  42. package/dist/esm/stream.mjs.map +1 -1
  43. package/dist/esm/tools/BashExecutor.mjs +9 -8
  44. package/dist/esm/tools/BashExecutor.mjs.map +1 -1
  45. package/dist/esm/tools/BashProgrammaticToolCalling.mjs +6 -5
  46. package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -1
  47. package/dist/esm/tools/CodeExecutor.mjs +23 -8
  48. package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
  49. package/dist/esm/tools/ProgrammaticToolCalling.mjs +8 -7
  50. package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
  51. package/dist/esm/tools/ToolNode.mjs +33 -10
  52. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  53. package/dist/esm/tools/ToolSearch.mjs +2 -2
  54. package/dist/esm/tools/ToolSearch.mjs.map +1 -1
  55. package/dist/esm/tools/runStepResume.mjs +48 -0
  56. package/dist/esm/tools/runStepResume.mjs.map +1 -0
  57. package/dist/esm/tools/subagent/SubagentExecutor.mjs +15 -43
  58. package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
  59. package/dist/esm/tools/subagent/SubagentReplay.mjs +6 -1
  60. package/dist/esm/tools/subagent/SubagentReplay.mjs.map +1 -1
  61. package/dist/esm/utils/toolSessions.mjs +62 -0
  62. package/dist/esm/utils/toolSessions.mjs.map +1 -0
  63. package/dist/types/agents/AgentContext.d.ts +7 -4
  64. package/dist/types/agents/projection.d.ts +1 -1
  65. package/dist/types/events.d.ts +2 -2
  66. package/dist/types/graphs/Graph.d.ts +22 -14
  67. package/dist/types/graphs/MultiAgentGraph.d.ts +2 -2
  68. package/dist/types/graphs/createGraph.d.ts +4 -4
  69. package/dist/types/graphs/graphFactory.d.ts +1 -1
  70. package/dist/types/hitl/askUserQuestion.d.ts +1 -1
  71. package/dist/types/hitl/askUserQuestions.d.ts +1 -1
  72. package/dist/types/hitl/askUserQuestionsInterrupt.d.ts +1 -1
  73. package/dist/types/hooks/types.d.ts +1 -1
  74. package/dist/types/instrumentation.d.ts +1 -1
  75. package/dist/types/langfuse.d.ts +3 -3
  76. package/dist/types/langfuseConfig.d.ts +2 -2
  77. package/dist/types/langfuseRuntimeContext.d.ts +1 -1
  78. package/dist/types/langfuseRuntimeScope.d.ts +2 -2
  79. package/dist/types/langfuseSpanRegistry.d.ts +1 -1
  80. package/dist/types/langfuseToolOutputTracing.d.ts +3 -3
  81. package/dist/types/llm/anthropic/index.d.ts +1 -1
  82. package/dist/types/llm/bedrock/index.d.ts +1 -1
  83. package/dist/types/llm/bedrock/toolCache.d.ts +2 -2
  84. package/dist/types/llm/contextOverflowRecovery.d.ts +2 -2
  85. package/dist/types/llm/google/index.d.ts +1 -1
  86. package/dist/types/llm/init.d.ts +2 -2
  87. package/dist/types/llm/invoke.d.ts +6 -6
  88. package/dist/types/llm/mistral/index.d.ts +1 -1
  89. package/dist/types/llm/openai/index.d.ts +2 -2
  90. package/dist/types/llm/openrouter/index.d.ts +2 -2
  91. package/dist/types/llm/openrouter/toolCache.d.ts +2 -2
  92. package/dist/types/llm/providers.d.ts +2 -2
  93. package/dist/types/llm/request.d.ts +2 -2
  94. package/dist/types/llm/stream/chunkAdapters.d.ts +1 -1
  95. package/dist/types/llm/streamLimits.d.ts +1 -1
  96. package/dist/types/llm/truncation.d.ts +1 -1
  97. package/dist/types/llm/vertexai/index.d.ts +1 -1
  98. package/dist/types/messages/alternation.d.ts +1 -1
  99. package/dist/types/messages/anthropicToolCache.d.ts +2 -2
  100. package/dist/types/messages/assistantPhase.d.ts +3 -3
  101. package/dist/types/messages/budget.d.ts +1 -1
  102. package/dist/types/messages/cache.d.ts +1 -1
  103. package/dist/types/messages/contextPruning.d.ts +2 -2
  104. package/dist/types/messages/core.d.ts +2 -2
  105. package/dist/types/messages/format.d.ts +2 -2
  106. package/dist/types/messages/ids.d.ts +2 -2
  107. package/dist/types/messages/injected.d.ts +1 -1
  108. package/dist/types/messages/langchain.d.ts +1 -1
  109. package/dist/types/messages/prune.d.ts +3 -3
  110. package/dist/types/openai/index.d.ts +1 -1
  111. package/dist/types/prompts/activityLabel.d.ts +2 -2
  112. package/dist/types/responses/index.d.ts +1 -1
  113. package/dist/types/run.d.ts +3 -3
  114. package/dist/types/session/handlers.d.ts +1 -1
  115. package/dist/types/session/types.d.ts +1 -1
  116. package/dist/types/stream.d.ts +4 -4
  117. package/dist/types/summarization/index.d.ts +1 -1
  118. package/dist/types/summarization/node.d.ts +6 -6
  119. package/dist/types/tools/BashExecutor.d.ts +2 -2
  120. package/dist/types/tools/BashProgrammaticToolCalling.d.ts +2 -2
  121. package/dist/types/tools/CodeExecutor.d.ts +7 -3
  122. package/dist/types/tools/CodeSessionFileSummary.d.ts +1 -1
  123. package/dist/types/tools/ProgrammaticToolCalling.d.ts +3 -3
  124. package/dist/types/tools/ReadFile.d.ts +1 -1
  125. package/dist/types/tools/SkillTool.d.ts +1 -1
  126. package/dist/types/tools/SubagentTool.d.ts +3 -3
  127. package/dist/types/tools/ToolNode.d.ts +8 -6
  128. package/dist/types/tools/ToolSearch.d.ts +2 -2
  129. package/dist/types/tools/cloudflare/CloudflareBridgeRuntime.d.ts +1 -1
  130. package/dist/types/tools/cloudflare/CloudflareProgrammaticToolCalling.d.ts +1 -1
  131. package/dist/types/tools/cloudflare/CloudflareSandboxExecutionEngine.d.ts +2 -2
  132. package/dist/types/tools/cloudflare/CloudflareSandboxTools.d.ts +1 -1
  133. package/dist/types/tools/eagerEventExecution.d.ts +1 -1
  134. package/dist/types/tools/handlers.d.ts +3 -3
  135. package/dist/types/tools/intentArg.d.ts +1 -1
  136. package/dist/types/tools/local/CompileCheckTool.d.ts +2 -2
  137. package/dist/types/tools/local/FileCheckpointer.d.ts +1 -1
  138. package/dist/types/tools/local/LocalCodingTools.d.ts +2 -2
  139. package/dist/types/tools/local/LocalExecutionEngine.d.ts +1 -1
  140. package/dist/types/tools/local/LocalExecutionTools.d.ts +1 -1
  141. package/dist/types/tools/local/LocalProgrammaticToolCalling.d.ts +1 -1
  142. package/dist/types/tools/local/bashAst.d.ts +1 -1
  143. package/dist/types/tools/local/resolveLocalExecutionTools.d.ts +1 -1
  144. package/dist/types/tools/local/syntaxCheck.d.ts +1 -1
  145. package/dist/types/tools/ptcTimeout.d.ts +1 -1
  146. package/dist/types/tools/runStepResume.d.ts +5 -0
  147. package/dist/types/tools/schema.d.ts +1 -1
  148. package/dist/types/tools/search/anthropic.d.ts +1 -1
  149. package/dist/types/tools/skillCatalog.d.ts +1 -1
  150. package/dist/types/tools/subagent/SubagentExecutor.d.ts +30 -5
  151. package/dist/types/tools/subagent/SubagentReplay.d.ts +4 -3
  152. package/dist/types/tools/subagent/childGraphConfig.d.ts +2 -2
  153. package/dist/types/types/activityLabel.d.ts +3 -3
  154. package/dist/types/types/graph.d.ts +16 -7
  155. package/dist/types/types/llm.d.ts +9 -9
  156. package/dist/types/types/run.d.ts +7 -7
  157. package/dist/types/types/stream.d.ts +23 -5
  158. package/dist/types/types/summarize.d.ts +2 -2
  159. package/dist/types/types/tools.d.ts +41 -21
  160. package/dist/types/utils/errors.d.ts +1 -1
  161. package/dist/types/utils/events.d.ts +1 -1
  162. package/dist/types/utils/handlers.d.ts +3 -3
  163. package/dist/types/utils/llm.d.ts +1 -1
  164. package/dist/types/utils/llmConfig.d.ts +1 -1
  165. package/dist/types/utils/title.d.ts +1 -1
  166. package/dist/types/utils/toolSessions.d.ts +18 -0
  167. package/package.json +28 -32
  168. package/src/agents/AgentContext.ts +7 -0
  169. package/src/graphs/Graph.ts +192 -13
  170. package/src/graphs/MultiAgentGraph.ts +1 -0
  171. package/src/run.ts +62 -11
  172. package/src/stream.ts +28 -9
  173. package/src/tools/BashExecutor.ts +31 -13
  174. package/src/tools/BashProgrammaticToolCalling.ts +19 -9
  175. package/src/tools/CodeExecutor.ts +57 -16
  176. package/src/tools/ProgrammaticToolCalling.ts +26 -12
  177. package/src/tools/ToolNode.ts +58 -8
  178. package/src/tools/ToolSearch.ts +2 -2
  179. package/src/tools/runStepResume.ts +121 -0
  180. package/src/tools/subagent/SubagentExecutor.ts +67 -65
  181. package/src/tools/subagent/SubagentReplay.ts +22 -1
  182. package/src/types/graph.ts +10 -0
  183. package/src/types/stream.ts +17 -0
  184. package/src/types/tools.ts +50 -21
  185. package/src/utils/toolSessions.ts +113 -0
  186. package/dist/types/agents/__tests__/promptCacheLiveHelpers.d.ts +0 -52
  187. package/dist/types/test/mockTools.d.ts +0 -28
  188. package/dist/types/utils/__tests__/fixtures/contextOverflowSignatures.d.ts +0 -40
@@ -18,7 +18,7 @@
18
18
  * must call {@link stripIntent} before using their args so no tool receives a
19
19
  * parameter it did not declare.
20
20
  */
21
- import type { JsonSchemaType, OutcomePatch } from '../types';
21
+ import type { JsonSchemaType, OutcomePatch } from '@/types';
22
22
  /** Argument carrying the model-authored label for a tool call. */
23
23
  export declare const INTENT_ARG = "intent";
24
24
  /**
@@ -23,8 +23,8 @@
23
23
  * exit code is reported.
24
24
  */
25
25
  import type { DynamicStructuredTool } from '@langchain/core/tools';
26
- import type * as t from '../../types';
27
- import { Constants } from '../../common';
26
+ import type * as t from '@/types';
27
+ import { Constants } from '@/common';
28
28
  /** Back-compat alias; canonical name lives on `Constants.COMPILE_CHECK`. */
29
29
  export declare const CompileCheckToolName = Constants.COMPILE_CHECK;
30
30
  export declare function createCompileCheckTool(config?: t.LocalExecutionConfig): DynamicStructuredTool;
@@ -1,5 +1,5 @@
1
1
  import type { WorkspaceFS } from './workspaceFS';
2
- import type * as t from '../../types';
2
+ import type * as t from '@/types';
3
3
  /**
4
4
  * Per-Run snapshot store for write_file / edit_file. Captures the
5
5
  * pre-write byte content of every path the local engine is about to
@@ -1,6 +1,6 @@
1
1
  import type { DynamicStructuredTool } from '@langchain/core/tools';
2
- import type * as t from '../../types';
3
- import { Constants } from '../../common';
2
+ import type * as t from '@/types';
3
+ import { Constants } from '@/common';
4
4
  /**
5
5
  * Tool name aliases retained for back-compat with consumers that imported
6
6
  * the per-file `Local*ToolName` constants. The canonical names live on
@@ -1,5 +1,5 @@
1
1
  import type { WorkspaceFS } from './workspaceFS';
2
- import type * as t from '../../types';
2
+ import type * as t from '@/types';
3
3
  type SpawnResult = {
4
4
  stdout: string;
5
5
  stderr: string;
@@ -1,5 +1,5 @@
1
1
  import type { DynamicStructuredTool } from '@langchain/core/tools';
2
- import type * as t from '../../types';
2
+ import type * as t from '@/types';
3
3
  export declare const LocalCodeExecutionToolDescription: string;
4
4
  export declare const LocalBashExecutionToolDescription: string;
5
5
  export declare function createLocalCodeExecutionTool(config?: t.LocalExecutionConfig): DynamicStructuredTool;
@@ -1,5 +1,5 @@
1
1
  import type { DynamicStructuredTool } from '@langchain/core/tools';
2
- import type * as t from '../../types';
2
+ import type * as t from '@/types';
3
3
  /**
4
4
  * Run the host's `PreToolUse` hook chain for a single bridge call.
5
5
  * Returns the (possibly rewritten) input and a `denyReason` if any
@@ -1,4 +1,4 @@
1
- import type * as t from '../../types';
1
+ import type * as t from '@/types';
2
2
  export type BashAstFinding = {
3
3
  code: string;
4
4
  message: string;
@@ -1,4 +1,4 @@
1
- import type * as t from '../../types';
1
+ import type * as t from '@/types';
2
2
  type ResolveLocalToolsResult = {
3
3
  toolMap: t.ToolMap;
4
4
  directToolNames: Set<string>;
@@ -15,7 +15,7 @@
15
15
  * is slow and per-file syntax (without type info) misses most TS
16
16
  * errors anyway. Use the project-level `compile_check` tool for that.
17
17
  */
18
- import type * as t from '../../types';
18
+ import type * as t from '@/types';
19
19
  export type SyntaxCheckOutcome = {
20
20
  ok: true;
21
21
  } | {
@@ -1,4 +1,4 @@
1
- import type { JsonSchemaType } from '../types';
1
+ import type { JsonSchemaType } from '@/types';
2
2
  export declare const DEFAULT_CODE_API_RUN_TIMEOUT_MS = 15000;
3
3
  export declare const MIN_CODE_API_RUN_TIMEOUT_MS = 1000;
4
4
  export declare const MAX_CODE_API_RUN_TIMEOUT_SCHEMA_MS = 300000;
@@ -0,0 +1,5 @@
1
+ import type { RunStepResumeState } from '@/types';
2
+ export declare function isRunStepResumeState(value: unknown): value is RunStepResumeState;
3
+ export declare function attachRunStepResumeState(payload: unknown, state: RunStepResumeState): object;
4
+ export declare function getRunStepResumeState(payload: unknown): RunStepResumeState | undefined;
5
+ export declare function stripRunStepResumeState(payload: unknown): unknown;
@@ -1,5 +1,5 @@
1
1
  import { type StructuredToolInterface } from '@langchain/core/tools';
2
- import type { LCTool } from '../types';
2
+ import type { LCTool } from '@/types';
3
3
  /**
4
4
  * Creates a schema-only tool for LLM binding in event-driven mode.
5
5
  * These tools have valid schemas for the LLM to understand but should
@@ -1,4 +1,4 @@
1
- import type { AnthropicTextBlockParam, AnthropicWebSearchResultBlockParam } from '../../llm/anthropic/types';
1
+ import type { AnthropicTextBlockParam, AnthropicWebSearchResultBlockParam } from '@/llm/anthropic/types';
2
2
  import type { SearchResultData } from './types';
3
3
  /**
4
4
  * Coerces Anthropic web search results to the SearchResultData format
@@ -1,4 +1,4 @@
1
- import type { SkillCatalogEntry } from '../types';
1
+ import type { SkillCatalogEntry } from '@/types';
2
2
  export type SkillCatalogOptions = {
3
3
  /** Total context window in tokens. Default: 200_000 */
4
4
  contextWindowTokens?: number;
@@ -1,12 +1,12 @@
1
1
  import { BaseMessage } from '@langchain/core/messages';
2
2
  import type { RunnableConfig } from '@langchain/core/runnables';
3
3
  import type { ToolCall } from '@langchain/core/messages/tool';
4
- import type { MultiAgentGraphState, HumanInTheLoopConfig, StandardGraphInput, ExecutableSubagentConfigEntry, SubagentExecutionContext, SubagentUsageSink, TokenCounter } from '../../types';
4
+ import type { MultiAgentGraphState, HumanInTheLoopConfig, StandardGraphInput, ExecutableSubagentConfigEntry, SubagentExecutionContext, SubagentUsageSink, TokenCounter } from '@/types';
5
5
  import type { SubagentResumeManifest, SettledSubagentToolOutput } from './SubagentReplay';
6
- import type { HookRegistry } from '../../hooks';
7
- import type { GraphFactory } from '../../graphs/graphFactory';
8
- import type { StandardGraph } from '../../graphs/Graph';
9
- import type { HandlerRegistry } from '../../events';
6
+ import type { HookRegistry } from '@/hooks';
7
+ import type { GraphFactory } from '@/graphs/graphFactory';
8
+ import type { StandardGraph } from '@/graphs/Graph';
9
+ import type { HandlerRegistry } from '@/events';
10
10
  export { buildChildInputs, isGraphSubagentConfig, normalizeSubagentConfigs, normalizeSubagentConfigEntries, resolveSubagentConfigs, resolveSubagentConfigEntries, } from './childGraphConfig';
11
11
  export declare const DEFAULT_SUBAGENT_DESCRIPTION = "No task description provided";
12
12
  export type SubagentExecuteParams = {
@@ -207,6 +207,31 @@ export declare class SubagentExecutor {
207
207
  resetCheckpointThreadIds(): void;
208
208
  private getGraphChildCheckpointThreadIds;
209
209
  private clearChildGraph;
210
+ /**
211
+ * Terminal sweep for a child graph's run steps. `Run.processStream` sweeps
212
+ * only the graph it owns, and a child executes through `workflow.invoke()`
213
+ * outside that loop — so without this, a child's last message step (no
214
+ * successor step ever opens to close it) and every step of an aborted child
215
+ * stay `in_progress` forever, leaving hosts with unmatched starts.
216
+ *
217
+ * Must run BEFORE `forwarding.drain()`: closures reach the parent only as
218
+ * child custom events through the forwarder, which stops relaying once
219
+ * drained.
220
+ *
221
+ * Deliberately not called on the interrupt path, mirroring the parent's
222
+ * `isAwaitingResume` guard: an in-process resume continues into these same
223
+ * steps, so closing them would strand the resumed run. A resume that
224
+ * crosses a process boundary is a known gap either way — the child rebuilds
225
+ * from `SubagentGraphResumeState`, which carries tool-call identity but not
226
+ * `contentData`, so pre-interrupt steps are unreachable from the new graph
227
+ * and stay open. That is the child-level instance of the same cross-process
228
+ * orphan the parent graph has, and it needs persisted lifecycle state to
229
+ * fix rather than a sweep here.
230
+ *
231
+ * `at` is the moment execution actually ended, threaded through so
232
+ * observational work between then and the sweep cannot inflate the stamps.
233
+ */
234
+ private closeChildRunSteps;
210
235
  clearHeavyState(): void;
211
236
  private getResumeCheckpointMarker;
212
237
  getSettledToolOutput(call: ToolCall, config: RunnableConfig): Promise<SettledSubagentToolOutput | undefined>;
@@ -1,8 +1,8 @@
1
1
  import type { ToolCall, ToolMessage } from '@langchain/core/messages/tool';
2
2
  import type { RunnableConfig } from '@langchain/core/runnables';
3
- import type { ToolOutputReferenceState } from '../../tools/toolOutputReferences';
4
- import type { ToolApprovalReplaySnapshot } from '../../hooks';
5
- import type { ToolSessionContext } from '../../types';
3
+ import type { ToolOutputReferenceState } from '@/tools/toolOutputReferences';
4
+ import type { ToolApprovalReplaySnapshot } from '@/hooks';
5
+ import type { RunStepResumeState, ToolSessionContext } from '@/types';
6
6
  export declare const SUBAGENT_RESUME_MANIFEST_CONFIG_KEY = "__librechat_subagent_resume_manifest";
7
7
  export declare const SUBAGENT_RESUME_ATTEMPT_CONFIG_KEY = "__librechat_subagent_resume_attempt";
8
8
  export declare const SUBAGENT_PARENT_BATCH_CONFIG_KEY = "__librechat_subagent_parent_batch";
@@ -43,6 +43,7 @@ export interface SubagentGraphResumeState {
43
43
  toolNodes: SubagentToolNodeResumeState[];
44
44
  eagerToolUsage: SubagentEagerToolUsageState[];
45
45
  eagerToolSuppressions: string[];
46
+ runStepState?: RunStepResumeState;
46
47
  toolOutputReferences?: ToolOutputReferenceState;
47
48
  }
48
49
  /** Private checkpoint payload linking a parent pause to an exact child state. */
@@ -1,5 +1,5 @@
1
- import type { AgentInputs, ExecutableSubagentConfig, ExecutableSubagentConfigEntry, GraphEdge, GraphSubagentConfig, ResolvedSubagentConfig, ResolvedSubagentConfigEntry, SubagentConfig, SubagentConfigEntry } from '../../types';
2
- import type { AgentContext } from '../../agents/AgentContext';
1
+ import type { AgentInputs, ExecutableSubagentConfig, ExecutableSubagentConfigEntry, GraphEdge, GraphSubagentConfig, ResolvedSubagentConfig, ResolvedSubagentConfigEntry, SubagentConfig, SubagentConfigEntry } from '@/types';
2
+ import type { AgentContext } from '@/agents/AgentContext';
3
3
  type ChildGraphPlanBase = {
4
4
  subjectAgentId: string;
5
5
  checkpointNodeId: string;
@@ -1,7 +1,7 @@
1
1
  import type { RunnableConfig } from '@langchain/core/runnables';
2
- import type { AssistantTextPhase } from '../types/assistantPhase';
3
- import type { ClientOptions } from '../types/llm';
4
- import type { Providers } from '../common';
2
+ import type { AssistantTextPhase } from '@/types/assistantPhase';
3
+ import type { ClientOptions } from '@/types/llm';
4
+ import type { Providers } from '@/common';
5
5
  /** One tool call's contribution to the label payload (host-assembled). */
6
6
  export type ActivityLabelToolEntry = {
7
7
  toolName: string;
@@ -4,13 +4,13 @@ import type { START, StateGraph, StateGraphArgs } from '@langchain/langgraph';
4
4
  import type { RunnableConfig, Runnable } from '@langchain/core/runnables';
5
5
  import type { ChatGenerationChunk } from '@langchain/core/outputs';
6
6
  import type { GoogleAIToolType } from '@langchain/google-common';
7
- import type { SummarizationNodeInput, SummarizeCompleteEvent, SummarizationConfig, SummarizeStartEvent, SummarizeDeltaEvent } from '../types/summarize';
8
- import type { RunStep, RunStepDeltaEvent, RunStepClosedEvent, MessageDeltaEvent, ReasoningDeltaEvent } from '../types/stream';
9
- import type { ToolMap, ToolSessionMap, ToolEndEvent, GenericTool, LCTool, ToolExecuteBatchRequest } from '../types/tools';
10
- import type { TokenCounter, StreamLimits, StreamPreemption, TokenBudgetBreakdown } from '../types/run';
11
- import type { Providers, Callback, GraphNodeKeys } from '../common';
12
- import type { StandardGraph, MultiAgentGraph } from '../graphs';
13
- import type { ClientOptions } from '../types/llm';
7
+ import type { SummarizationNodeInput, SummarizeCompleteEvent, SummarizationConfig, SummarizeStartEvent, SummarizeDeltaEvent } from '@/types/summarize';
8
+ import type { RunStep, RunStepDeltaEvent, RunStepResumeState, RunStepClosedEvent, MessageDeltaEvent, ReasoningDeltaEvent } from '@/types/stream';
9
+ import type { ToolMap, ToolSessionMap, ToolEndEvent, GenericTool, LCTool, ToolExecuteBatchRequest } from '@/types/tools';
10
+ import type { TokenCounter, StreamLimits, StreamPreemption, TokenBudgetBreakdown } from '@/types/run';
11
+ import type { Providers, Callback, GraphNodeKeys } from '@/common';
12
+ import type { StandardGraph, MultiAgentGraph } from '@/graphs';
13
+ import type { ClientOptions } from '@/types/llm';
14
14
  /** Interface for bound model with stream and invoke methods */
15
15
  export interface ChatModel {
16
16
  stream?: (messages: BaseMessage[], config?: RunnableConfig) => Promise<AsyncIterable<AIMessageChunk>>;
@@ -28,6 +28,7 @@ export type SystemCallbacks = {
28
28
  };
29
29
  export type BaseGraphState = {
30
30
  messages: BaseMessage[];
31
+ runStepState?: RunStepResumeState;
31
32
  };
32
33
  export type AgentSubgraphState = BaseGraphState & {
33
34
  summarizationRequest?: SummarizationNodeInput;
@@ -628,6 +629,14 @@ export interface LangfuseConfig {
628
629
  }
629
630
  export interface AgentInputs {
630
631
  agentId: string;
632
+ /**
633
+ * Partition key for transient code-session ids and file refs. Agents with
634
+ * the same key share those refs; different execution profiles/scopes must
635
+ * use different keys. Defaults to the legacy shared `execute_code` slot.
636
+ * Non-default partitions also disable speculative eager execution of code
637
+ * tools because their factory may target a durable backend.
638
+ */
639
+ codeSessionKey?: string;
631
640
  /** Human-readable name for the agent (used in handoff context). Defaults to agentId if not provided. */
632
641
  name?: string;
633
642
  toolEnd?: boolean;
@@ -12,15 +12,15 @@ import type { AnthropicInput } from '@langchain/anthropic';
12
12
  import type { Runnable } from '@langchain/core/runnables';
13
13
  import type { OpenAI as OpenAIClient } from 'openai';
14
14
  import type { ChatXAIInput } from '@langchain/xai';
15
- import type { ChatOpenRouterCallOptions } from '../llm/openrouter';
16
- import type { PromptCacheTtl } from '../messages/cache';
17
- import { AzureChatOpenAI, ChatDeepSeek, ChatMoonshot, ChatOpenAI, ChatXAI } from '../llm/openai';
18
- import { CustomChatGoogleGenerativeAI } from '../llm/google';
19
- import { CustomChatBedrockConverse } from '../llm/bedrock';
20
- import { CustomAnthropic } from '../llm/anthropic';
21
- import { ChatOpenRouter } from '../llm/openrouter';
22
- import { ChatVertexAI } from '../llm/vertexai';
23
- import { Providers } from '../common';
15
+ import type { ChatOpenRouterCallOptions } from '@/llm/openrouter';
16
+ import type { PromptCacheTtl } from '@/messages/cache';
17
+ import { AzureChatOpenAI, ChatDeepSeek, ChatMoonshot, ChatOpenAI, ChatXAI } from '@/llm/openai';
18
+ import { CustomChatGoogleGenerativeAI } from '@/llm/google';
19
+ import { CustomChatBedrockConverse } from '@/llm/bedrock';
20
+ import { CustomAnthropic } from '@/llm/anthropic';
21
+ import { ChatOpenRouter } from '@/llm/openrouter';
22
+ import { ChatVertexAI } from '@/llm/vertexai';
23
+ import { Providers } from '@/common';
24
24
  export type AzureClientOptions = Partial<OpenAIChatInput> & Partial<AzureOpenAIInput> & {
25
25
  openAIApiKey?: string;
26
26
  openAIApiVersion?: string;
@@ -3,13 +3,13 @@ import type { RunnableConfig } from '@langchain/core/runnables';
3
3
  import type { BaseMessage } from '@langchain/core/messages';
4
4
  import type { StructuredTool } from '@langchain/core/tools';
5
5
  import type * as z from 'zod';
6
- import type { ToolSessionMap, ToolExecutionConfig, ToolOutputReferencesConfig, EagerEventToolExecutionConfig } from '../types/tools';
7
- import type { HumanInTheLoopConfig } from '../types/hitl';
8
- import type { HookRegistry } from '../hooks';
9
- import type * as s from '../types/stream';
10
- import type * as e from '../common/enum';
11
- import type * as g from '../types/graph';
12
- import type * as l from '../types/llm';
6
+ import type { ToolSessionMap, ToolExecutionConfig, ToolOutputReferencesConfig, EagerEventToolExecutionConfig } from '@/types/tools';
7
+ import type { HumanInTheLoopConfig } from '@/types/hitl';
8
+ import type { HookRegistry } from '@/hooks';
9
+ import type * as s from '@/types/stream';
10
+ import type * as e from '@/common/enum';
11
+ import type * as g from '@/types/graph';
12
+ import type * as l from '@/types/llm';
13
13
  export type ZodObjectAny = z.ZodObject<any, any, any, any>;
14
14
  export type BaseGraphConfig = {
15
15
  llmConfig: l.LLMConfig;
@@ -3,11 +3,11 @@ import type { ToolCall, ToolCallChunk } from '@langchain/core/messages/tool';
3
3
  import type { LLMResult, Generation } from '@langchain/core/outputs';
4
4
  import type { Command } from '@langchain/langgraph';
5
5
  import type Anthropic from '@anthropic-ai/sdk';
6
- import type { AnthropicContentBlock } from '../llm/anthropic/types';
7
- import type { AssistantTextPhase } from '../types/assistantPhase';
8
- import type { SummarizeCompleteEvent } from '../types/summarize';
9
- import type { ToolEndEvent } from '../types/tools';
10
- import { StepTypes, ContentTypes, GraphEvents } from '../common/enum';
6
+ import type { AnthropicContentBlock } from '@/llm/anthropic/types';
7
+ import type { AssistantTextPhase } from '@/types/assistantPhase';
8
+ import type { SummarizeCompleteEvent } from '@/types/summarize';
9
+ import type { ToolEndEvent } from '@/types/tools';
10
+ import { StepTypes, ContentTypes, GraphEvents } from '@/common/enum';
11
11
  export type HandleLLMEnd = (output: LLMResult, runId: string, parentRunId?: string, tags?: string[]) => void;
12
12
  export type MetadataAggregatorResult = {
13
13
  handleLLMEnd: HandleLLMEnd;
@@ -75,6 +75,24 @@ export type RunStep = {
75
75
  summary?: SummaryContentBlock;
76
76
  usage?: null | object;
77
77
  };
78
+ /** Minimal durable lifecycle state needed to continue open run steps. */
79
+ export interface RunStepResumeEntry {
80
+ step: RunStep;
81
+ pendingToolCallIds: string[];
82
+ latestCompletionAt?: number;
83
+ openMessageStep: boolean;
84
+ }
85
+ /** SDK-private state persisted in LangGraph checkpoints for process-safe resume. */
86
+ export interface RunStepResumeState {
87
+ version: 1;
88
+ revision: number;
89
+ nextIndex: number;
90
+ toolCallSteps: Array<{
91
+ toolCallId: string;
92
+ stepId: string;
93
+ }>;
94
+ steps: RunStepResumeEntry[];
95
+ }
78
96
  /**
79
97
  * Represents a run step delta i.e. any changed fields on a run step during
80
98
  * streaming.
@@ -1,5 +1,5 @@
1
- import type { SummaryContentBlock } from '../types/stream';
2
- import type { Providers } from '../common';
1
+ import type { SummaryContentBlock } from '@/types/stream';
2
+ import type { Providers } from '@/common';
3
3
  export type SummarizationTrigger = {
4
4
  type: 'token_ratio' | 'remaining_tokens' | 'messages_to_refine' | (string & {});
5
5
  value: number;
@@ -1,12 +1,12 @@
1
1
  import type { StructuredToolInterface } from '@langchain/core/tools';
2
- import type { RunnableToolLike } from '@langchain/core/runnables';
2
+ import type { RunnableConfig, RunnableToolLike } from '@langchain/core/runnables';
3
3
  import type { ToolCall } from '@langchain/core/messages/tool';
4
- import type { ToolOutputReferenceRegistry } from '../tools/toolOutputReferences';
5
- import type { RunBreakerScope } from '../llm/streamLimits';
6
- import type { MessageContentComplex, ToolErrorData } from './stream';
4
+ import type { ToolOutputReferenceRegistry } from '@/tools/toolOutputReferences';
5
+ import type { RunBreakerScope } from '@/llm/streamLimits';
6
+ import type { MessageContentComplex, RunStepResumeState, ToolErrorData } from './stream';
7
7
  import type { HumanInTheLoopConfig } from './hitl';
8
8
  import type { LangfuseConfig } from './graph';
9
- import type { HookRegistry } from '../hooks';
9
+ import type { HookRegistry } from '@/hooks';
10
10
  /** Replacement type for `import type { ToolCall } from '@langchain/core/messages/tool'` in order to have stringified args typed */
11
11
  export type CustomToolCall = {
12
12
  name: string;
@@ -118,6 +118,8 @@ export type ToolNodeOptions = {
118
118
  toolRegistry?: LCToolRegistry;
119
119
  /** Reference to Graph's sessions map for automatic session injection */
120
120
  sessions?: ToolSessionMap;
121
+ /** Partition within `sessions` used by this agent's code tools. */
122
+ codeSessionKey?: string;
121
123
  /** When true, dispatches ON_TOOL_EXECUTE events instead of invoking tools directly */
122
124
  eventDrivenMode?: boolean;
123
125
  /** Tool definitions for event-driven mode (used for context, not invocation) */
@@ -264,6 +266,10 @@ export type ToolNodeOptions = {
264
266
  * controller.
265
267
  */
266
268
  getRunScope?: () => RunBreakerScope;
269
+ /** SDK-owned checkpoint bridge for open run-step lifecycle state. */
270
+ restoreRunStepResumeState?: (state?: RunStepResumeState, config?: RunnableConfig) => void;
271
+ /** SDK-owned checkpoint snapshot for open run-step lifecycle state. */
272
+ createRunStepResumeState?: () => RunStepResumeState;
267
273
  };
268
274
  export type ToolNodeConstructorParams = ToolRefs & ToolNodeOptions;
269
275
  export type ToolEndEvent = {
@@ -361,6 +367,19 @@ export type CodeEnvFile = (CodeEnvFileBase & {
361
367
  kind: 'user';
362
368
  });
363
369
  export type CodeExecutionToolParams = undefined | {
370
+ /** Trusted Code API endpoint selected by the host for this agent. */
371
+ baseUrl?: string;
372
+ /**
373
+ * Expected Code API execution profile. Sent as a request assertion so
374
+ * endpoint/configuration drift fails closed instead of silently using
375
+ * the wrong sandbox backend.
376
+ */
377
+ executionProfile?: CodeApiExecutionProfile;
378
+ /**
379
+ * Trusted warm-runtime affinity hint selected by the host for this
380
+ * agent invocation. This overrides the legacy ToolNode-injected hint.
381
+ */
382
+ runtimeSessionHint?: string;
364
383
  /** Execution session — see `CodeSessionContext.session_id`. */
365
384
  session_id?: string;
366
385
  user_id?: string;
@@ -368,15 +387,14 @@ export type CodeExecutionToolParams = undefined | {
368
387
  /** Optional host-supplied Code API auth headers. */
369
388
  authHeaders?: CodeApiAuthHeaders;
370
389
  /**
371
- * Advertise best-effort stateful sessions in the tool description
372
- * (variables/files may persist between calls, may reset). Prompt text
373
- * only, and it must be set here because the description is bound to the
374
- * LLM at construction time. Pair it with the run-scoped
375
- * `toolExecution.sandbox.statefulSessions` gate, which drives the wire
376
- * hint — set both from one flag so the prompt and the backend agree.
390
+ * Advertise filesystem-tier stateful sessions in the tool description
391
+ * and allow a trusted runtime affinity hint onto the wire. Resolve this,
392
+ * `baseUrl`, `executionProfile`, and `runtimeSessionHint` together from
393
+ * the executing agent so the prompt and backend agree.
377
394
  */
378
395
  statefulSessions?: boolean;
379
396
  };
397
+ export type CodeApiExecutionProfile = 'default' | 'stateful';
380
398
  export type CodeApiAuthHeaderMap = Record<string, string>;
381
399
  export type CodeApiAuthHeaders = CodeApiAuthHeaderMap | (() => CodeApiAuthHeaderMap | Promise<CodeApiAuthHeaderMap>);
382
400
  export type FileRef = {
@@ -756,7 +774,7 @@ export type LocalExecConfig = {
756
774
  * `spawn` — see the type-level note above on why both should be
757
775
  * overridden together for non-host engines.
758
776
  */
759
- fs?: import('../tools/local/workspaceFS').WorkspaceFS;
777
+ fs?: import('@/tools/local/workspaceFS').WorkspaceFS;
760
778
  /**
761
779
  * Set by custom execution backends that already provide their own
762
780
  * sandbox boundary. Suppresses the local host-sandbox warning while
@@ -1032,19 +1050,17 @@ export type CloudflareSandboxExecutionConfig = {
1032
1050
  };
1033
1051
  export type SandboxExecutionConfig = {
1034
1052
  /**
1035
- * Opt into best-effort stateful runtime sessions on the remote Code API
1036
- * (its warm per-session MicroVM backend). This gate is run-scoped: it only
1037
- * controls the wire behavior (ToolNode injecting the session hint on
1038
- * execute_code/bash calls). The transport is otherwise unchanged.
1053
+ * Legacy run-scoped opt-in for warm runtime hint injection. New hosts that
1054
+ * need mixed execution profiles should resolve `statefulSessions`,
1055
+ * `baseUrl`, `executionProfile`, and `runtimeSessionHint` on each executing
1056
+ * agent's tool factories instead. Direct executors ignore this injected hint
1057
+ * unless their own factory has `statefulSessions: true`.
1039
1058
  *
1040
1059
  * It does NOT change the model-facing tool description. Tool descriptions are
1041
1060
  * bound to the LLM at construction time (`createCodeExecutionTool` /
1042
1061
  * `createBashExecutionTool`), before this run config is applied inside the
1043
1062
  * graph, so they can only be adjusted via the tools' own `statefulSessions`
1044
- * factory param. Set BOTH from one flag (as LibreChat does): with this on but
1045
- * the factory param off, the backend runs statefully while the model is still
1046
- * told the environment is stateless (non-corrupting — the model just won't
1047
- * exploit persistence).
1063
+ * factory param.
1048
1064
  */
1049
1065
  statefulSessions?: boolean;
1050
1066
  /**
@@ -1078,7 +1094,7 @@ export type ProgrammaticCache = {
1078
1094
  hookContext?: ProgrammaticHookContext;
1079
1095
  };
1080
1096
  export type ProgrammaticHookContext = {
1081
- registry: import('../hooks').HookRegistry | undefined;
1097
+ registry: import('@/hooks').HookRegistry | undefined;
1082
1098
  runId: string;
1083
1099
  threadId?: string;
1084
1100
  agentId?: string;
@@ -1193,6 +1209,10 @@ export type BashProgrammaticToolCallingParams = ProgrammaticToolCallingParams;
1193
1209
  export type ProgrammaticToolCallingParams = {
1194
1210
  /** Code API base URL (or use CODE_BASEURL env var) */
1195
1211
  baseUrl?: string;
1212
+ /** Expected Code API execution profile (host-controlled). */
1213
+ executionProfile?: CodeApiExecutionProfile;
1214
+ /** Trusted warm-runtime affinity hint for this agent invocation. */
1215
+ runtimeSessionHint?: string;
1196
1216
  /** Safety limit for round-trips (default: 20) */
1197
1217
  maxRoundTrips?: number;
1198
1218
  /** Maximum per-sandbox-run timeout for PTC's legacy `timeout` field. */
@@ -1,4 +1,4 @@
1
- import type { Providers } from '../common';
1
+ import type { Providers } from '@/common';
2
2
  /**
3
3
  * Why the request was rejected. Both kinds are fixed by shrinking the
4
4
  * prompt, which is what makes them recoverable; they are distinguished
@@ -1,5 +1,5 @@
1
1
  import type { RunnableConfig } from '@langchain/core/runnables';
2
- import type { AgentLogEvent } from '../types/graph';
2
+ import type { AgentLogEvent } from '@/types/graph';
3
3
  /**
4
4
  * Safely dispatches a custom event and properly awaits it to avoid
5
5
  * race conditions where events are dispatched after run cleanup.
@@ -14,9 +14,9 @@
14
14
  * });
15
15
  * ```
16
16
  */
17
- import type * as t from '../types';
18
- import { createContentAggregator } from '../stream';
19
- import { GraphEvents } from '../common';
17
+ import type * as t from '@/types';
18
+ import { createContentAggregator } from '@/stream';
19
+ import { GraphEvents } from '@/common';
20
20
  interface HandlerCallbacks {
21
21
  onRunStep?: (event: GraphEvents.ON_RUN_STEP, data: t.StreamEventData) => void;
22
22
  onRunStepCompleted?: (event: GraphEvents.ON_RUN_STEP_COMPLETED, data: t.StreamEventData) => void;
@@ -1,4 +1,4 @@
1
- import { Providers } from '../common';
1
+ import { Providers } from '@/common';
2
2
  export declare function isOpenAILike(provider?: string | Providers): boolean;
3
3
  export declare function isGoogleLike(provider?: string | Providers): boolean;
4
4
  /** Returns true for native Anthropic or Bedrock running a Claude model. */
@@ -1,3 +1,3 @@
1
- import type * as t from '../types';
1
+ import type * as t from '@/types';
2
2
  export declare const llmConfigs: Record<string, t.LLMConfig | undefined>;
3
3
  export declare function getLLMConfig(provider: string): t.LLMConfig;
@@ -1,4 +1,4 @@
1
1
  import type { Runnable } from '@langchain/core/runnables';
2
- import type * as t from '../types';
2
+ import type * as t from '@/types';
3
3
  export declare const createTitleRunnable: (model: t.ChatModelInstance, _titlePrompt?: string) => Promise<Runnable>;
4
4
  export declare const createCompletionTitleRunnable: (model: t.ChatModelInstance, titlePrompt?: string) => Promise<Runnable>;
@@ -0,0 +1,18 @@
1
+ import type * as t from '@/types';
2
+ type CodeSessionAgent = Pick<t.AgentInputs, 'codeSessionKey' | 'initialSessions'>;
3
+ /**
4
+ * Seeds a top-level graph while preserving the legacy run-wide session map.
5
+ * A legacy `execute_code` seed is copied into every custom agent partition
6
+ * unless the host already supplied an explicit seed for that partition.
7
+ */
8
+ export declare function seedRunInitialSessions(args: {
9
+ sessions: t.ToolSessionMap;
10
+ initialSessions: t.ToolSessionMap;
11
+ agents: Iterable<Pick<t.AgentInputs, 'codeSessionKey'>>;
12
+ }): void;
13
+ /**
14
+ * Seeds an isolated child graph from each selected agent. Legacy code-session
15
+ * entries are remapped to the owning agent's partition before they are merged.
16
+ */
17
+ export declare function seedAgentInitialSessions(sessions: t.ToolSessionMap, agents: Iterable<CodeSessionAgent>): void;
18
+ export {};