@librechat/agents 3.8.4 → 3.8.6

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 (81) hide show
  1. package/dist/cjs/agents/AgentContext.cjs +1 -1
  2. package/dist/cjs/common/constants.cjs +2 -0
  3. package/dist/cjs/common/constants.cjs.map +1 -1
  4. package/dist/cjs/graphs/Graph.cjs +18 -9
  5. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  6. package/dist/cjs/hitl/approvalReview.cjs +1 -1
  7. package/dist/cjs/hooks/types.cjs.map +1 -1
  8. package/dist/cjs/main.cjs +7 -6
  9. package/dist/cjs/messages/index.cjs +1 -1
  10. package/dist/cjs/messages/prune.cjs +1 -1
  11. package/dist/cjs/run.cjs +7 -3
  12. package/dist/cjs/run.cjs.map +1 -1
  13. package/dist/cjs/stream.cjs +13 -3
  14. package/dist/cjs/stream.cjs.map +1 -1
  15. package/dist/cjs/summarization/node.cjs +3 -1
  16. package/dist/cjs/summarization/node.cjs.map +1 -1
  17. package/dist/cjs/tools/ToolNode.cjs +134 -32
  18. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  19. package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs +1 -0
  20. package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs.map +1 -1
  21. package/dist/cjs/tools/subagent/SubagentExecutionRegistry.cjs +0 -1
  22. package/dist/cjs/tools/subagent/SubagentExecutionRegistry.cjs.map +1 -1
  23. package/dist/cjs/tools/subagent/SubagentExecutor.cjs +123 -29
  24. package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
  25. package/dist/cjs/tools/toolBatchReplay.cjs +65 -13
  26. package/dist/cjs/tools/toolBatchReplay.cjs.map +1 -1
  27. package/dist/cjs/utils/index.cjs +1 -1
  28. package/dist/esm/agents/AgentContext.mjs +1 -1
  29. package/dist/esm/common/constants.mjs +2 -1
  30. package/dist/esm/common/constants.mjs.map +1 -1
  31. package/dist/esm/graphs/Graph.mjs +17 -8
  32. package/dist/esm/graphs/Graph.mjs.map +1 -1
  33. package/dist/esm/hitl/approvalReview.mjs +1 -1
  34. package/dist/esm/hooks/types.mjs.map +1 -1
  35. package/dist/esm/main.mjs +6 -6
  36. package/dist/esm/messages/index.mjs +1 -1
  37. package/dist/esm/messages/prune.mjs +1 -1
  38. package/dist/esm/run.mjs +7 -3
  39. package/dist/esm/run.mjs.map +1 -1
  40. package/dist/esm/stream.mjs +13 -3
  41. package/dist/esm/stream.mjs.map +1 -1
  42. package/dist/esm/summarization/node.mjs +3 -1
  43. package/dist/esm/summarization/node.mjs.map +1 -1
  44. package/dist/esm/tools/ToolNode.mjs +135 -33
  45. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  46. package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs +1 -0
  47. package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs.map +1 -1
  48. package/dist/esm/tools/subagent/SubagentExecutionRegistry.mjs +0 -1
  49. package/dist/esm/tools/subagent/SubagentExecutionRegistry.mjs.map +1 -1
  50. package/dist/esm/tools/subagent/SubagentExecutor.mjs +123 -29
  51. package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
  52. package/dist/esm/tools/toolBatchReplay.mjs +64 -13
  53. package/dist/esm/tools/toolBatchReplay.mjs.map +1 -1
  54. package/dist/esm/utils/index.mjs +1 -1
  55. package/dist/types/common/constants.d.ts +2 -0
  56. package/dist/types/graphs/Graph.d.ts +3 -2
  57. package/dist/types/hooks/types.d.ts +3 -0
  58. package/dist/types/run.d.ts +1 -0
  59. package/dist/types/summarization/node.d.ts +1 -0
  60. package/dist/types/tools/ToolNode.d.ts +4 -2
  61. package/dist/types/tools/subagent/SubagentExecutor.d.ts +7 -4
  62. package/dist/types/tools/toolBatchReplay.d.ts +6 -3
  63. package/dist/types/types/graph.d.ts +28 -0
  64. package/dist/types/types/run.d.ts +2 -0
  65. package/dist/types/types/tools.d.ts +11 -1
  66. package/package.json +1 -1
  67. package/src/common/constants.ts +3 -0
  68. package/src/graphs/Graph.ts +32 -18
  69. package/src/hooks/types.ts +3 -0
  70. package/src/run.ts +30 -15
  71. package/src/stream.ts +27 -5
  72. package/src/summarization/node.ts +3 -0
  73. package/src/tools/ToolNode.ts +528 -149
  74. package/src/tools/local/LocalProgrammaticToolCalling.ts +1 -0
  75. package/src/tools/subagent/SubagentExecutionRegistry.ts +0 -1
  76. package/src/tools/subagent/SubagentExecutor.ts +216 -48
  77. package/src/tools/toolBatchReplay.ts +121 -20
  78. package/src/types/graph.ts +37 -0
  79. package/src/types/run.ts +2 -0
  80. package/src/types/tools.ts +11 -1
  81. package/src/utils/llmConfig.ts +0 -1
