@librechat/agents 3.4.0 → 3.4.1
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/graphs/Graph.cjs +111 -27
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/hooks/HookRegistry.cjs +83 -0
- package/dist/cjs/hooks/HookRegistry.cjs.map +1 -1
- package/dist/cjs/hooks/executeHooks.cjs +60 -14
- package/dist/cjs/hooks/executeHooks.cjs.map +1 -1
- package/dist/cjs/hooks/index.cjs.map +1 -1
- package/dist/cjs/hooks/types.cjs +2 -0
- package/dist/cjs/hooks/types.cjs.map +1 -1
- package/dist/cjs/llm/init.cjs +3 -3
- package/dist/cjs/llm/invoke.cjs +2 -2
- package/dist/cjs/main.cjs +14 -13
- package/dist/cjs/messages/format.cjs +40 -23
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/cjs/run.cjs +82 -15
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/session/AgentSession.cjs +37 -2
- package/dist/cjs/session/AgentSession.cjs.map +1 -1
- package/dist/cjs/stream.cjs +1 -1
- package/dist/cjs/summarization/node.cjs +6 -3
- package/dist/cjs/summarization/node.cjs.map +1 -1
- package/dist/cjs/tools/BashExecutor.cjs +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +1 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +1 -1
- package/dist/cjs/tools/ToolNode.cjs +316 -94
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/ToolSearch.cjs +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +630 -78
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentReplay.cjs +175 -0
- package/dist/cjs/tools/subagent/SubagentReplay.cjs.map +1 -0
- package/dist/cjs/tools/toolOutputReferences.cjs +20 -0
- package/dist/cjs/tools/toolOutputReferences.cjs.map +1 -1
- package/dist/cjs/utils/index.cjs +2 -2
- package/dist/esm/graphs/Graph.mjs +111 -27
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/hooks/HookRegistry.mjs +83 -0
- package/dist/esm/hooks/HookRegistry.mjs.map +1 -1
- package/dist/esm/hooks/executeHooks.mjs +60 -14
- package/dist/esm/hooks/executeHooks.mjs.map +1 -1
- package/dist/esm/hooks/index.mjs.map +1 -1
- package/dist/esm/hooks/types.mjs +2 -1
- package/dist/esm/hooks/types.mjs.map +1 -1
- package/dist/esm/llm/init.mjs +1 -1
- package/dist/esm/llm/invoke.mjs +2 -2
- package/dist/esm/main.mjs +11 -11
- package/dist/esm/messages/format.mjs +40 -23
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/esm/run.mjs +83 -16
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/session/AgentSession.mjs +37 -2
- package/dist/esm/session/AgentSession.mjs.map +1 -1
- package/dist/esm/stream.mjs +1 -1
- package/dist/esm/summarization/node.mjs +6 -3
- package/dist/esm/summarization/node.mjs.map +1 -1
- package/dist/esm/tools/BashExecutor.mjs +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +1 -1
- package/dist/esm/tools/ToolNode.mjs +317 -95
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/ToolSearch.mjs +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +631 -79
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentReplay.mjs +168 -0
- package/dist/esm/tools/subagent/SubagentReplay.mjs.map +1 -0
- package/dist/esm/tools/toolOutputReferences.mjs +20 -0
- package/dist/esm/tools/toolOutputReferences.mjs.map +1 -1
- package/dist/esm/utils/index.mjs +2 -2
- package/dist/types/graphs/Graph.d.ts +16 -1
- package/dist/types/hooks/HookRegistry.d.ts +10 -1
- package/dist/types/hooks/executeHooks.d.ts +5 -1
- package/dist/types/hooks/index.d.ts +2 -2
- package/dist/types/hooks/types.d.ts +12 -0
- package/dist/types/run.d.ts +4 -1
- package/dist/types/session/AgentSession.d.ts +1 -0
- package/dist/types/tools/ToolNode.d.ts +23 -15
- package/dist/types/tools/subagent/SubagentExecutor.d.ts +46 -7
- package/dist/types/tools/subagent/SubagentReplay.d.ts +81 -0
- package/dist/types/tools/toolOutputReferences.d.ts +12 -0
- package/dist/types/types/graph.d.ts +5 -5
- package/dist/types/types/hitl.d.ts +15 -0
- package/package.json +6 -2
- package/src/graphs/Graph.ts +246 -52
- package/src/graphs/__tests__/Graph.breakerLifecycle.test.ts +48 -9
- package/src/graphs/__tests__/Graph.contextOverflow.test.ts +1 -1
- package/src/graphs/__tests__/Graph.subagentResumeState.test.ts +80 -0
- package/src/hooks/HookRegistry.ts +151 -1
- package/src/hooks/__tests__/HookRegistry.test.ts +96 -0
- package/src/hooks/__tests__/executeHooks.test.ts +160 -0
- package/src/hooks/executeHooks.ts +133 -15
- package/src/hooks/index.ts +3 -1
- package/src/hooks/types.ts +16 -0
- package/src/messages/format.ts +54 -26
- package/src/messages/formatAgentMessages.reducer.test.ts +162 -0
- package/src/messages/formatAgentMessages.steer.test.ts +16 -11
- package/src/messages/formatAgentMessages.test.ts +7 -2
- package/src/run.ts +164 -18
- package/src/session/AgentSession.ts +52 -2
- package/src/session/__tests__/JsonlSessionStore.test.ts +53 -0
- package/src/summarization/__tests__/node.test.ts +32 -14
- package/src/summarization/node.ts +15 -11
- package/src/tools/ToolNode.ts +631 -157
- package/src/tools/__tests__/SubagentExecutor.test.ts +542 -6
- package/src/tools/__tests__/SubagentReplay.test.ts +300 -0
- package/src/tools/__tests__/ToolNode.breakerSignal.test.ts +208 -2
- package/src/tools/__tests__/directToolHITLResumeScope.test.ts +486 -2
- package/src/tools/__tests__/hitl.test.ts +234 -5
- package/src/tools/__tests__/subagentHooks.test.ts +1040 -62
- package/src/tools/__tests__/toolOutputReferences.test.ts +19 -2
- package/src/tools/subagent/SubagentExecutor.ts +1369 -131
- package/src/tools/subagent/SubagentReplay.ts +575 -0
- package/src/tools/toolOutputReferences.ts +40 -1
- package/src/types/graph.ts +5 -5
- package/src/types/hitl.ts +16 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const require_SubagentReplay = require("../tools/subagent/SubagentReplay.cjs");
|
|
1
2
|
const require_misc = require("../utils/misc.cjs");
|
|
2
3
|
const require_langfuseConfig = require("../langfuseConfig.cjs");
|
|
3
4
|
const require_langfuseRuntimeScope = require("../langfuseRuntimeScope.cjs");
|
|
@@ -27,16 +28,16 @@ const require_handoffCue = require("../messages/handoffCue.cjs");
|
|
|
27
28
|
const require_reducer = require("../messages/reducer.cjs");
|
|
28
29
|
const require_recency = require("../messages/recency.cjs");
|
|
29
30
|
require("../messages/index.cjs");
|
|
31
|
+
const require_graph = require("../utils/graph.cjs");
|
|
32
|
+
const require_llm = require("../utils/llm.cjs");
|
|
30
33
|
const require_handlers = require("../tools/handlers.cjs");
|
|
31
34
|
const require_streamLimits = require("../llm/streamLimits.cjs");
|
|
32
35
|
const require_toolOutputReferences = require("../tools/toolOutputReferences.cjs");
|
|
33
|
-
const require_llm = require("../utils/llm.cjs");
|
|
34
|
-
const require_toolCache = require("../llm/bedrock/toolCache.cjs");
|
|
35
|
-
const require_preempt = require("../llm/preempt.cjs");
|
|
36
|
-
const require_graph = require("../utils/graph.cjs");
|
|
37
36
|
const require_events$1 = require("../events.cjs");
|
|
38
37
|
const require_run = require("../utils/run.cjs");
|
|
39
38
|
require("../utils/index.cjs");
|
|
39
|
+
const require_toolCache = require("../llm/bedrock/toolCache.cjs");
|
|
40
|
+
const require_preempt = require("../llm/preempt.cjs");
|
|
40
41
|
const require_init = require("../llm/init.cjs");
|
|
41
42
|
const require_invoke = require("../llm/invoke.cjs");
|
|
42
43
|
const require_contextOverflowRecovery = require("../llm/contextOverflowRecovery.cjs");
|
|
@@ -262,6 +263,7 @@ function getDispatchableFinalReasoningContent({ agentContext, responseReasoningC
|
|
|
262
263
|
return responseReasoningContent;
|
|
263
264
|
}
|
|
264
265
|
var Graph = class {
|
|
266
|
+
restoreCheckpointMessages(_messages, _pendingMessages) {}
|
|
265
267
|
/** Returns a snapshot of deferred tools discovered by this graph. */
|
|
266
268
|
getDiscoveredTools(_agentId) {
|
|
267
269
|
return [];
|
|
@@ -419,7 +421,7 @@ var Graph = class {
|
|
|
419
421
|
this._toolOutputRegistry?.clear();
|
|
420
422
|
this._toolOutputRegistry = void 0;
|
|
421
423
|
for (const node of this._compiledToolNodes) node.clearDirectPathTurns();
|
|
422
|
-
this.
|
|
424
|
+
for (const executor of this._subagentExecutors) executor.clearHeavyState();
|
|
423
425
|
this.sessions.clear();
|
|
424
426
|
}
|
|
425
427
|
getEagerEventToolUsageCount(agentId) {
|
|
@@ -460,6 +462,73 @@ var Graph = class {
|
|
|
460
462
|
registerCompiledToolNode(node) {
|
|
461
463
|
this._compiledToolNodes.add(node);
|
|
462
464
|
}
|
|
465
|
+
registerSubagentExecutor(executor) {
|
|
466
|
+
this._subagentExecutors.add(executor);
|
|
467
|
+
}
|
|
468
|
+
resetSubagentCheckpointThreadIds() {
|
|
469
|
+
for (const executor of this._subagentExecutors) executor.resetCheckpointThreadIds();
|
|
470
|
+
}
|
|
471
|
+
getChildCheckpointThreadIds() {
|
|
472
|
+
const threadIds = /* @__PURE__ */ new Set();
|
|
473
|
+
for (const executor of this._subagentExecutors) for (const threadId of executor.getChildCheckpointThreadIds()) threadIds.add(threadId);
|
|
474
|
+
return [...threadIds];
|
|
475
|
+
}
|
|
476
|
+
createSubagentResumeState(runId) {
|
|
477
|
+
return {
|
|
478
|
+
toolCallSteps: [...this.toolCallStepIds].map(([toolCallId, stepId]) => ({
|
|
479
|
+
toolCallId,
|
|
480
|
+
stepId
|
|
481
|
+
})),
|
|
482
|
+
toolSessions: [...this.sessions].map(([toolName, context]) => ({
|
|
483
|
+
toolName,
|
|
484
|
+
context: {
|
|
485
|
+
...context,
|
|
486
|
+
...context.files == null ? {} : { files: context.files.map((file) => ({ ...file })) }
|
|
487
|
+
}
|
|
488
|
+
})),
|
|
489
|
+
toolNodes: [...this._compiledToolNodes].map((node) => node.createSubagentResumeState()),
|
|
490
|
+
eagerToolUsage: [{
|
|
491
|
+
agentId: "",
|
|
492
|
+
toolUsageCounts: [...this.eagerEventToolUsageCount].map(([toolName, count]) => ({
|
|
493
|
+
toolName,
|
|
494
|
+
count
|
|
495
|
+
}))
|
|
496
|
+
}, ...[...this.eagerEventToolUsageCountsByAgentId].map(([agentId, usageCounts]) => ({
|
|
497
|
+
agentId,
|
|
498
|
+
toolUsageCounts: [...usageCounts].map(([toolName, count]) => ({
|
|
499
|
+
toolName,
|
|
500
|
+
count
|
|
501
|
+
}))
|
|
502
|
+
}))],
|
|
503
|
+
eagerToolSuppressions: [...this.eagerEventToolSuppressions],
|
|
504
|
+
...this._toolOutputRegistry == null ? {} : { toolOutputReferences: this._toolOutputRegistry.snapshotState(runId) }
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
restoreSubagentResumeState(state, runId) {
|
|
508
|
+
const toolNodesByKey = new Map([...this._compiledToolNodes].map((node) => {
|
|
509
|
+
return [node.createSubagentResumeState().stateKey, node];
|
|
510
|
+
}));
|
|
511
|
+
if (toolNodesByKey.size !== state.toolNodes.length) throw new Error("Cannot restore changed subagent tool topology.");
|
|
512
|
+
for (const nodeState of state.toolNodes) if (!toolNodesByKey.has(nodeState.stateKey)) throw new Error(`Cannot restore subagent tool state for "${nodeState.stateKey}".`);
|
|
513
|
+
const registry = state.toolOutputReferences == null ? void 0 : this.getOrCreateToolOutputRegistry();
|
|
514
|
+
if (state.toolOutputReferences != null && registry == null) throw new Error("Cannot restore disabled tool output references.");
|
|
515
|
+
this.toolCallStepIds.clear();
|
|
516
|
+
for (const { toolCallId, stepId } of state.toolCallSteps) this.toolCallStepIds.set(toolCallId, stepId);
|
|
517
|
+
this.sessions.clear();
|
|
518
|
+
for (const { toolName, context } of state.toolSessions) this.sessions.set(toolName, {
|
|
519
|
+
...context,
|
|
520
|
+
...context.files == null ? {} : { files: context.files.map((file) => ({ ...file })) }
|
|
521
|
+
});
|
|
522
|
+
for (const nodeState of state.toolNodes) toolNodesByKey.get(nodeState.stateKey).restoreSubagentResumeState(nodeState);
|
|
523
|
+
this.clearEagerEventToolUsageCounts();
|
|
524
|
+
for (const usageState of state.eagerToolUsage) {
|
|
525
|
+
const usageCounts = this.getEagerEventToolUsageCount(usageState.agentId);
|
|
526
|
+
for (const { toolName, count } of usageState.toolUsageCounts) usageCounts.set(toolName, count);
|
|
527
|
+
}
|
|
528
|
+
this.eagerEventToolSuppressions.clear();
|
|
529
|
+
for (const toolName of state.eagerToolSuppressions) this.eagerEventToolSuppressions.add(toolName);
|
|
530
|
+
if (state.toolOutputReferences != null && registry != null) registry.restoreState(runId, state.toolOutputReferences);
|
|
531
|
+
}
|
|
463
532
|
/**
|
|
464
533
|
* Returns the shared `ToolOutputReferenceRegistry` for this run,
|
|
465
534
|
* constructing it on first access. Returns `undefined` when the
|
|
@@ -501,6 +570,7 @@ var Graph = class {
|
|
|
501
570
|
* across Runs if a provider reuses call ids (Codex P2 #33).
|
|
502
571
|
*/
|
|
503
572
|
_compiledToolNodes = /* @__PURE__ */ new Set();
|
|
573
|
+
_subagentExecutors = /* @__PURE__ */ new Set();
|
|
504
574
|
getOrCreateFileCheckpointer() {
|
|
505
575
|
if (this._fileCheckpointer != null) return this._fileCheckpointer;
|
|
506
576
|
if (this.toolExecution?.engine === "local" && this.toolExecution.local?.fileCheckpointing === true) {
|
|
@@ -523,6 +593,8 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
523
593
|
/** Whether the workflow was actually compiled with a checkpointer. */
|
|
524
594
|
hasCompiledCheckpointer = false;
|
|
525
595
|
messages = [];
|
|
596
|
+
/** Whether a rebuilt resume seeded the message baseline from its checkpoint. */
|
|
597
|
+
hasRestoredCheckpointMessages = false;
|
|
526
598
|
/** Cached run messages preserved before clearHeavyState() so getRunMessages() works after cleanup. */
|
|
527
599
|
cachedRunMessages;
|
|
528
600
|
/** Per-agent discovery snapshots preserved before contexts are reset on cleanup. */
|
|
@@ -686,7 +758,9 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
686
758
|
this.defaultAgentId = agents[0].agentId;
|
|
687
759
|
}
|
|
688
760
|
resetValues(keepContent, checkpointScope) {
|
|
761
|
+
this.resetSubagentCheckpointThreadIds();
|
|
689
762
|
this.messages = [];
|
|
763
|
+
this.hasRestoredCheckpointMessages = false;
|
|
690
764
|
this.cachedRunMessages = void 0;
|
|
691
765
|
this.cachedDiscoveredTools = void 0;
|
|
692
766
|
this.config = require_graph.resetIfNotEmpty(this.config, void 0);
|
|
@@ -744,6 +818,14 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
744
818
|
for (const context of this.agentContexts.values()) context.reset({ preserveOriginalToolContent });
|
|
745
819
|
this.originalToolContentCheckpointScope = hasScopedCheckpoint ? checkpointScope : void 0;
|
|
746
820
|
}
|
|
821
|
+
/** Seeds the sidecar message view that checkpoint restoration bypasses. */
|
|
822
|
+
restoreCheckpointMessages(messages, pendingMessages) {
|
|
823
|
+
if (this.messages.length > 0) return;
|
|
824
|
+
this.messages = pendingMessages == null ? [...messages] : require_reducer.messagesStateReducer(messages, pendingMessages);
|
|
825
|
+
this.startIndex = this.messages.length;
|
|
826
|
+
this.hasRestoredCheckpointMessages = true;
|
|
827
|
+
this.cachedRunMessages = void 0;
|
|
828
|
+
}
|
|
747
829
|
clearHeavyState() {
|
|
748
830
|
this.cachedRunMessages = this.messages.slice(this.startIndex);
|
|
749
831
|
this.cachedDiscoveredTools = new Map(Array.from(this.agentContexts, ([agentId, context]) => [agentId, context.getDiscoveredTools()]));
|
|
@@ -1031,6 +1113,9 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1031
1113
|
runLangfuse: this.langfuse,
|
|
1032
1114
|
agentLangfuse: agentContext?.langfuse
|
|
1033
1115
|
});
|
|
1116
|
+
const interruptingToolNames = new Set(this.interruptingToolNames ?? []);
|
|
1117
|
+
if (this.humanInTheLoop?.enabled === true && (agentContext?.subagentConfigs?.length ?? 0) > 0) interruptingToolNames.add("subagent");
|
|
1118
|
+
const effectiveInterruptingToolNames = interruptingToolNames.size > 0 ? interruptingToolNames : void 0;
|
|
1034
1119
|
if (eventDrivenMode) {
|
|
1035
1120
|
const schemaTools = require_schema.createSchemaOnlyTools(toolDefinitions);
|
|
1036
1121
|
const toolDefMap = new Map(toolDefinitions.map((def) => [def.name, def]));
|
|
@@ -1067,7 +1152,7 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1067
1152
|
eagerEventToolSuppressions: this.eagerEventToolSuppressions,
|
|
1068
1153
|
toolExecution: this.toolExecution,
|
|
1069
1154
|
directToolNames: directToolNames.size > 0 ? directToolNames : void 0,
|
|
1070
|
-
interruptingToolNames:
|
|
1155
|
+
interruptingToolNames: effectiveInterruptingToolNames,
|
|
1071
1156
|
maxContextTokens: agentContext?.maxContextTokens,
|
|
1072
1157
|
maxToolResultChars: agentContext?.maxToolResultChars,
|
|
1073
1158
|
toolOutputRegistry: this.getOrCreateToolOutputRegistry(),
|
|
@@ -1095,7 +1180,7 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1095
1180
|
sessions: this.sessions,
|
|
1096
1181
|
toolExecution: this.toolExecution,
|
|
1097
1182
|
codeSessionToolNames: this.codeSessionToolNames,
|
|
1098
|
-
interruptingToolNames:
|
|
1183
|
+
interruptingToolNames: effectiveInterruptingToolNames,
|
|
1099
1184
|
hookRegistry: this.hookRegistry,
|
|
1100
1185
|
humanInTheLoop: this.humanInTheLoop,
|
|
1101
1186
|
maxContextTokens: agentContext?.maxContextTokens,
|
|
@@ -2341,6 +2426,8 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2341
2426
|
tokenCounter: agentContext.tokenCounter,
|
|
2342
2427
|
usageSink: this.subagentUsageSink,
|
|
2343
2428
|
streamLimits: this.streamLimits,
|
|
2429
|
+
humanInTheLoop: this.humanInTheLoop,
|
|
2430
|
+
checkpointer: this.compileOptions?.checkpointer,
|
|
2344
2431
|
maxDepth: effectiveSubagentDepth,
|
|
2345
2432
|
createChildGraph: (input) => {
|
|
2346
2433
|
const childGraph = new StandardGraph(input);
|
|
@@ -2350,12 +2437,8 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2350
2437
|
}
|
|
2351
2438
|
const toolHandlerRegistry = createToolHandlerRegistry(getParentHandlerRegistry());
|
|
2352
2439
|
childGraph.hookRegistry = this.hookRegistry;
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
* nested subagent interrupts need a stable child checkpoint and
|
|
2356
|
-
* resume bridge. Child hooks still fire; `ask` decisions fail
|
|
2357
|
-
* closed inside the subagent until that flow is implemented.
|
|
2358
|
-
*/
|
|
2440
|
+
childGraph.humanInTheLoop = this.humanInTheLoop;
|
|
2441
|
+
if (this.humanInTheLoop?.enabled === true) childGraph.compileOptions = { checkpointer: this.compileOptions?.checkpointer };
|
|
2359
2442
|
childGraph.toolOutputReferences = this.toolOutputReferences;
|
|
2360
2443
|
childGraph.eagerEventToolExecution = this.eagerEventToolExecution;
|
|
2361
2444
|
childGraph.codeSessionToolNames = this.codeSessionToolNames;
|
|
@@ -2366,24 +2449,19 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2366
2449
|
return childGraph;
|
|
2367
2450
|
}
|
|
2368
2451
|
});
|
|
2452
|
+
this.registerSubagentExecutor(executor);
|
|
2369
2453
|
const subagentTool = (0, _langchain_core_tools.tool)(async (rawInput, config) => {
|
|
2370
2454
|
const input = rawInput;
|
|
2371
2455
|
const description = typeof input.description === "string" && input.description.trim().length > 0 ? input.description : "No task description provided";
|
|
2372
2456
|
const subagentType = typeof input.subagent_type === "string" ? input.subagent_type : "";
|
|
2373
2457
|
const threadId = config.configurable?.thread_id;
|
|
2374
|
-
/**
|
|
2375
|
-
*
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
* temporal heuristics needed. If a future LangChain version
|
|
2382
|
-
* changes the threading, the type-guarded read falls back to
|
|
2383
|
-
* `undefined` and the correlation degrades gracefully.
|
|
2384
|
-
*/
|
|
2385
|
-
const toolCall = config.toolCall;
|
|
2386
|
-
const parentToolCallId = typeof toolCall?.id === "string" ? toolCall.id : void 0;
|
|
2458
|
+
/** Surface the parent call id so child checkpoints, interrupts, and
|
|
2459
|
+
* update events remain correlated across replay and resume. */
|
|
2460
|
+
const toolRuntime = config;
|
|
2461
|
+
const toolCall = toolRuntime.toolCall;
|
|
2462
|
+
let parentToolCallId;
|
|
2463
|
+
if (typeof toolRuntime.toolCallId === "string" && toolRuntime.toolCallId !== "") parentToolCallId = toolRuntime.toolCallId;
|
|
2464
|
+
else if (typeof toolCall?.id === "string" && toolCall.id !== "") parentToolCallId = toolCall.id;
|
|
2387
2465
|
/** The parent tool batch's entry-captured scope (stamped by
|
|
2388
2466
|
* ToolNode before PreToolUse hooks) — binds this child to the
|
|
2389
2467
|
* run that dispatched it, not to whatever controller a reset
|
|
@@ -2404,6 +2482,12 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2404
2482
|
parentConfigurable: config.configurable
|
|
2405
2483
|
})).content;
|
|
2406
2484
|
}, require_SubagentTool.buildSubagentToolParams(resolvedConfigs));
|
|
2485
|
+
const replayableSubagentTool = subagentTool;
|
|
2486
|
+
replayableSubagentTool[require_SubagentReplay.SUBAGENT_REPLAY_CONTROLLER] = {
|
|
2487
|
+
getResumeManifest: (parentToolCallIds) => executor.getResumeManifest(parentToolCallIds),
|
|
2488
|
+
getSettledOutput: (call, config) => executor.getSettledToolOutput(call, config),
|
|
2489
|
+
persistSettledOutput: (call, config, output) => executor.persistSettledToolOutput(call, config, output)
|
|
2490
|
+
};
|
|
2407
2491
|
if (!agentContext.graphTools) agentContext.graphTools = [];
|
|
2408
2492
|
agentContext.graphTools.push(subagentTool);
|
|
2409
2493
|
/**
|
|
@@ -2556,7 +2640,7 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2556
2640
|
const agentNode = this.createAgentNode(this.defaultAgentId);
|
|
2557
2641
|
return new _langchain_langgraph.StateGraph(_langchain_langgraph.Annotation.Root({ messages: (0, _langchain_langgraph.Annotation)({
|
|
2558
2642
|
reducer: (a, b) => {
|
|
2559
|
-
if (!this.messages.length) this.startIndex = a.length + b.length;
|
|
2643
|
+
if (!this.messages.length && !this.hasRestoredCheckpointMessages) this.startIndex = a.length + b.length;
|
|
2560
2644
|
const result = require_reducer.messagesStateReducer(a, b);
|
|
2561
2645
|
this.messages = result;
|
|
2562
2646
|
return result;
|