@librechat/agents 4.2.5 → 4.2.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 (59) hide show
  1. package/dist/cjs/harness/identity.cjs +26 -0
  2. package/dist/cjs/harness/identity.cjs.map +1 -0
  3. package/dist/cjs/harness/index.cjs +3 -15
  4. package/dist/cjs/harness/index.cjs.map +1 -1
  5. package/dist/cjs/harness/providerText.cjs +79 -0
  6. package/dist/cjs/harness/providerText.cjs.map +1 -0
  7. package/dist/cjs/llm/contextPressureMeter.cjs +1 -1
  8. package/dist/cjs/llm/contextPressureMeter.cjs.map +1 -1
  9. package/dist/cjs/llm/openai/index.cjs +21 -12
  10. package/dist/cjs/llm/openai/index.cjs.map +1 -1
  11. package/dist/cjs/llm/openai/streamMetadata.cjs +4 -1
  12. package/dist/cjs/llm/openai/streamMetadata.cjs.map +1 -1
  13. package/dist/cjs/main.cjs +5 -0
  14. package/dist/cjs/stream.cjs +4 -1
  15. package/dist/cjs/stream.cjs.map +1 -1
  16. package/dist/cjs/tools/BashExecutor.cjs +2 -1
  17. package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
  18. package/dist/cjs/tools/ToolNode.cjs +141 -94
  19. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  20. package/dist/cjs/tools/toolOutputReferences.cjs +39 -17
  21. package/dist/cjs/tools/toolOutputReferences.cjs.map +1 -1
  22. package/dist/esm/harness/identity.mjs +24 -0
  23. package/dist/esm/harness/identity.mjs.map +1 -0
  24. package/dist/esm/harness/index.mjs +3 -15
  25. package/dist/esm/harness/index.mjs.map +1 -1
  26. package/dist/esm/harness/providerText.mjs +78 -0
  27. package/dist/esm/harness/providerText.mjs.map +1 -0
  28. package/dist/esm/llm/contextPressureMeter.mjs +1 -1
  29. package/dist/esm/llm/contextPressureMeter.mjs.map +1 -1
  30. package/dist/esm/llm/openai/index.mjs +21 -12
  31. package/dist/esm/llm/openai/index.mjs.map +1 -1
  32. package/dist/esm/llm/openai/streamMetadata.mjs +4 -1
  33. package/dist/esm/llm/openai/streamMetadata.mjs.map +1 -1
  34. package/dist/esm/main.mjs +3 -1
  35. package/dist/esm/stream.mjs +4 -1
  36. package/dist/esm/stream.mjs.map +1 -1
  37. package/dist/esm/tools/BashExecutor.mjs +2 -1
  38. package/dist/esm/tools/BashExecutor.mjs.map +1 -1
  39. package/dist/esm/tools/ToolNode.mjs +142 -95
  40. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  41. package/dist/esm/tools/toolOutputReferences.mjs +39 -18
  42. package/dist/esm/tools/toolOutputReferences.mjs.map +1 -1
  43. package/dist/types/harness/identity.d.ts +14 -0
  44. package/dist/types/harness/index.d.ts +5 -9
  45. package/dist/types/harness/providerText.d.ts +32 -0
  46. package/dist/types/llm/openai/streamMetadata.d.ts +3 -3
  47. package/dist/types/tools/ToolNode.d.ts +7 -7
  48. package/dist/types/tools/toolOutputReferences.d.ts +16 -4
  49. package/package.json +1 -1
  50. package/src/harness/identity.ts +34 -0
  51. package/src/harness/index.ts +15 -23
  52. package/src/harness/providerText.ts +128 -0
  53. package/src/llm/contextPressureMeter.ts +2 -4
  54. package/src/llm/openai/index.ts +60 -20
  55. package/src/llm/openai/streamMetadata.ts +14 -3
  56. package/src/stream.ts +10 -1
  57. package/src/tools/BashExecutor.ts +2 -1
  58. package/src/tools/ToolNode.ts +333 -256
  59. package/src/tools/toolOutputReferences.ts +101 -32
@@ -20,7 +20,7 @@ import "../hooks/index.mjs";
20
20
  import { convertInjectedMessages } from "../messages/injected.mjs";
21
21
  import { createToolCallsDispatchedEvent, safeDispatchCustomEvent } from "../utils/events.mjs";
22
22
  import { INTENT_ARG, isIntentLabelProperty, outcomeFieldsFromResult, readOutcomeFields, resolveToolOutcome } from "./intentArg.mjs";
