@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.
- package/dist/cjs/harness/identity.cjs +26 -0
- package/dist/cjs/harness/identity.cjs.map +1 -0
- package/dist/cjs/harness/index.cjs +3 -15
- package/dist/cjs/harness/index.cjs.map +1 -1
- package/dist/cjs/harness/providerText.cjs +79 -0
- package/dist/cjs/harness/providerText.cjs.map +1 -0
- package/dist/cjs/llm/contextPressureMeter.cjs +1 -1
- package/dist/cjs/llm/contextPressureMeter.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs +21 -12
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/streamMetadata.cjs +4 -1
- package/dist/cjs/llm/openai/streamMetadata.cjs.map +1 -1
- package/dist/cjs/main.cjs +5 -0
- package/dist/cjs/stream.cjs +4 -1
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/tools/BashExecutor.cjs +2 -1
- package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +141 -94
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/toolOutputReferences.cjs +39 -17
- package/dist/cjs/tools/toolOutputReferences.cjs.map +1 -1
- package/dist/esm/harness/identity.mjs +24 -0
- package/dist/esm/harness/identity.mjs.map +1 -0
- package/dist/esm/harness/index.mjs +3 -15
- package/dist/esm/harness/index.mjs.map +1 -1
- package/dist/esm/harness/providerText.mjs +78 -0
- package/dist/esm/harness/providerText.mjs.map +1 -0
- package/dist/esm/llm/contextPressureMeter.mjs +1 -1
- package/dist/esm/llm/contextPressureMeter.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +21 -12
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/llm/openai/streamMetadata.mjs +4 -1
- package/dist/esm/llm/openai/streamMetadata.mjs.map +1 -1
- package/dist/esm/main.mjs +3 -1
- package/dist/esm/stream.mjs +4 -1
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/tools/BashExecutor.mjs +2 -1
- package/dist/esm/tools/BashExecutor.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +142 -95
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/toolOutputReferences.mjs +39 -18
- package/dist/esm/tools/toolOutputReferences.mjs.map +1 -1
- package/dist/types/harness/identity.d.ts +14 -0
- package/dist/types/harness/index.d.ts +5 -9
- package/dist/types/harness/providerText.d.ts +32 -0
- package/dist/types/llm/openai/streamMetadata.d.ts +3 -3
- package/dist/types/tools/ToolNode.d.ts +7 -7
- package/dist/types/tools/toolOutputReferences.d.ts +16 -4
- package/package.json +1 -1
- package/src/harness/identity.ts +34 -0
- package/src/harness/index.ts +15 -23
- package/src/harness/providerText.ts +128 -0
- package/src/llm/contextPressureMeter.ts +2 -4
- package/src/llm/openai/index.ts +60 -20
- package/src/llm/openai/streamMetadata.ts +14 -3
- package/src/stream.ts +10 -1
- package/src/tools/BashExecutor.ts +2 -1
- package/src/tools/ToolNode.ts +333 -256
- package/src/tools/toolOutputReferences.ts +101 -32
|
@@ -711,7 +711,6 @@ var ToolNode = class extends require_run.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 ? require_toolOutputReferences.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 require_run.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
|
|
727
|
+
const resolution = batchContext.resolvedInput ?? resolveFn(runId, args);
|
|
728
|
+
const { resolved } = resolution;
|
|
729
729
|
args = resolved;
|
|
730
|
-
|
|
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 require_run.RunnableCallable {
|
|
|
789
790
|
const originalContent = toolMsg.content;
|
|
790
791
|
const compacted = require_toolContent.compactToolContent(originalContent, this.maxToolResultChars);
|
|
791
792
|
if (compacted.changed) toolMsg.content = compacted.content;
|
|
792
|
-
if (toolMsg.status === "error")
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
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 = require_CodeSessionFileSummary.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, require_CodeSessionFileSummary.stripCodeSessionFileSummary(serialized.registryContent), refKey
|
|
807
|
+
const refMeta = this.recordOutputReference(runId, require_CodeSessionFileSummary.stripCodeSessionFileSummary(serialized.registryContent), refKey);
|
|
817
808
|
return new _langchain_core_messages.ToolMessage({
|
|
818
809
|
status: "success",
|
|
819
810
|
name: tool.name,
|
|
@@ -857,17 +848,26 @@ var ToolNode = class extends require_run.RunnableCallable {
|
|
|
857
848
|
}
|
|
858
849
|
});
|
|
859
850
|
}
|
|
860
|
-
const errorContent = require_toolErrorContent.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 _langchain_core_messages.ToolMessage({
|
|
863
852
|
status: "error",
|
|
864
|
-
content:
|
|
853
|
+
content: require_toolErrorContent.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 _langchain_core_messages.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 require_run.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
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
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
|
-
|
|
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 : require_toolOutputReferences.snapshotResolvedArgs(resolvedArgs);
|
|
947
967
|
const preResult = hookRegistry == null ? {
|
|
948
968
|
additionalContexts: [],
|
|
949
969
|
injectedMessages: [],
|
|
@@ -975,24 +995,36 @@ var ToolNode = class extends require_run.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 && require_hitl.isBackgroundDenyMode(this.humanInTheLoop)) return persistOutput(this.blockDirectCall({
|
|
997
1029
|
call,
|
|
998
1030
|
resolvedArgs,
|
|
@@ -1040,10 +1072,6 @@ var ToolNode = class extends require_run.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 require_run.RunnableCallable {
|
|
|
1053
1081
|
reason: askReason,
|
|
1054
1082
|
allowedDecisions
|
|
1055
1083
|
}], runId, this.executionContext, this.executingAgentId);
|
|
1084
|
+
const approvalBaseline = referenceView == null ? void 0 : require_toolOutputReferences.snapshotResolvedArgs(effectiveCall.args);
|
|
1056
1085
|
const resumeValue = _langchain_core_singletons.AsyncLocalStorageProviderSingleton.runWithConfig(config, () => (0, _langchain_langgraph.interrupt)(payload));
|
|
1057
1086
|
hookRegistry?.clearPendingToolApproval(approvalReplaySessionId, approvalReplayKey);
|
|
1058
1087
|
const currentApproval = require_approvalReview.getReviewedToolApproval(payload, toolCallId);
|
|
@@ -1112,7 +1141,7 @@ var ToolNode = class extends require_run.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 require_run.RunnableCallable {
|
|
|
1129
1158
|
}
|
|
1130
1159
|
}
|
|
1131
1160
|
}
|
|
1132
|
-
if (
|
|
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 _langchain_core_messages.ToolMessage)) return output;
|
|
1138
1169
|
if (output.status === "error" && hasFailureHook) {
|
|
@@ -1237,16 +1268,13 @@ var ToolNode = class extends require_run.RunnableCallable {
|
|
|
1237
1268
|
tool_call_id: call.id ?? ""
|
|
1238
1269
|
});
|
|
1239
1270
|
}
|
|
1240
|
-
recordOutputReference(runId, registryContent, refKey
|
|
1241
|
-
if (
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
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;
|
|
@@ -1361,7 +1389,8 @@ var ToolNode = class extends require_run.RunnableCallable {
|
|
|
1361
1389
|
const threadId = config.configurable?.thread_id;
|
|
1362
1390
|
const registry = this.toolOutputRegistry;
|
|
1363
1391
|
const unresolvedByCallId = /* @__PURE__ */ new Map();
|
|
1364
|
-
const
|
|
1392
|
+
const referenceView = preBatchSnapshot ?? registry?.snapshot(registryRunId);
|
|
1393
|
+
let preToolCalls = toolCalls.map((call, i) => {
|
|
1365
1394
|
const originalArgs = call.args;
|
|
1366
1395
|
let resolvedArgs = originalArgs;
|
|
1367
1396
|
const pre = call.id != null ? preResolvedArgs?.get(call.id) : void 0;
|
|
@@ -1370,7 +1399,7 @@ var ToolNode = class extends require_run.RunnableCallable {
|
|
|
1370
1399
|
if (pre.unresolved.length > 0 && call.id != null) unresolvedByCallId.set(call.id, pre.unresolved);
|
|
1371
1400
|
} else if (registry != null) {
|
|
1372
1401
|
const options = { substituteIntentKey: this.toolDeclaresBusinessIntent(call.name) };
|
|
1373
|
-
const { resolved, unresolved } =
|
|
1402
|
+
const { resolved, unresolved } = referenceView.resolve(originalArgs, options);
|
|
1374
1403
|
resolvedArgs = resolved;
|
|
1375
1404
|
if (unresolved.length > 0 && call.id != null) unresolvedByCallId.set(call.id, unresolved);
|
|
1376
1405
|
}
|
|
@@ -1390,6 +1419,25 @@ var ToolNode = class extends require_run.RunnableCallable {
|
|
|
1390
1419
|
injectedMessages: [],
|
|
1391
1420
|
errors: []
|
|
1392
1421
|
});
|
|
1422
|
+
const referenceFailures = [];
|
|
1423
|
+
const rejectReferences = (entry) => {
|
|
1424
|
+
const error = this.unresolvedReferenceMessage(entry.call, { unresolved: unresolvedByCallId.get(entry.call.id ?? "") ?? [] }, referenceView);
|
|
1425
|
+
if (error == null) return false;
|
|
1426
|
+
messageByCallId.set(entry.call.id ?? "", error);
|
|
1427
|
+
referenceFailures.push(entry);
|
|
1428
|
+
this.eagerEventToolExecutions?.delete(entry.call.id ?? "");
|
|
1429
|
+
postToolBatchEntryByCallId.set(entry.call.id ?? "", {
|
|
1430
|
+
toolName: entry.call.name,
|
|
1431
|
+
toolInput: entry.args,
|
|
1432
|
+
toolUseId: entry.call.id ?? "",
|
|
1433
|
+
stepId: entry.stepId,
|
|
1434
|
+
turn: this.toolUsageCount.get(entry.call.name) ?? 0,
|
|
1435
|
+
status: "error",
|
|
1436
|
+
error: String(error.content)
|
|
1437
|
+
});
|
|
1438
|
+
return true;
|
|
1439
|
+
};
|
|
1440
|
+
preToolCalls = preToolCalls.filter((entry) => !rejectReferences(entry));
|
|
1393
1441
|
const hookRegistry = this.hookRegistry;
|
|
1394
1442
|
const approvalReplaySessionId = getToolApprovalReplaySessionId(config, runId);
|
|
1395
1443
|
const replayOwner = require_toolBatchReplay.getToolBatchReplayOwner(config, this.executingAgentId ?? this.agentId ?? "");
|
|
@@ -1411,6 +1459,7 @@ var ToolNode = class extends require_run.RunnableCallable {
|
|
|
1411
1459
|
this.eagerEventToolExecutions.delete(callId);
|
|
1412
1460
|
}
|
|
1413
1461
|
}
|
|
1462
|
+
const referenceBaselines = referenceView == null ? void 0 : new Map(preToolCalls.map((entry) => [entry, require_toolOutputReferences.snapshotResolvedArgs(entry.args)]));
|
|
1414
1463
|
const preResults = hookRegistry == null ? preToolCalls.map(() => HOOK_FALLBACK) : await Promise.all(preToolCalls.map((entry) => {
|
|
1415
1464
|
const toolUseId = entry.call.id;
|
|
1416
1465
|
const approvalReplayKey = toolUseId == null ? void 0 : createToolApprovalReplayKey(config, this.executingAgentId ?? this.agentId ?? "", toolUseId);
|
|
@@ -1490,7 +1539,10 @@ var ToolNode = class extends require_run.RunnableCallable {
|
|
|
1490
1539
|
};
|
|
1491
1540
|
const applyInputOverride = (entry, nextArgs) => {
|
|
1492
1541
|
if (registry != null) {
|
|
1493
|
-
const { resolved, unresolved } =
|
|
1542
|
+
const { resolved, unresolved } = referenceView.resolve(nextArgs, {
|
|
1543
|
+
previouslyResolved: referenceBaselines?.get(entry),
|
|
1544
|
+
substituteIntentKey: this.toolDeclaresBusinessIntent(entry.call.name)
|
|
1545
|
+
});
|
|
1494
1546
|
entry.args = this.coerceEventToolArgs(entry.call.name, resolved);
|
|
1495
1547
|
if (entry.call.id != null) if (unresolved.length > 0) unresolvedByCallId.set(entry.call.id, unresolved);
|
|
1496
1548
|
else unresolvedByCallId.delete(entry.call.id);
|
|
@@ -1511,18 +1563,18 @@ var ToolNode = class extends require_run.RunnableCallable {
|
|
|
1511
1563
|
blockEntry(entry, hookResult.reason ?? "Blocked by hook");
|
|
1512
1564
|
continue;
|
|
1513
1565
|
}
|
|
1566
|
+
if (hookResult.updatedInput != null || referenceView != null) {
|
|
1567
|
+
applyInputOverride(entry, hookResult.updatedInput ?? entry.args);
|
|
1568
|
+
if (rejectReferences(entry)) continue;
|
|
1569
|
+
}
|
|
1514
1570
|
if (hookResult.decision === "ask") {
|
|
1515
1571
|
if (this.humanInTheLoop?.enabled !== true) {
|
|
1516
1572
|
blockEntry(entry, require_hitl.isBackgroundDenyMode(this.humanInTheLoop) ? this.backgroundApprovalReason(entry.call.name, hookResult.reason) : hookResult.reason ?? "Blocked by hook");
|
|
1517
1573
|
continue;
|
|
1518
1574
|
}
|
|
1519
|
-
if (hookResult.updatedInput
|
|
1520
|
-
else {
|
|
1575
|
+
if (hookResult.updatedInput == null) {
|
|
1521
1576
|
const reviewed = require_approvalReview.getReviewedToolApproval(approvalReviewEvidence?.payload, entry.call.id);
|
|
1522
|
-
if (reviewed != null)
|
|
1523
|
-
entry.args = this.coerceEventToolArgs(entry.call.name, reviewed.request.arguments);
|
|
1524
|
-
if (entry.call.id != null) unresolvedByCallId.delete(entry.call.id);
|
|
1525
|
-
}
|
|
1577
|
+
if (reviewed != null) entry.args = this.coerceEventToolArgs(entry.call.name, reviewed.request.arguments);
|
|
1526
1578
|
}
|
|
1527
1579
|
askEntries.push({
|
|
1528
1580
|
entry,
|
|
@@ -1531,17 +1583,13 @@ var ToolNode = class extends require_run.RunnableCallable {
|
|
|
1531
1583
|
});
|
|
1532
1584
|
continue;
|
|
1533
1585
|
}
|
|
1534
|
-
if (hookResult.updatedInput != null) applyInputOverride(entry, hookResult.updatedInput);
|
|
1535
1586
|
const reviewedApproval = require_approvalReview.getReviewedToolApproval(approvalReviewEvidence?.payload, entry.call.id);
|
|
1536
1587
|
if (reviewedApproval != null) {
|
|
1537
1588
|
if (this.humanInTheLoop?.enabled !== true) {
|
|
1538
1589
|
blockEntry(entry, "Foreground tool approval is disabled");
|
|
1539
1590
|
continue;
|
|
1540
1591
|
}
|
|
1541
|
-
if (hookResult.updatedInput == null)
|
|
1542
|
-
entry.args = this.coerceEventToolArgs(entry.call.name, reviewedApproval.request.arguments);
|
|
1543
|
-
if (entry.call.id != null) unresolvedByCallId.delete(entry.call.id);
|
|
1544
|
-
}
|
|
1592
|
+
if (hookResult.updatedInput == null) entry.args = this.coerceEventToolArgs(entry.call.name, reviewedApproval.request.arguments);
|
|
1545
1593
|
askEntries.push({
|
|
1546
1594
|
entry,
|
|
1547
1595
|
reason: reviewedApproval.request.description,
|
|
@@ -1556,6 +1604,7 @@ var ToolNode = class extends require_run.RunnableCallable {
|
|
|
1556
1604
|
approvedEntries.push(entry);
|
|
1557
1605
|
}
|
|
1558
1606
|
if (askEntries.length > 0) {
|
|
1607
|
+
if (referenceBaselines != null) for (const { entry } of askEntries) referenceBaselines.set(entry, require_toolOutputReferences.snapshotResolvedArgs(entry.args));
|
|
1559
1608
|
const payload = buildToolApprovalInterruptPayload(askEntries, runId, this.executionContext, this.executingAgentId);
|
|
1560
1609
|
const resumeValue = _langchain_core_singletons.AsyncLocalStorageProviderSingleton.runWithConfig(config, () => (0, _langchain_langgraph.interrupt)(payload));
|
|
1561
1610
|
for (const { entry } of askEntries) hookRegistry?.clearPendingToolApproval(approvalReplaySessionId, createToolApprovalReplayKey(config, this.executingAgentId ?? this.agentId ?? "", entry.call.id));
|
|
@@ -1609,6 +1658,7 @@ var ToolNode = class extends require_run.RunnableCallable {
|
|
|
1609
1658
|
continue;
|
|
1610
1659
|
}
|
|
1611
1660
|
applyInputOverride(entry, updatedInput);
|
|
1661
|
+
if (rejectReferences(entry)) continue;
|
|
1612
1662
|
approvedEntries.push(entry);
|
|
1613
1663
|
continue;
|
|
1614
1664
|
}
|
|
@@ -1621,6 +1671,7 @@ var ToolNode = class extends require_run.RunnableCallable {
|
|
|
1621
1671
|
}
|
|
1622
1672
|
await flushDeferredBlockedSideEffects();
|
|
1623
1673
|
} else approvedEntries.push(...preToolCalls);
|
|
1674
|
+
for (const entry of referenceFailures) await this.dispatchStepCompleted(entry.call.id ?? "", entry.call.name, entry.args, String(messageByCallId.get(entry.call.id ?? "").content), config);
|
|
1624
1675
|
const injected = [];
|
|
1625
1676
|
const batchIndexByCallId = /* @__PURE__ */ new Map();
|
|
1626
1677
|
if (approvedEntries.length > 0) {
|
|
@@ -1765,14 +1816,11 @@ var ToolNode = class extends require_run.RunnableCallable {
|
|
|
1765
1816
|
let finalToolOutput = result.content;
|
|
1766
1817
|
if (result.status === "error") {
|
|
1767
1818
|
contentString = require_toolErrorContent.formatToolErrorContent(result.errorMessage, this.maxToolResultChars, config.signal);
|
|
1768
|
-
const unresolved = unresolvedByCallId.get(result.toolCallId) ?? [];
|
|
1769
|
-
const errorRefMeta = unresolved.length > 0 ? this.recordOutputReference(registryRunId, contentString, void 0, unresolved) : void 0;
|
|
1770
1819
|
toolMessage = new _langchain_core_messages.ToolMessage({
|
|
1771
1820
|
status: "error",
|
|
1772
1821
|
content: contentString,
|
|
1773
1822
|
name: toolName,
|
|
1774
|
-
tool_call_id: result.toolCallId
|
|
1775
|
-
...errorRefMeta != null && { additional_kwargs: errorRefMeta }
|
|
1823
|
+
tool_call_id: result.toolCallId
|
|
1776
1824
|
});
|
|
1777
1825
|
if (hasFailureHook) {
|
|
1778
1826
|
const failureHookResult = await require_executeHooks.executeHooks({
|
|
@@ -1831,8 +1879,7 @@ var ToolNode = class extends require_run.RunnableCallable {
|
|
|
1831
1879
|
eagerCompletionDispatchedIds.delete(result.toolCallId);
|
|
1832
1880
|
}
|
|
1833
1881
|
}
|
|
1834
|
-
const
|
|
1835
|
-
const successRefMeta = this.recordOutputReference(registryRunId, require_CodeSessionFileSummary.stripCodeSessionFileSummary(registryRaw), refKey, unresolved);
|
|
1882
|
+
const successRefMeta = this.recordOutputReference(registryRunId, require_CodeSessionFileSummary.stripCodeSessionFileSummary(registryRaw), refKey);
|
|
1836
1883
|
toolMessage = new _langchain_core_messages.ToolMessage({
|
|
1837
1884
|
status: "success",
|
|
1838
1885
|
name: toolName,
|
|
@@ -2133,7 +2180,7 @@ var ToolNode = class extends require_run.RunnableCallable {
|
|
|
2133
2180
|
const errorOwnership = createToolErrorOwnership();
|
|
2134
2181
|
const batchScopeId = config.configurable?.run_id ?? `\0anon-${this.anonBatchCounter++}`;
|
|
2135
2182
|
const resumedReferenceState = referenceReplay.state;
|
|
2136
|
-
const
|
|
2183
|
+
const batchReferenceSnapshot = (resumedReferenceState == null ? void 0 : this.toolOutputRegistry?.resumeBatch(batchScopeId, resumedReferenceState)) ?? this.toolOutputRegistry?.snapshot(batchScopeId);
|
|
2137
2184
|
referenceReplay.state = resumedReferenceState ?? this.toolOutputRegistry?.snapshotState(batchScopeId);
|
|
2138
2185
|
const turn = resumedReferenceState?.turnCounter ?? this.toolOutputRegistry?.nextTurn(batchScopeId) ?? 0;
|
|
2139
2186
|
let outputs;
|
|
@@ -2146,7 +2193,7 @@ var ToolNode = class extends require_run.RunnableCallable {
|
|
|
2146
2193
|
batchIndices: [0],
|
|
2147
2194
|
turn,
|
|
2148
2195
|
batchScopeId,
|
|
2149
|
-
preBatchSnapshot:
|
|
2196
|
+
preBatchSnapshot: batchReferenceSnapshot
|
|
2150
2197
|
});
|
|
2151
2198
|
const directAdditionalContexts = [];
|
|
2152
2199
|
const { lg_tool_call: _sendToolCall, ...sendState } = input;
|
|
@@ -2157,7 +2204,7 @@ var ToolNode = class extends require_run.RunnableCallable {
|
|
|
2157
2204
|
batchIndex: 0,
|
|
2158
2205
|
turn,
|
|
2159
2206
|
batchScopeId,
|
|
2160
|
-
preBatchSnapshot:
|
|
2207
|
+
preBatchSnapshot: batchReferenceSnapshot,
|
|
2161
2208
|
resolvedArgsByCallId,
|
|
2162
2209
|
codeSessionBaselineByCallId,
|
|
2163
2210
|
errorOwnership,
|
|
@@ -2233,7 +2280,7 @@ var ToolNode = class extends require_run.RunnableCallable {
|
|
|
2233
2280
|
batchIndices: eventEntries.map((entry) => entry.batchIndex),
|
|
2234
2281
|
turn,
|
|
2235
2282
|
batchScopeId,
|
|
2236
|
-
preBatchSnapshot:
|
|
2283
|
+
preBatchSnapshot: batchReferenceSnapshot
|
|
2237
2284
|
});
|
|
2238
2285
|
const directCalls = directEntries.map((e) => e.call);
|
|
2239
2286
|
const directIndices = directEntries.map((e) => e.batchIndex);
|
|
@@ -2241,7 +2288,7 @@ var ToolNode = class extends require_run.RunnableCallable {
|
|
|
2241
2288
|
const eventIndices = eventEntries.map((e) => e.batchIndex);
|
|
2242
2289
|
const approvalScopeCallIds = new Set(filteredCalls.flatMap((call) => call.id == null ? [] : [call.id]));
|
|
2243
2290
|
const preResolvedEventArgs = /* @__PURE__ */ new Map();
|
|
2244
|
-
const preBatchSnapshot =
|
|
2291
|
+
const preBatchSnapshot = batchReferenceSnapshot;
|
|
2245
2292
|
if (preBatchSnapshot != null) {
|
|
2246
2293
|
for (const entry of eventEntries) if (entry.call.id != null) {
|
|
2247
2294
|
const { resolved, unresolved } = preBatchSnapshot.resolve(entry.call.args, { substituteIntentKey: this.toolDeclaresBusinessIntent(entry.call.name) });
|
|
@@ -2306,7 +2353,7 @@ var ToolNode = class extends require_run.RunnableCallable {
|
|
|
2306
2353
|
...eventResult.injected
|
|
2307
2354
|
];
|
|
2308
2355
|
} else {
|
|
2309
|
-
const preBatchSnapshot =
|
|
2356
|
+
const preBatchSnapshot = batchReferenceSnapshot;
|
|
2310
2357
|
const directAdditionalContexts = [];
|
|
2311
2358
|
const approvalScopeCallIds = new Set(filteredCalls.flatMap((call) => call.id == null ? [] : [call.id]));
|
|
2312
2359
|
const toolOutputs = await this.runDirectBatchInterruptSafe(filteredCalls, filteredCalls.map((_call, i) => i), config, {
|