@@ -1,15 +1,15 @@
1
1
  const require_enum = require("../common/enum.cjs");
2
2
  require("../common/index.cjs");
3
- const require_truncation = require("../utils/truncation.cjs");
4
- const require_runStepResume = require("./runStepResume.cjs");
5
- const require_SubagentReplay = require("./subagent/SubagentReplay.cjs");
6
3
  const require_misc = require("../utils/misc.cjs");
7
4
  const require_langfuseRuntimeScope = require("../langfuseRuntimeScope.cjs");
5
+ const require_truncation = require("../utils/truncation.cjs");
8
6
  const require_toolContent = require("../utils/toolContent.cjs");
9
7
  const require_provenance = require("../messages/provenance.cjs");
8
+ const require_runStepResume = require("./runStepResume.cjs");
9
+ const require_SubagentReplay = require("./subagent/SubagentReplay.cjs");
10
+ const require_types = require("../hooks/types.cjs");
10
11
  const require_eagerEventExecution = require("./eagerEventExecution.cjs");
11
12
  const require_approvalReview = require("../hitl/approvalReview.cjs");
12
- const require_types = require("../hooks/types.cjs");
13
13
  const require_toolBatchReplay = require("./toolBatchReplay.cjs");
14
14
  const require_executeHooks = require("../hooks/executeHooks.cjs");
15
15
  require("../hooks/index.cjs");
@@ -237,6 +237,41 @@ function updateCodeSession(sessions, sessionKey, execSessionId, files) {
237
237
  lastUpdated: Date.now()
238
238
  });
239
239
  }