23
- import { ToolOutputReferenceRegistry, buildReferenceKey } from "./toolOutputReferences.mjs";
23
+ import { ToolOutputReferenceRegistry, buildReferenceKey, snapshotResolvedArgs } from "./toolOutputReferences.mjs";
24
24
  import { formatToolErrorContent } from "./toolErrorContent.mjs";
25
25
  import { RunnableCallable } from "../utils/run.mjs";
26
26
  import "../utils/index.mjs";
@@ -711,7 +711,6 @@ var ToolNode = class extends RunnableCallable {
711
711
  if (preBatchSnapshot != null) resolveFn = (_runId, args) => preBatchSnapshot.resolve(args, resolveOptions);
712
712
  else if (registry != null) resolveFn = (runIdArg, args) => registry.resolve(runIdArg, args, resolveOptions);
713
713
  const refKey = registry != null && batchIndex != null && turn != null ? buildReferenceKey(batchIndex, turn) : void 0;
714
- let unresolvedRefs = [];
715
714
  const runId = batchScopeId ?? config.configurable?.run_id;
716
715
  try {
717
716
  if (tool === void 0) throw new Error(this.getUnknownToolErrorMessage(call.name));
@@ -725,9 +724,11 @@ var ToolNode = class extends RunnableCallable {
725
724
  if (batchContext.replayBatchKey != null && call.id != null && call.id !== "") this.directPathTurns.set(call.id, usageCount);
726
725
  let args = call.args;
727
726
  if (resolveFn != null) {
728
- const { resolved, unresolved } = resolveFn(runId, args);
727
+ const resolution = batchContext.resolvedInput ?? resolveFn(runId, args);
728
+ const { resolved } = resolution;
729
729
  args = resolved;
730
- unresolvedRefs = unresolved;
730
+ const referenceError = this.unresolvedReferenceMessage(call, resolution, preBatchSnapshot ?? registry?.snapshot(runId));
731
+ if (referenceError != null) return referenceError;
731
732
  if (resolvedArgsByCallId != null && call.id != null && call.id !== "" && resolved !== call.args && typeof resolved === "object") resolvedArgsByCallId.set(call.id, resolved);
732
733
  }
733
734
  const stepId = this.toolCallStepIds?.get(call.id);
@@ -789,31 +790,21 @@ var ToolNode = class extends RunnableCallable {
789
790
  const originalContent = toolMsg.content;
790
791
  const compacted = compactToolContent(originalContent, this.maxToolResultChars);
791
792
  if (compacted.changed) toolMsg.content = compacted.content;
792
- if (toolMsg.status === "error") {
793
- if (unresolvedRefs.length > 0) toolMsg.additional_kwargs = {
794
- ...toolMsg.additional_kwargs,
795
- _unresolvedRefs: unresolvedRefs
796
- };
797
- return toolMsg;
798
- }
799
- if (this.toolOutputRegistry != null || unresolvedRefs.length > 0) if (typeof originalContent === "string") {
800
- const registryContent = stripCodeSessionFileSummary(originalContent);
801
- const refMeta = this.recordOutputReference(runId, registryContent, refKey, unresolvedRefs);
802
- if (refMeta != null) toolMsg.additional_kwargs = {
803
- ...toolMsg.additional_kwargs,
804
- ...refMeta
805
- };
806
- } else {
807
- if (unresolvedRefs.length > 0) toolMsg.additional_kwargs = {
808
- ...toolMsg.additional_kwargs,
809
- _unresolvedRefs: unresolvedRefs
810
- };
811
- if (refKey != null && this.toolOutputRegistry.claimWarnOnce(runId, call.name)) console.warn(`[ToolNode] Skipping tool output reference for "${call.name}": ToolMessage content is not a string (further occurrences for this tool in the same run are suppressed).`);
793
+ if (toolMsg.status === "error") return toolMsg;
794
+ if (this.toolOutputRegistry != null) {
795
+ if (typeof originalContent === "string") {
796
+ const registryContent = stripCodeSessionFileSummary(originalContent);
797
+ const refMeta = this.recordOutputReference(runId, registryContent, refKey);
798
+ if (refMeta != null) toolMsg.additional_kwargs = {
799
+ ...toolMsg.additional_kwargs,
800
+ ...refMeta
801
+ };
802
+ } else if (refKey != null && this.toolOutputRegistry.claimWarnOnce(runId, call.name)) console.warn(`[ToolNode] Skipping tool output reference for "${call.name}": ToolMessage content is not a string (further occurrences for this tool in the same run are suppressed).`);
812
803
  }
813
804
  return toolMsg;
814
805
  }
815
806
  const serialized = serializeToolOutputWithinLimits(output, this.maxToolResultChars, this.toolOutputRegistry != null && refKey != null ? this.toolOutputRegistry.perOutputLimit : 0);
816
- const refMeta = this.recordOutputReference(runId, stripCodeSessionFileSummary(serialized.registryContent), refKey, unresolvedRefs);
807
+ const refMeta = this.recordOutputReference(runId, stripCodeSessionFileSummary(serialized.registryContent), refKey);
817
808
  return new ToolMessage({
818
809
  status: "success",
819
810
  name: tool.name,
@@ -857,17 +848,26 @@ var ToolNode = class extends RunnableCallable {
857
848
  }
858
849
  });
859
850
  }
860
- const errorContent = formatToolErrorContent(e.message, this.maxToolResultChars, config.signal, e);
861
- const refMeta = unresolvedRefs.length > 0 ? this.recordOutputReference(runId, errorContent, void 0, unresolvedRefs) : void 0;
862
851
  return new ToolMessage({
863
852
  status: "error",
864
- content: errorContent,
853
+ content: formatToolErrorContent(e.message, this.maxToolResultChars, config.signal, e),
865
854
  name: call.name,
866
- tool_call_id: call.id ?? "",
867
- ...refMeta != null && { additional_kwargs: refMeta }
855
+ tool_call_id: call.id ?? ""
868
856
  });
869
857
  }
870
858
  }
859
+ unresolvedReferenceMessage(call, resolution, view) {
860
+ if (resolution.unresolved.length === 0) return void 0;
861
+ const missing = [...new Set(resolution.unresolved.slice(0, 10).map((key) => key.slice(0, 80)))];
862
+ const available = [...new Set((view?.availableKeys ?? []).slice(0, 10).map((key) => key.slice(0, 80)))];
863
+ return new ToolMessage({
864
+ status: "error",
865
+ name: call.name,
866
+ tool_call_id: call.id ?? "",
867
+ content: `Unknown tool output references: ${missing.join(", ")}${resolution.unresolved.length > missing.length ? ", …" : ""}; nothing was run. Available keys (most recent, up to 10): ${available.join(", ") || "(none)"}. Use a prior batch's key, fetch the output again, or prefix a literal placeholder with a backslash.`,
868
+ additional_kwargs: { _unresolvedRefs: missing }
869
+ });
870
+ }
871
871
  async runDirectToolWithLifecycleHooks(call, config, batchContext = {}) {
872
872
  if (this.preparedSubagents?.owns(this.executingAgentId ?? "", call) === true && this.hookRegistry?.hasResultAlteringHooks(config.configurable?.run_id ?? "") === true) {
873
873
  this.preparedSubagents.clear();
@@ -935,15 +935,35 @@ var ToolNode = class extends RunnableCallable {
935
935
  const turn = usageCount;
936
936
  const stepId = this.toolCallStepIds?.get(call.id ?? "") ?? "";
937
937
  const hookResolveOptions = { substituteIntentKey: this.toolDeclaresBusinessIntent(call.name) };
938
- const resolveDirectArgs = (args) => {
939
- if (batchContext.preBatchSnapshot != null) return batchContext.preBatchSnapshot.resolve(args, hookResolveOptions).resolved;
940
- if (this.toolOutputRegistry != null) return this.toolOutputRegistry.resolve(registryRunId, args, hookResolveOptions).resolved;
941
- return args;
938
+ const referenceView = batchContext.preBatchSnapshot ?? this.toolOutputRegistry?.snapshot(registryRunId);
939
+ let inputResolution = {
940
+ resolved: {},
941
+ unresolved: []
942
+ };
943
+ const resolveDirectArgs = (args, previouslyResolved) => {
944
+ inputResolution = referenceView?.resolve(args, {
945
+ ...hookResolveOptions,
946
+ previouslyResolved
947
+ }) ?? {
948
+ resolved: args,
949
+ unresolved: []
950
+ };
951
+ return inputResolution.resolved;
942
952
  };
943
953
  const originalResolvedArgs = resolveDirectArgs(call.args);
954
+ const originalReferenceError = this.unresolvedReferenceMessage(call, inputResolution, referenceView);
955
+ if (originalReferenceError != null) return persistOutput(originalReferenceError);
944
956
  let resolvedArgs = hasPreHook || pendingApproval != null ? originalResolvedArgs : reviewedApproval?.request.arguments ?? originalResolvedArgs;
945
- let effectiveCall = call;
957
+ if (resolvedArgs !== originalResolvedArgs) inputResolution = {
958
+ resolved: resolvedArgs,
959
+ unresolved: []
960
+ };
961
+ let effectiveCall = {
962
+ ...call,
963
+ args: resolvedArgs
964
+ };
946
965
  if (hasPreHook || pendingApproval != null || reviewedApproval != null || approvalReviewEvidence != null) {
966
+ const hookBaseline = referenceView == null ? void 0 : snapshotResolvedArgs(resolvedArgs);
947
967
  const preResult = hookRegistry == null ? {
948
968
  additionalContexts: [],
949
969
  injectedMessages: [],
@@ -975,24 +995,36 @@ var ToolNode = class extends RunnableCallable {
975
995
  injectedMessages: [],
976
996
  errors: []
977
997
  });
998
+ if (preResult != null && preResult.additionalContexts.length > 0) {
999
+ replayAdditionalContexts.push(...preResult.additionalContexts);
1000
+ batchContext.additionalContextsSink?.push(...preResult.additionalContexts);
1001
+ }
1002
+ if (preResult?.updatedInput != null) {
1003
+ resolvedArgs = resolveDirectArgs(preResult.updatedInput, hookBaseline);
1004
+ effectiveCall = {
1005
+ ...call,
1006
+ args: resolvedArgs
1007
+ };
1008
+ } else if (preResult != null && reviewedApproval != null) {
1009
+ resolvedArgs = reviewedApproval.request.arguments;
1010
+ inputResolution = {
1011
+ resolved: resolvedArgs,
1012
+ unresolved: []
1013
+ };
1014
+ effectiveCall = {
1015
+ ...call,
1016
+ args: resolvedArgs
1017
+ };
1018
+ } else if (referenceView != null) {
1019
+ resolvedArgs = resolveDirectArgs(resolvedArgs, hookBaseline);
1020
+ effectiveCall = {
1021
+ ...call,
1022
+ args: resolvedArgs
1023
+ };
1024
+ }
1025
+ const referenceError = this.unresolvedReferenceMessage(call, inputResolution, referenceView);
1026
+ if (referenceError != null) return persistOutput(referenceError);
978
1027
  if (preResult != null) {
979
- if (preResult.additionalContexts.length > 0) {
980
- replayAdditionalContexts.push(...preResult.additionalContexts);
981
- batchContext.additionalContextsSink?.push(...preResult.additionalContexts);
982
- }
983
- if (preResult.updatedInput != null) {
984
- resolvedArgs = resolveDirectArgs(preResult.updatedInput);
985
- effectiveCall = {
986
- ...call,
987
- args: resolvedArgs
988
- };
989
- } else if (reviewedApproval != null) {
990
- resolvedArgs = reviewedApproval.request.arguments;
991
- effectiveCall = {
992
- ...call,
993
- args: resolvedArgs
994
- };
995
- }
996
1028
  if (preResult.hasHookFailures === true && isBackgroundDenyMode(this.humanInTheLoop)) return persistOutput(this.blockDirectCall({
997
1029
  call,
998
1030
  resolvedArgs,
@@ -1040,10 +1072,6 @@ var ToolNode = class extends RunnableCallable {
1040
1072
  }), effectiveCall.args);
1041
1073
  const allowedDecisions = preResult.decision === "ask" ? preResult.allowedDecisions : reviewedApproval?.reviewConfig.allowed_decisions;
1042
1074
  const askReason = preResult.decision === "ask" ? preResult.reason : reviewedApproval?.request.description;
1043
- if (effectiveCall === call) effectiveCall = {
1044
- ...call,
1045
- args: resolvedArgs
1046
- };
1047
1075
  const payload = buildToolApprovalInterruptPayload([{
1048
1076
  entry: {
1049
1077
  call: effectiveCall,
@@ -1053,6 +1081,7 @@ var ToolNode = class extends RunnableCallable {
1053
1081
  reason: askReason,
1054
1082
  allowedDecisions
1055
1083
  }], runId, this.executionContext, this.executingAgentId);
1084
+ const approvalBaseline = referenceView == null ? void 0 : snapshotResolvedArgs(effectiveCall.args);
1056
1085
  const resumeValue = AsyncLocalStorageProviderSingleton.runWithConfig(config, () => interrupt(payload));
1057
1086
  hookRegistry?.clearPendingToolApproval(approvalReplaySessionId, approvalReplayKey);
1058
1087
  const currentApproval = getReviewedToolApproval(payload, toolCallId);
@@ -1112,7 +1141,7 @@ var ToolNode = class extends RunnableCallable {
1112
1141
  }), effectiveCall.args);
1113
1142
  effectiveCall = {
1114
1143
  ...call,
1115
- args: updatedInput
1144
+ args: resolveDirectArgs(updatedInput, approvalBaseline)
1116
1145
  };
1117
1146
  }
1118
1147
  if (declaredType !== "approve" && declaredType !== "edit") {
@@ -1129,10 +1158,12 @@ var ToolNode = class extends RunnableCallable {
1129
1158
  }
1130
1159
  }
1131
1160
  }
1132
- if (effectiveCall !== call && batchContext.resolvedArgsByCallId != null && call.id != null && call.id !== "") batchContext.resolvedArgsByCallId.set(call.id, effectiveCall.args);
1161
+ if (batchContext.resolvedArgsByCallId != null && call.id != null && call.id !== "") batchContext.resolvedArgsByCallId.set(call.id, effectiveCall.args);
1133
1162
  const output = await this.runTool(effectiveCall, replayConfig, {
1134
1163
  ...batchContext,
1135
- usageCount
1164
+ usageCount,
1165
+ preBatchSnapshot: referenceView,
1166
+ resolvedInput: inputResolution
1136
1167
  });
1137
1168
  if (!(output instanceof ToolMessage)) return output;
1138
1169
  if (output.status === "error" && hasFailureHook) {
@@ -1237,16 +1268,13 @@ var ToolNode = class extends RunnableCallable {
1237
1268
  tool_call_id: call.id ?? ""
1238
1269
  });
1239
1270
  }
1240
- recordOutputReference(runId, registryContent, refKey, unresolved) {
1241
- if (this.toolOutputRegistry != null && refKey != null) this.toolOutputRegistry.set(runId, refKey, registryContent);
1242
- if (refKey == null && unresolved.length === 0) return void 0;
1243
- const meta = {};
1244
- if (refKey != null) {
1245
- meta._refKey = refKey;
1246
- if (runId != null) meta._refScope = runId;
1247
- }
1248
- if (unresolved.length > 0) meta._unresolvedRefs = unresolved;
1249
- return meta;
1271
+ recordOutputReference(runId, registryContent, refKey) {
1272
+ if (refKey == null) return void 0;
1273
+ this.toolOutputRegistry?.set(runId, refKey, registryContent);
1274
+ return runId == null ? { _refKey: refKey } : {
1275
+ _refKey: refKey,
1276
+ _refScope: runId
1277
+ };
1250
1278
  }
1251
1279
  getCodeSessionContext() {
1252
1280
  if (!this.sessions) return;
@@ -1360,7 +1388,8 @@ var ToolNode = class extends RunnableCallable {
1360
1388
  const threadId = config.configurable?.thread_id;
1361
1389
  const registry = this.toolOutputRegistry;
1362
1390
  const unresolvedByCallId = /* @__PURE__ */ new Map();
1363
- const preToolCalls = toolCalls.map((call, i) => {
1391
+ const referenceView = preBatchSnapshot ?? registry?.snapshot(registryRunId);
1392
+ let preToolCalls = toolCalls.map((call, i) => {
1364
1393
  const originalArgs = call.args;
1365
1394
  let resolvedArgs = originalArgs;
1366
1395
  const pre = call.id != null ? preResolvedArgs?.get(call.id) : void 0;
@@ -1369,7 +1398,7 @@ var ToolNode = class extends RunnableCallable {
1369
1398
  if (pre.unresolved.length > 0 && call.id != null) unresolvedByCallId.set(call.id, pre.unresolved);
1370
1399
  } else if (registry != null) {
1371
1400
  const options = { substituteIntentKey: this.toolDeclaresBusinessIntent(call.name) };
1372
- const { resolved, unresolved } = preBatchSnapshot != null ? preBatchSnapshot.resolve(originalArgs, options) : registry.resolve(registryRunId, originalArgs, options);
1401
+ const { resolved, unresolved } = referenceView.resolve(originalArgs, options);
1373
1402
  resolvedArgs = resolved;
1374
1403
  if (unresolved.length > 0 && call.id != null) unresolvedByCallId.set(call.id, unresolved);
1375
1404
  }
@@ -1389,6 +1418,25 @@ var ToolNode = class extends RunnableCallable {
1389
1418
  injectedMessages: [],
1390
1419
  errors: []
1391
1420
  });
1421
+ const referenceFailures = [];
1422
+ const rejectReferences = (entry) => {
1423
+ const error = this.unresolvedReferenceMessage(entry.call, { unresolved: unresolvedByCallId.get(entry.call.id ?? "") ?? [] }, referenceView);
1424
+ if (error == null) return false;
1425
+ messageByCallId.set(entry.call.id ?? "", error);
1426
+ referenceFailures.push(entry);
1427
+ this.eagerEventToolExecutions?.delete(entry.call.id ?? "");
1428
+ postToolBatchEntryByCallId.set(entry.call.id ?? "", {
1429
+ toolName: entry.call.name,
1430
+ toolInput: entry.args,
1431
+ toolUseId: entry.call.id ?? "",
1432
+ stepId: entry.stepId,
1433
+ turn: this.toolUsageCount.get(entry.call.name) ?? 0,
1434
+ status: "error",
1435
+ error: String(error.content)
1436
+ });
1437
+ return true;
1438
+ };
1439
+ preToolCalls = preToolCalls.filter((entry) => !rejectReferences(entry));
1392
1440
  const hookRegistry = this.hookRegistry;
1393
1441
  const approvalReplaySessionId = getToolApprovalReplaySessionId(config, runId);
1394
1442
  const replayOwner = getToolBatchReplayOwner(config, this.executingAgentId ?? this.agentId ?? "");
@@ -1410,6 +1458,7 @@ var ToolNode = class extends RunnableCallable {
1410
1458
  this.eagerEventToolExecutions.delete(callId);
1411
1459
  }
1412
1460
  }
1461
+ const referenceBaselines = referenceView == null ? void 0 : new Map(preToolCalls.map((entry) => [entry, snapshotResolvedArgs(entry.args)]));
1413
1462
  const preResults = hookRegistry == null ? preToolCalls.map(() => HOOK_FALLBACK) : await Promise.all(preToolCalls.map((entry) => {
1414
1463
  const toolUseId = entry.call.id;
1415
1464
  const approvalReplayKey = toolUseId == null ? void 0 : createToolApprovalReplayKey(config, this.executingAgentId ?? this.agentId ?? "", toolUseId);
@@ -1489,7 +1538,10 @@ var ToolNode = class extends RunnableCallable {
1489
1538
  };
1490
1539
  const applyInputOverride = (entry, nextArgs) => {
1491
1540
  if (registry != null) {
1492
- const { resolved, unresolved } = (preBatchSnapshot ?? { resolve: (args, options) => registry.resolve(registryRunId, args, options) }).resolve(nextArgs, { substituteIntentKey: this.toolDeclaresBusinessIntent(entry.call.name) });
1541
+ const { resolved, unresolved } = referenceView.resolve(nextArgs, {
1542
+ previouslyResolved: referenceBaselines?.get(entry),
1543
+ substituteIntentKey: this.toolDeclaresBusinessIntent(entry.call.name)
1544
+ });
1493
1545
  entry.args = this.coerceEventToolArgs(entry.call.name, resolved);
1494
1546
  if (entry.call.id != null) if (unresolved.length > 0) unresolvedByCallId.set(entry.call.id, unresolved);
1495
1547
  else unresolvedByCallId.delete(entry.call.id);
@@ -1510,18 +1562,18 @@ var ToolNode = class extends RunnableCallable {
1510
1562
  blockEntry(entry, hookResult.reason ?? "Blocked by hook");
1511
1563
  continue;
1512
1564
  }
1565
+ if (hookResult.updatedInput != null || referenceView != null) {
1566
+ applyInputOverride(entry, hookResult.updatedInput ?? entry.args);
1567
+ if (rejectReferences(entry)) continue;
1568
+ }
1513
1569
  if (hookResult.decision === "ask") {
1514
1570
  if (this.humanInTheLoop?.enabled !== true) {
1515
1571
  blockEntry(entry, isBackgroundDenyMode(this.humanInTheLoop) ? this.backgroundApprovalReason(entry.call.name, hookResult.reason) : hookResult.reason ?? "Blocked by hook");
1516
1572
  continue;
1517
1573
  }
1518
- if (hookResult.updatedInput != null) applyInputOverride(entry, hookResult.updatedInput);
1519
- else {
1574
+ if (hookResult.updatedInput == null) {
1520
1575
  const reviewed = getReviewedToolApproval(approvalReviewEvidence?.payload, entry.call.id);
1521
- if (reviewed != null) {
1522
- entry.args = this.coerceEventToolArgs(entry.call.name, reviewed.request.arguments);
1523
- if (entry.call.id != null) unresolvedByCallId.delete(entry.call.id);
1524
- }
1576
+ if (reviewed != null) entry.args = this.coerceEventToolArgs(entry.call.name, reviewed.request.arguments);
1525
1577
  }
1526
1578
  askEntries.push({
1527
1579
  entry,
@@ -1530,17 +1582,13 @@ var ToolNode = class extends RunnableCallable {
1530
1582
  });
1531
1583
  continue;
1532
1584
  }
1533
- if (hookResult.updatedInput != null) applyInputOverride(entry, hookResult.updatedInput);
1534
1585
  const reviewedApproval = getReviewedToolApproval(approvalReviewEvidence?.payload, entry.call.id);
1535
1586
  if (reviewedApproval != null) {
1536
1587
  if (this.humanInTheLoop?.enabled !== true) {
1537
1588
  blockEntry(entry, "Foreground tool approval is disabled");
1538
1589
  continue;
1539
1590
  }
1540
- if (hookResult.updatedInput == null) {
1541
- entry.args = this.coerceEventToolArgs(entry.call.name, reviewedApproval.request.arguments);
1542
- if (entry.call.id != null) unresolvedByCallId.delete(entry.call.id);
1543
- }
1591
+ if (hookResult.updatedInput == null) entry.args = this.coerceEventToolArgs(entry.call.name, reviewedApproval.request.arguments);
1544
1592
  askEntries.push({
1545
1593
  entry,
1546
1594
  reason: reviewedApproval.request.description,
@@ -1555,6 +1603,7 @@ var ToolNode = class extends RunnableCallable {
1555
1603
  approvedEntries.push(entry);
1556
1604
  }
1557
1605
  if (askEntries.length > 0) {
1606
+ if (referenceBaselines != null) for (const { entry } of askEntries) referenceBaselines.set(entry, snapshotResolvedArgs(entry.args));
1558
1607
  const payload = buildToolApprovalInterruptPayload(askEntries, runId, this.executionContext, this.executingAgentId);
1559
1608
  const resumeValue = AsyncLocalStorageProviderSingleton.runWithConfig(config, () => interrupt(payload));
1560
1609
  for (const { entry } of askEntries) hookRegistry?.clearPendingToolApproval(approvalReplaySessionId, createToolApprovalReplayKey(config, this.executingAgentId ?? this.agentId ?? "", entry.call.id));
@@ -1608,6 +1657,7 @@ var ToolNode = class extends RunnableCallable {
1608
1657
  continue;
1609
1658
  }
1610
1659
  applyInputOverride(entry, updatedInput);
1660
+ if (rejectReferences(entry)) continue;
1611
1661
  approvedEntries.push(entry);
1612
1662
  continue;
1613
1663
  }
@@ -1620,6 +1670,7 @@ var ToolNode = class extends RunnableCallable {
1620
1670
  }
1621
1671
  await flushDeferredBlockedSideEffects();
1622
1672
  } else approvedEntries.push(...preToolCalls);
1673
+ for (const entry of referenceFailures) await this.dispatchStepCompleted(entry.call.id ?? "", entry.call.name, entry.args, String(messageByCallId.get(entry.call.id ?? "").content), config);
1623
1674
  const injected = [];
1624
1675
  const batchIndexByCallId = /* @__PURE__ */ new Map();
1625
1676
  if (approvedEntries.length > 0) {
@@ -1764,14 +1815,11 @@ var ToolNode = class extends RunnableCallable {
1764
1815
  let finalToolOutput = result.content;
1765
1816
  if (result.status === "error") {
1766
1817
  contentString = formatToolErrorContent(result.errorMessage, this.maxToolResultChars, config.signal);
1767
- const unresolved = unresolvedByCallId.get(result.toolCallId) ?? [];
1768
- const errorRefMeta = unresolved.length > 0 ? this.recordOutputReference(registryRunId, contentString, void 0, unresolved) : void 0;
1769
1818
  toolMessage = new ToolMessage({
1770
1819
  status: "error",
1771
1820
  content: contentString,
1772
1821
  name: toolName,
1773
- tool_call_id: result.toolCallId,
1774
- ...errorRefMeta != null && { additional_kwargs: errorRefMeta }
1822
+ tool_call_id: result.toolCallId
1775
1823
  });
1776
1824
  if (hasFailureHook) {
1777
1825
  const failureHookResult = await executeHooks({
@@ -1830,8 +1878,7 @@ var ToolNode = class extends RunnableCallable {
1830
1878
  eagerCompletionDispatchedIds.delete(result.toolCallId);
1831
1879
  }
1832
1880
  }
1833
- const unresolved = unresolvedByCallId.get(result.toolCallId) ?? [];
1834
- const successRefMeta = this.recordOutputReference(registryRunId, stripCodeSessionFileSummary(registryRaw), refKey, unresolved);
1881
+ const successRefMeta = this.recordOutputReference(registryRunId, stripCodeSessionFileSummary(registryRaw), refKey);
1835
1882
  toolMessage = new ToolMessage({
1836
1883
  status: "success",
1837
1884
  name: toolName,
@@ -2132,7 +2179,7 @@ var ToolNode = class extends RunnableCallable {
2132
2179
  const errorOwnership = createToolErrorOwnership();
2133
2180
  const batchScopeId = config.configurable?.run_id ?? `\0anon-${this.anonBatchCounter++}`;
2134
2181
  const resumedReferenceState = referenceReplay.state;
2135
- const replayInputSnapshot = resumedReferenceState == null ? void 0 : this.toolOutputRegistry?.resumeBatch(batchScopeId, resumedReferenceState);
2182
+ const batchReferenceSnapshot = (resumedReferenceState == null ? void 0 : this.toolOutputRegistry?.resumeBatch(batchScopeId, resumedReferenceState)) ?? this.toolOutputRegistry?.snapshot(batchScopeId);
2136
2183
  referenceReplay.state = resumedReferenceState ?? this.toolOutputRegistry?.snapshotState(batchScopeId);
2137
2184
  const turn = resumedReferenceState?.turnCounter ?? this.toolOutputRegistry?.nextTurn(batchScopeId) ?? 0;
2138
2185
  let outputs;
@@ -2145,7 +2192,7 @@ var ToolNode = class extends RunnableCallable {
2145
2192
  batchIndices: [0],
2146
2193
  turn,
2147
2194
  batchScopeId,
2148
- preBatchSnapshot: replayInputSnapshot
2195
+ preBatchSnapshot: batchReferenceSnapshot
2149
2196
  });
2150
2197
  const directAdditionalContexts = [];
2151
2198
  const { lg_tool_call: _sendToolCall, ...sendState } = input;
@@ -2156,7 +2203,7 @@ var ToolNode = class extends RunnableCallable {
2156
2203
  batchIndex: 0,
2157
2204
  turn,
2158
2205
  batchScopeId,
2159
- preBatchSnapshot: replayInputSnapshot,
2206
+ preBatchSnapshot: batchReferenceSnapshot,
2160
2207
  resolvedArgsByCallId,
2161
2208
  codeSessionBaselineByCallId,
2162
2209
  errorOwnership,
@@ -2232,7 +2279,7 @@ var ToolNode = class extends RunnableCallable {
2232
2279
  batchIndices: eventEntries.map((entry) => entry.batchIndex),
2233
2280
  turn,
2234
2281
  batchScopeId,
2235
- preBatchSnapshot: replayInputSnapshot
2282
+ preBatchSnapshot: batchReferenceSnapshot
2236
2283
  });
2237
2284
  const directCalls = directEntries.map((e) => e.call);
2238
2285
  const directIndices = directEntries.map((e) => e.batchIndex);
@@ -2240,7 +2287,7 @@ var ToolNode = class extends RunnableCallable {
2240
2287
  const eventIndices = eventEntries.map((e) => e.batchIndex);
2241
2288
  const approvalScopeCallIds = new Set(filteredCalls.flatMap((call) => call.id == null ? [] : [call.id]));
2242
2289
  const preResolvedEventArgs = /* @__PURE__ */ new Map();
2243
- const preBatchSnapshot = replayInputSnapshot ?? this.toolOutputRegistry?.snapshot(batchScopeId);
2290
+ const preBatchSnapshot = batchReferenceSnapshot;
2244
2291
  if (preBatchSnapshot != null) {
2245
2292
  for (const entry of eventEntries) if (entry.call.id != null) {
2246
2293
  const { resolved, unresolved } = preBatchSnapshot.resolve(entry.call.args, { substituteIntentKey: this.toolDeclaresBusinessIntent(entry.call.name) });
@@ -2305,7 +2352,7 @@ var ToolNode = class extends RunnableCallable {
2305
2352
  ...eventResult.injected
2306
2353
  ];
2307
2354
  } else {
2308
- const preBatchSnapshot = replayInputSnapshot ?? this.toolOutputRegistry?.snapshot(batchScopeId);
2355
+ const preBatchSnapshot = batchReferenceSnapshot;
2309
2356
  const directAdditionalContexts = [];
2310
2357
  const approvalScopeCallIds = new Set(filteredCalls.flatMap((call) => call.id == null ? [] : [call.id]));
2311
2358
  const toolOutputs = await this.runDirectBatchInterruptSafe(filteredCalls, filteredCalls.map((_call, i) => i), config, {