240
+ function retainCodeSessionInputs(sessions, sessionKey, context) {
241
+ if (context?.session_id == null || context.session_id === "" || context.files == null) return;
242
+ const existing = sessions.get(sessionKey);
243
+ const files = [...existing?.files ?? []];
244
+ const indexByIdentity = /* @__PURE__ */ new Map();
245
+ const indexByName = /* @__PURE__ */ new Map();
246
+ for (let i = 0; i < files.length; i++) {
247
+ indexByIdentity.set(fileIdentityKey(files[i]), i);
248
+ indexByName.set(files[i].name, i);
249
+ }
250
+ let changed = existing?.session_id !== context.session_id;
251
+ for (const file of context.files) {
252
+ if (!file.id || !file.name || !file.storage_session_id) continue;
253
+ const identity = fileIdentityKey(file);
254
+ if (indexByIdentity.has(identity)) continue;
255
+ const replacementIndex = indexByName.get(file.name);
256
+ if (replacementIndex !== void 0) {
257
+ indexByIdentity.delete(fileIdentityKey(files[replacementIndex]));
258
+ files[replacementIndex] = { ...file };
259
+ indexByIdentity.set(identity, replacementIndex);
260
+ changed = true;
261
+ continue;
262
+ }
263
+ indexByIdentity.set(identity, files.length);
264
+ indexByName.set(file.name, files.length);
265
+ files.push({ ...file });
266
+ changed = true;
267
+ }
268
+ if (!changed) return;
269
+ sessions.set(sessionKey, {
270
+ session_id: context.session_id,
271
+ files,
272
+ lastUpdated: Date.now()
273
+ });
274
+ }
240
275
  var ToolNode = class extends require_run.RunnableCallable {
241
276
  toolMap;
242
277
  loadRuntimeTools;
@@ -265,6 +300,7 @@ var ToolNode = class extends require_run.RunnableCallable {
265
300
  eagerEventToolSuppressions;
266
301
  agentId;
267
302
  executingAgentId;
303
+ executionContext;
268
304
  executingAgentName;
269
305
  rootAgentId;
270
306
  rootAgentName;
@@ -280,7 +316,7 @@ var ToolNode = class extends require_run.RunnableCallable {
280
316
  getRunScope;
281
317
  preparedSubagents;
282
318
  anonBatchCounter = 0;
283
- constructor({ tools, toolMap, name, tags, trace, runLangfuse, agentLangfuse, errorHandler, toolCallStepIds, handleToolErrors, loadRuntimeTools, toolRegistry, toolDefinitions, getDiscoveredToolNames, sessions, codeSessionKey, eventDrivenMode, eagerEventToolExecution, eagerEventToolExecutions, eagerEventToolUsageCount, eagerEventToolSuppressions, agentId, executingAgentId, executingAgentName, rootAgentId, rootAgentName, directToolNames, interruptingToolNames, codeSessionToolNames, maxContextTokens, maxToolResultChars, hookRegistry, humanInTheLoop, toolOutputReferences, toolOutputRegistry, toolExecution, fileCheckpointer, getBreakerSignal, getRunScope, preparedSubagents, restoreRunStepResumeState, createRunStepResumeState }) {
319
+ constructor({ tools, toolMap, name, tags, trace, runLangfuse, agentLangfuse, errorHandler, toolCallStepIds, handleToolErrors, loadRuntimeTools, toolRegistry, toolDefinitions, getDiscoveredToolNames, sessions, codeSessionKey, eventDrivenMode, eagerEventToolExecution, eagerEventToolExecutions, eagerEventToolUsageCount, eagerEventToolSuppressions, agentId, executingAgentId, executionContext, executingAgentName, rootAgentId, rootAgentName, directToolNames, interruptingToolNames, codeSessionToolNames, maxContextTokens, maxToolResultChars, hookRegistry, humanInTheLoop, toolOutputReferences, toolOutputRegistry, toolExecution, fileCheckpointer, getBreakerSignal, getRunScope, preparedSubagents, restoreRunStepResumeState, createRunStepResumeState }) {
284
320
  super({
285
321
  name: name ?? TOOL_NODE_RUN_NAME,
286
322
  tags,
@@ -298,14 +334,15 @@ var ToolNode = class extends require_run.RunnableCallable {
298
334
  const trustedParentCallIds = new Set(calls.filter((call) => call.name === "subagent" && this.toolMap.get(call.name)?.[require_SubagentReplay.SUBAGENT_REPLAY_CONTROLLER] != null).map((call) => call.id ?? ""));
299
335
  isChildReplay = reviewEvidence?.owner != null ? require_toolBatchReplay.isChildToolReplayOwner(config, reviewEvidence.owner, trustedParentCallIds) : replayState.records.some((record) => require_toolBatchReplay.isChildToolReplayOwner(config, record.owner, trustedParentCallIds));
300
336
  }
301
- if ((reviewEvidence?.owner != null || replayState != null) && !require_toolBatchReplay.isToolReplayResume(config, reviewEvidence?.interruptId ?? replayState?.interruptId, isChildReplay)) {
337
+ const hasApprovalAuthorization = reviewEvidence?.owner != null || replayState?.approvalOwner != null;
338
+ const replayResumeStatus = hasApprovalAuthorization || replayState != null ? require_toolBatchReplay.getToolReplayResumeStatus(config, reviewEvidence?.interruptId ?? replayState?.interruptId, isChildReplay) : void 0;
339
+ if (replayResumeStatus === "unverifiable" && hasApprovalAuthorization) throw new Error("Cannot verify the active tool approval resume — failing closed");
340
+ if (replayResumeStatus === "stale") {
341
+ const configurable = { ...config.configurable };
342
+ require_toolBatchReplay.clearStaleToolApprovalConfig(configurable, replayOwner, activeReplayKey);
302
343
  config = {
303
344
  ...config,
304
- configurable: {
305
- ...config.configurable,
306
- [require_approvalReview.TOOL_APPROVAL_REVIEW_CONFIG_KEY]: void 0,
307
- [require_toolBatchReplay.TOOL_BATCH_REPLAY_KEY]: void 0
308
- }
345
+ configurable
309
346
  };
310
347
  reviewEvidence = void 0;
311
348
  }
@@ -373,6 +410,7 @@ var ToolNode = class extends require_run.RunnableCallable {
373
410
  this.eagerEventToolSuppressions = eagerEventToolSuppressions;
374
411
  this.agentId = agentId;
375
412
  this.executingAgentId = executingAgentId ?? agentId;
413
+ this.executionContext = executionContext;
376
414
  this.executingAgentName = executingAgentName;
377
415
  this.rootAgentId = rootAgentId;
378
416
  this.rootAgentName = rootAgentName;
@@ -400,8 +438,13 @@ var ToolNode = class extends require_run.RunnableCallable {
400
438
  withToolScope(options, invoke) {
401
439
  const scopedOptions = this.executingAgentId == null ? options : {
402
440
  ...options,
441
+ configurable: {
442
+ ...options?.configurable,
443
+ executionContext: this.executionContext
444
+ },
403
445
  metadata: {
404
446
  ...options?.metadata,
447
+ executionContext: this.executionContext,
405
448
  agentId: this.executingAgentId,
406
449
  activeAgentId: this.executingAgentId,
407
450
  ...this.executingAgentName == null ? {} : { activeAgentName: this.executingAgentName },
@@ -660,6 +703,7 @@ var ToolNode = class extends require_run.RunnableCallable {
660
703
  runId: config.configurable?.run_id ?? "",
661
704
  threadId: config.configurable?.thread_id,
662
705
  agentId: this.agentId,
706
+ executionContext: this.executionContext,
663
707
  executingAgentId: this.executingAgentId
664
708
  }
665
709
  };
@@ -855,6 +899,7 @@ var ToolNode = class extends require_run.RunnableCallable {
855
899
  runId,
856
900
  threadId,
857
901
  agentId: this.agentId,
902
+ executionContext: this.executionContext,
858
903
  executingAgentId: this.executingAgentId,
859
904
  toolName: call.name,
860
905
  toolInput: resolvedArgs,
@@ -1033,6 +1078,7 @@ var ToolNode = class extends require_run.RunnableCallable {
1033
1078
  runId,
1034
1079
  threadId,
1035
1080
  agentId: this.agentId,
1081
+ executionContext: this.executionContext,
1036
1082
  executingAgentId: this.executingAgentId,
1037
1083
  toolName: call.name,
1038
1084
  toolInput: effectiveCall.args,
@@ -1058,6 +1104,7 @@ var ToolNode = class extends require_run.RunnableCallable {
1058
1104
  runId,
1059
1105
  threadId,
1060
1106
  agentId: this.agentId,
1107
+ executionContext: this.executionContext,
1061
1108
  executingAgentId: this.executingAgentId,
1062
1109
  toolName: call.name,
1063
1110
  toolInput: effectiveCall.args,
@@ -1105,6 +1152,7 @@ var ToolNode = class extends require_run.RunnableCallable {
1105
1152
  runId,
1106
1153
  threadId,
1107
1154
  agentId: this.agentId,
1155
+ executionContext: this.executionContext,
1108
1156
  executingAgentId: this.executingAgentId,
1109
1157
  toolName: call.name,
1110
1158
  toolInput: resolvedArgs,
@@ -1148,19 +1196,45 @@ var ToolNode = class extends require_run.RunnableCallable {
1148
1196
  resolveRuntimeSessionHint(config) {
1149
1197
  return require_eagerEventExecution.resolveRuntimeSessionHint(this.toolExecution, config.configurable?.thread_id);
1150
1198
  }
1151
- storeCodeSessionFromResults(results, requestMap) {
1199
+ storeCodeSessionFromResults(results, requestMap, baselineByRequestId) {
1152
1200
  if (!this.sessions) return;
1201
+ this.retainCodeSessionInputsFromRequests(requestMap.values(), baselineByRequestId);
1153
1202
  for (let i = 0; i < results.length; i++) {
1154
1203
  const result = results[i];
1155
- if (result.status !== "success" || result.artifact == null) continue;
1156
1204
  const request = requestMap.get(result.toolCallId);
1157
1205
  if (request?.name == null || request.name === "" || !this.participatesInCodeSession(request.name) && request.name !== "skill") continue;
1206
+ if (result.status !== "success" || result.artifact == null) continue;
1158
1207
  const artifact = result.artifact;
1159
1208
  const execSessionId = artifact?.session_id;
1160
1209
  if (execSessionId == null || execSessionId === "") continue;
1161
1210
  updateCodeSession(this.sessions, this.codeSessionKey, execSessionId, artifact?.files);
1162
1211
  }
1163
1212
  }
1213
+ retainCodeSessionInputsFromRequests(requests, baselineByRequestId) {
1214
+ if (!this.sessions) return;
1215
+ const refreshedByName = /* @__PURE__ */ new Map();
1216
+ let refreshedSessionId;
1217
+ let fileSessionId;
1218
+ for (const request of requests) {
1219
+ if (request.name === "" || !this.participatesInCodeSession(request.name) && request.name !== "skill" && request.name !== "read_file" && request.retainCodeSessionInputs !== true) continue;
1220
+ const context = request.codeSessionContext;
1221
+ if (context?.session_id == null || context.session_id === "") continue;
1222
+ if (context.session_id !== request.codeSessionBaselineId) refreshedSessionId = context.session_id;
1223
+ const baselineIdentityByName = baselineByRequestId.get(request.id);
1224
+ for (const file of context.files ?? []) {
1225
+ if (!file.id || !file.name || !file.storage_session_id) continue;
1226
+ if (baselineIdentityByName?.get(file.name) === fileIdentityKey(file)) continue;
1227
+ fileSessionId = context.session_id;
1228
+ refreshedByName.set(file.name, file);
1229
+ }
1230
+ }
1231
+ const sessionId = refreshedSessionId ?? fileSessionId;
1232
+ if (sessionId == null) return;
1233
+ retainCodeSessionInputs(this.sessions, this.codeSessionKey, {
1234
+ session_id: sessionId,
1235
+ files: [...refreshedByName.values()]
1236
+ });
1237
+ }
1164
1238
  async handleRunToolCompletions(calls, outputs, config, resolvedArgsByCallId, errorOwnership) {
1165
1239
  const ownership = errorOwnership ?? this.looseErrorOwnership;
1166
1240
  for (let i = 0; i < calls.length; i++) {
@@ -1273,6 +1347,7 @@ var ToolNode = class extends require_run.RunnableCallable {
1273
1347
  runId,
1274
1348
  threadId,
1275
1349
  agentId: this.agentId,
1350
+ executionContext: this.executionContext,
1276
1351
  executingAgentId: this.executingAgentId,
1277
1352
  toolName: entry.call.name,
1278
1353
  toolInput: entry.args,
@@ -1323,6 +1398,7 @@ var ToolNode = class extends require_run.RunnableCallable {
1323
1398
  runId,
1324
1399
  threadId,
1325
1400
  agentId: this.agentId,
1401
+ executionContext: this.executionContext,
1326
1402
  executingAgentId: this.executingAgentId,
1327
1403
  toolName: item.toolName,
1328
1404
  toolInput: item.args,
@@ -1488,15 +1564,20 @@ var ToolNode = class extends require_run.RunnableCallable {
1488
1564
  for (const entry of approvedEntries) if (entry.batchIndex != null && entry.call.id != null) batchIndexByCallId.set(entry.call.id, entry.batchIndex);
1489
1565
  for (const result of plan.rejectedResults) this.eagerEventToolExecutions?.delete(result.toolCallId);
1490
1566
  const requestMap = new Map(plan.allRequests.map((r) => [r.id, r]));
1567
+ for (const request of plan.allRequests) request.codeSessionBaselineId = request.codeSessionContext?.session_id;
1568
+ const codeSessionBaselineByRequestId = new Map(plan.allRequests.map((request) => [request.id, new Map((request.codeSessionContext?.files ?? []).map((file) => [file.name, fileIdentityKey(file)]))]));
1491
1569
  const eagerExecutions = [];
1492
1570
  const dispatchRequests = [];
1493
1571
  for (const request of requests) {
1494
1572
  const eagerExecution = this.takeMatchingEagerEventExecution(request);
1495
- if (eagerExecution != null) eagerExecutions.push({
1496
- request,
1497
- execution: eagerExecution
1498
- });
1499
- else dispatchRequests.push(request);
1573
+ if (eagerExecution != null) {
1574
+ eagerExecutions.push({
1575
+ request,
1576
+ execution: eagerExecution
1577
+ });
1578
+ if (eagerExecution.codeSessionBaselineByName != null) codeSessionBaselineByRequestId.set(request.id, eagerExecution.codeSessionBaselineByName);
1579
+ request.codeSessionBaselineId = eagerExecution.request.codeSessionBaselineId;
1580
+ } else dispatchRequests.push(request);
1500
1581
  }
1501
1582
  const canEmitEarlyCompletions = this.hookRegistry?.hasResultAlteringHooks(runId) !== true && this.humanInTheLoop?.enabled !== true;
1502
1583
  const hasPostHook = this.hookRegistry?.hasHookFor("PostToolUse", runId) === true;
@@ -1524,6 +1605,7 @@ var ToolNode = class extends require_run.RunnableCallable {
1524
1605
  if (dispatchSettled && resultSettled) resolve(settledResults ?? []);
1525
1606
  };
1526
1607
  const batchRequest = {
1608
+ executionContext: this.executionContext,
1527
1609
  toolCalls: dispatchRequests,
1528
1610
  userId: config.configurable?.user_id,
1529
1611
  agentId: this.executingAgentId,
@@ -1545,13 +1627,27 @@ var ToolNode = class extends require_run.RunnableCallable {
1545
1627
  }).catch(reject);
1546
1628
  });
1547
1629
  const eagerResultsPromise = Promise.all(eagerExecutions.map(async ({ request, execution }) => {
1548
- return {
1549
- results: await this.resolveEagerEventExecution(request, execution),
1550
- completionDispatched: execution.completionDispatched === true && execution.request.turn === request.turn,
1551
- toolCallId: request.id
1552
- };
1630
+ try {
1631
+ return {
1632
+ results: await this.resolveEagerEventExecution(request, execution),
1633
+ completionDispatched: execution.completionDispatched === true && execution.request.turn === request.turn,
1634
+ toolCallId: request.id
1635
+ };
1636
+ } finally {
1637
+ if (execution.request.codeSessionContext != null) request.codeSessionContext = execution.request.codeSessionContext;
1638
+ }
1553
1639
  }));
1554
- const [eagerResults, dispatchedResults] = await Promise.all([eagerResultsPromise, dispatchPromise]);
1640
+ const [eagerOutcome, dispatchedOutcome] = await Promise.allSettled([eagerResultsPromise, dispatchPromise]);
1641
+ if (eagerOutcome.status === "rejected") {
1642
+ this.retainCodeSessionInputsFromRequests(requestMap.values(), codeSessionBaselineByRequestId);
1643
+ throw eagerOutcome.reason;
1644
+ }
1645
+ if (dispatchedOutcome.status === "rejected") {
1646
+ this.retainCodeSessionInputsFromRequests(requestMap.values(), codeSessionBaselineByRequestId);
1647
+ throw dispatchedOutcome.reason;
1648
+ }
1649
+ const eagerResults = eagerOutcome.value;
1650
+ const dispatchedResults = dispatchedOutcome.value;
1555
1651
  await Promise.allSettled(earlyCompletionDispatches);
1556
1652
  const eagerCompletionDispatchedIds = new Set(eagerResults.filter((result) => result.completionDispatched).map((result) => result.toolCallId));
1557
1653
  const flattenedEagerResults = eagerResults.flatMap((result) => result.results);
@@ -1560,7 +1656,7 @@ var ToolNode = class extends require_run.RunnableCallable {
1560
1656
  ...flattenedEagerResults,
1561
1657
  ...dispatchedResults
1562
1658
  ];
1563
- this.storeCodeSessionFromResults(results, requestMap);
1659
+ this.storeCodeSessionFromResults(results, requestMap, codeSessionBaselineByRequestId);
1564
1660
  for (const result of results) {
1565
1661
  if (result.injectedMessages && result.injectedMessages.length > 0) try {
1566
1662
  injected.push(...require_injected.convertInjectedMessages(result.injectedMessages));
@@ -1591,6 +1687,7 @@ var ToolNode = class extends require_run.RunnableCallable {
1591
1687
  runId,
1592
1688
  threadId,
1593
1689
  agentId: this.agentId,
1690
+ executionContext: this.executionContext,
1594
1691
  executingAgentId: this.executingAgentId,
1595
1692
  toolName,
1596
1693
  toolInput: request?.args ?? {},
@@ -1618,6 +1715,7 @@ var ToolNode = class extends require_run.RunnableCallable {
1618
1715
  runId,
1619
1716
  threadId,
1620
1717
  agentId: this.agentId,
1718
+ executionContext: this.executionContext,
1621
1719
  executingAgentId: this.executingAgentId,
1622
1720
  toolName,
1623
1721
  toolInput: request?.args ?? {},
@@ -1687,18 +1785,21 @@ var ToolNode = class extends require_run.RunnableCallable {
1687
1785
  if (execution.toolName !== request.name || !require_eagerEventExecution.recordArgsEqual(execution.args, request.args)) {
1688
1786
  this.eagerEventToolSuppressions?.add(request.name);
1689
1787
  this.eagerEventToolSuppressions?.add(execution.toolName);
1788
+ if (this.participatesInCodeSession(execution.toolName) || execution.toolName === "skill" || execution.toolName === "read_file") request.retainCodeSessionInputs = true;
1690
1789
  console.warn(`[ToolNode] eager prestart args diverged from the final request for tool "${request.name}" (toolCallId=${request.id}); suppressing eager prestart for this tool for the rest of the run`);
1790
+ const createMismatchOutcome = () => ({ results: [{
1791
+ toolCallId: request.id,
1792
+ status: "error",
1793
+ content: "",
1794
+ errorMessage: "Tool call changed after eager execution started; refusing to re-run the tool to avoid duplicate side effects."
1795
+ }] });
1691
1796
  return {
1692
1797
  toolCallId: request.id,
1693
1798
  toolName: request.name,
1694
1799
  args: request.args,
1695
- request,
1696
- promise: Promise.resolve({ results: [{
1697
- toolCallId: request.id,
1698
- status: "error",
1699
- content: "",
1700
- errorMessage: "Tool call changed after eager execution started; refusing to re-run the tool to avoid duplicate side effects."
1701
- }] })
1800
+ request: execution.request,
1801
+ codeSessionBaselineByName: execution.codeSessionBaselineByName,
1802
+ promise: execution.promise.then(createMismatchOutcome, createMismatchOutcome)
1702
1803
  };
1703
1804
  }
1704
1805
  return execution;
@@ -1733,6 +1834,7 @@ var ToolNode = class extends require_run.RunnableCallable {
1733
1834
  runId,
1734
1835
  threadId,
1735
1836
  agentId: this.agentId,
1837
+ executionContext: this.executionContext,
1736
1838
  executingAgentId: this.executingAgentId,
1737
1839
  entries: orderedBatchEntries
1738
1840
  },