@librechat/agents 3.4.0 → 3.4.2
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/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +165 -57
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +81 -33
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/graphs/applyGraphRuntimeConfig.cjs +14 -0
- package/dist/cjs/graphs/applyGraphRuntimeConfig.cjs.map +1 -0
- package/dist/cjs/graphs/createGraph.cjs +15 -0
- package/dist/cjs/graphs/createGraph.cjs.map +1 -0
- package/dist/cjs/graphs/index.cjs +1 -0
- package/dist/cjs/hooks/HookRegistry.cjs +83 -0
- package/dist/cjs/hooks/HookRegistry.cjs.map +1 -1
- package/dist/cjs/hooks/createWorkspacePolicyHook.cjs +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 +34 -24
- package/dist/cjs/messages/format.cjs +40 -23
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/cjs/run.cjs +130 -53
- 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/session/JsonlSessionStore.cjs +2 -2
- 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/SubagentTool.cjs +4 -4
- package/dist/cjs/tools/SubagentTool.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +321 -95
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/ToolSearch.cjs +1 -1
- package/dist/cjs/tools/eagerEventExecution.cjs +1 -0
- package/dist/cjs/tools/local/LocalExecutionEngine.cjs +3 -3
- package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs +2 -2
- package/dist/cjs/tools/search/rerankers.cjs +154 -1
- package/dist/cjs/tools/search/rerankers.cjs.map +1 -1
- package/dist/cjs/tools/search/tool.cjs +4 -1
- package/dist/cjs/tools/search/tool.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutionRegistry.cjs +601 -0
- package/dist/cjs/tools/subagent/SubagentExecutionRegistry.cjs.map +1 -0
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +1114 -233
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentReplay.cjs +177 -0
- package/dist/cjs/tools/subagent/SubagentReplay.cjs.map +1 -0
- package/dist/cjs/tools/subagent/childGraphConfig.cjs +278 -0
- package/dist/cjs/tools/subagent/childGraphConfig.cjs.map +1 -0
- package/dist/cjs/tools/subagent/index.cjs +1 -0
- package/dist/cjs/tools/subagent/runtimeLimits.cjs +5 -0
- package/dist/cjs/tools/subagent/runtimeLimits.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/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +165 -57
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +81 -33
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/graphs/applyGraphRuntimeConfig.mjs +14 -0
- package/dist/esm/graphs/applyGraphRuntimeConfig.mjs.map +1 -0
- package/dist/esm/graphs/createGraph.mjs +15 -0
- package/dist/esm/graphs/createGraph.mjs.map +1 -0
- package/dist/esm/graphs/index.mjs +1 -0
- package/dist/esm/hooks/HookRegistry.mjs +83 -0
- package/dist/esm/hooks/HookRegistry.mjs.map +1 -1
- package/dist/esm/hooks/createWorkspacePolicyHook.mjs +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 +21 -19
- package/dist/esm/messages/format.mjs +40 -23
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/esm/run.mjs +131 -54
- 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/session/JsonlSessionStore.mjs +2 -2
- 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/SubagentTool.mjs +4 -4
- package/dist/esm/tools/SubagentTool.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +322 -96
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/ToolSearch.mjs +1 -1
- package/dist/esm/tools/eagerEventExecution.mjs +1 -1
- package/dist/esm/tools/local/LocalExecutionEngine.mjs +3 -3
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs +2 -2
- package/dist/esm/tools/search/rerankers.mjs +154 -1
- package/dist/esm/tools/search/rerankers.mjs.map +1 -1
- package/dist/esm/tools/search/tool.mjs +4 -1
- package/dist/esm/tools/search/tool.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutionRegistry.mjs +597 -0
- package/dist/esm/tools/subagent/SubagentExecutionRegistry.mjs.map +1 -0
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +1114 -233
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentReplay.mjs +170 -0
- package/dist/esm/tools/subagent/SubagentReplay.mjs.map +1 -0
- package/dist/esm/tools/subagent/childGraphConfig.mjs +272 -0
- package/dist/esm/tools/subagent/childGraphConfig.mjs.map +1 -0
- package/dist/esm/tools/subagent/index.mjs +1 -0
- package/dist/esm/tools/subagent/runtimeLimits.mjs +5 -0
- package/dist/esm/tools/subagent/runtimeLimits.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/agents/AgentContext.d.ts +1 -1
- package/dist/types/graphs/Graph.d.ts +22 -2
- package/dist/types/graphs/MultiAgentGraph.d.ts +7 -1
- package/dist/types/graphs/applyGraphRuntimeConfig.d.ts +3 -0
- package/dist/types/graphs/createGraph.d.ts +13 -0
- package/dist/types/graphs/graphFactory.d.ts +13 -0
- package/dist/types/graphs/index.d.ts +2 -0
- 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 +6 -3
- package/dist/types/session/AgentSession.d.ts +1 -0
- package/dist/types/tools/SubagentTool.d.ts +1 -1
- package/dist/types/tools/ToolNode.d.ts +23 -15
- package/dist/types/tools/search/rerankers.d.ts +28 -0
- package/dist/types/tools/search/types.d.ts +38 -1
- package/dist/types/tools/subagent/SubagentExecutionRegistry.d.ts +171 -0
- package/dist/types/tools/subagent/SubagentExecutor.d.ts +70 -36
- package/dist/types/tools/subagent/SubagentReplay.d.ts +85 -0
- package/dist/types/tools/subagent/childGraphConfig.d.ts +37 -0
- package/dist/types/tools/subagent/index.d.ts +1 -1
- package/dist/types/tools/subagent/runtimeLimits.d.ts +4 -0
- package/dist/types/tools/toolOutputReferences.d.ts +12 -0
- package/dist/types/types/graph.d.ts +189 -24
- package/dist/types/types/hitl.d.ts +15 -0
- package/package.json +8 -2
- package/src/agents/AgentContext.ts +1 -1
- package/src/graphs/Graph.ts +349 -104
- package/src/graphs/MultiAgentGraph.ts +149 -47
- 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/graphs/__tests__/MultiAgentGraph.test.ts +86 -0
- package/src/graphs/__tests__/composition.smoke.test.ts +152 -0
- package/src/graphs/__tests__/createGraph.test.ts +206 -0
- package/src/graphs/applyGraphRuntimeConfig.ts +25 -0
- package/src/graphs/createGraph.ts +32 -0
- package/src/graphs/graphFactory.ts +12 -0
- package/src/graphs/index.ts +2 -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 +214 -56
- package/src/session/AgentSession.ts +52 -2
- package/src/session/__tests__/JsonlSessionStore.test.ts +53 -0
- package/src/specs/graph-subagent.live.test.ts +242 -0
- package/src/specs/graph-subagent.test.ts +322 -0
- package/src/specs/langfuse-routing.integration.test.ts +120 -1
- package/src/specs/subagent.test.ts +130 -4
- package/src/summarization/__tests__/node.test.ts +32 -14
- package/src/summarization/node.ts +15 -11
- package/src/tools/SubagentTool.ts +4 -4
- package/src/tools/ToolNode.ts +643 -157
- package/src/tools/__tests__/SubagentExecutor.test.ts +740 -15
- package/src/tools/__tests__/SubagentReplay.test.ts +329 -0
- package/src/tools/__tests__/ToolNode.breakerSignal.test.ts +208 -2
- package/src/tools/__tests__/directToolHITLResumeScope.test.ts +512 -2
- package/src/tools/__tests__/hitl.test.ts +234 -5
- package/src/tools/__tests__/subagentHooks.test.ts +1126 -61
- package/src/tools/__tests__/toolOutputReferences.test.ts +19 -2
- package/src/tools/search/rag-api-reranker.test.ts +891 -0
- package/src/tools/search/rerankers.ts +260 -0
- package/src/tools/search/tool.ts +6 -0
- package/src/tools/search/types.ts +45 -1
- package/src/tools/subagent/SubagentExecutionRegistry.ts +1159 -0
- package/src/tools/subagent/SubagentExecutor.ts +2232 -312
- package/src/tools/subagent/SubagentReplay.ts +584 -0
- package/src/tools/subagent/__tests__/SubagentExecutionRegistry.test.ts +637 -0
- package/src/tools/subagent/__tests__/SubagentExecutor.lazy.test.ts +3054 -0
- package/src/tools/subagent/__tests__/childGraphConfig.test.ts +521 -0
- package/src/tools/subagent/childGraphConfig.ts +694 -0
- package/src/tools/subagent/index.ts +6 -0
- package/src/tools/subagent/runtimeLimits.ts +7 -0
- package/src/tools/toolOutputReferences.ts +40 -1
- package/src/types/graph.ts +222 -24
- 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");
|
|
@@ -7,6 +8,7 @@ const require_enum = require("../common/enum.cjs");
|
|
|
7
8
|
require("../common/index.cjs");
|
|
8
9
|
const require_langfuseToolOutputTracing = require("../langfuseToolOutputTracing.cjs");
|
|
9
10
|
const require_callbacks = require("../utils/callbacks.cjs");
|
|
11
|
+
const require_applyGraphRuntimeConfig = require("./applyGraphRuntimeConfig.cjs");
|
|
10
12
|
const require_truncation = require("../utils/truncation.cjs");
|
|
11
13
|
const require_toolContent = require("../utils/toolContent.cjs");
|
|
12
14
|
const require_tokens = require("../utils/tokens.cjs");
|
|
@@ -27,30 +29,31 @@ const require_handoffCue = require("../messages/handoffCue.cjs");
|
|
|
27
29
|
const require_reducer = require("../messages/reducer.cjs");
|
|
28
30
|
const require_recency = require("../messages/recency.cjs");
|
|
29
31
|
require("../messages/index.cjs");
|
|
32
|
+
const require_graph = require("../utils/graph.cjs");
|
|
33
|
+
const require_llm = require("../utils/llm.cjs");
|
|
30
34
|
const require_handlers = require("../tools/handlers.cjs");
|
|
31
35
|
const require_streamLimits = require("../llm/streamLimits.cjs");
|
|
32
36
|
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
37
|
const require_events$1 = require("../events.cjs");
|
|
38
38
|
const require_run = require("../utils/run.cjs");
|
|
39
39
|
require("../utils/index.cjs");
|
|
40
|
+
const require_toolCache = require("../llm/bedrock/toolCache.cjs");
|
|
41
|
+
const require_preempt = require("../llm/preempt.cjs");
|
|
40
42
|
const require_init = require("../llm/init.cjs");
|
|
41
43
|
const require_invoke = require("../llm/invoke.cjs");
|
|
42
|
-
const require_contextOverflowRecovery = require("../llm/contextOverflowRecovery.cjs");
|
|
43
|
-
const require_toolCache$1 = require("../llm/openrouter/toolCache.cjs");
|
|
44
44
|
const require_executeHooks = require("../hooks/executeHooks.cjs");
|
|
45
45
|
require("../hooks/index.cjs");
|
|
46
|
+
const require_childGraphConfig = require("../tools/subagent/childGraphConfig.cjs");
|
|
47
|
+
const require_SubagentExecutor = require("../tools/subagent/SubagentExecutor.cjs");
|
|
48
|
+
require("../tools/subagent/index.cjs");
|
|
49
|
+
const require_contextOverflowRecovery = require("../llm/contextOverflowRecovery.cjs");
|
|
50
|
+
const require_toolCache$1 = require("../llm/openrouter/toolCache.cjs");
|
|
46
51
|
const require_LocalCodingTools = require("../tools/local/LocalCodingTools.cjs");
|
|
47
52
|
const require_CloudflareSandboxTools = require("../tools/cloudflare/CloudflareSandboxTools.cjs");
|
|
48
53
|
require("../tools/cloudflare/index.cjs");
|
|
49
54
|
const require_resolveLocalExecutionTools = require("../tools/local/resolveLocalExecutionTools.cjs");
|
|
50
55
|
require("../tools/local/index.cjs");
|
|
51
56
|
const require_ToolNode = require("../tools/ToolNode.cjs");
|
|
52
|
-
const require_SubagentExecutor = require("../tools/subagent/SubagentExecutor.cjs");
|
|
53
|
-
require("../tools/subagent/index.cjs");
|
|
54
57
|
const require_SubagentTool = require("../tools/SubagentTool.cjs");
|
|
55
58
|
const require_index$7 = require("../summarization/index.cjs");
|
|
56
59
|
const require_request = require("../llm/request.cjs");
|
|
@@ -72,11 +75,13 @@ const EMPTY_PREEMPT_BOUNDARY = {
|
|
|
72
75
|
};
|
|
73
76
|
/** Minimum relative variance before calibrated toolSchemaTokens overrides current value. */
|
|
74
77
|
const CALIBRATION_VARIANCE_THRESHOLD = .15;
|
|
75
|
-
function
|
|
78
|
+
function createChildHandlerRegistry(source) {
|
|
76
79
|
const toolHandler = source?.getHandler("on_tool_execute");
|
|
77
|
-
|
|
80
|
+
const updateHandler = source?.getHandler("on_subagent_update");
|
|
81
|
+
if (toolHandler == null && updateHandler == null) return;
|
|
78
82
|
const registry = new require_events$1.HandlerRegistry();
|
|
79
|
-
registry.register("on_tool_execute", toolHandler);
|
|
83
|
+
if (toolHandler != null) registry.register("on_tool_execute", toolHandler);
|
|
84
|
+
if (updateHandler != null) registry.register("on_subagent_update", updateHandler);
|
|
80
85
|
return registry;
|
|
81
86
|
}
|
|
82
87
|
function getHandlerDispatchedEventKey(eventName, stepId) {
|
|
@@ -262,6 +267,7 @@ function getDispatchableFinalReasoningContent({ agentContext, responseReasoningC
|
|
|
262
267
|
return responseReasoningContent;
|
|
263
268
|
}
|
|
264
269
|
var Graph = class {
|
|
270
|
+
restoreCheckpointMessages(_messages, _pendingMessages) {}
|
|
265
271
|
/** Returns a snapshot of deferred tools discovered by this graph. */
|
|
266
272
|
getDiscoveredTools(_agentId) {
|
|
267
273
|
return [];
|
|
@@ -419,7 +425,7 @@ var Graph = class {
|
|
|
419
425
|
this._toolOutputRegistry?.clear();
|
|
420
426
|
this._toolOutputRegistry = void 0;
|
|
421
427
|
for (const node of this._compiledToolNodes) node.clearDirectPathTurns();
|
|
422
|
-
this.
|
|
428
|
+
for (const executor of this._subagentExecutors) executor.clearHeavyState();
|
|
423
429
|
this.sessions.clear();
|
|
424
430
|
}
|
|
425
431
|
getEagerEventToolUsageCount(agentId) {
|
|
@@ -460,6 +466,73 @@ var Graph = class {
|
|
|
460
466
|
registerCompiledToolNode(node) {
|
|
461
467
|
this._compiledToolNodes.add(node);
|
|
462
468
|
}
|
|
469
|
+
registerSubagentExecutor(executor) {
|
|
470
|
+
this._subagentExecutors.add(executor);
|
|
471
|
+
}
|
|
472
|
+
resetSubagentCheckpointThreadIds() {
|
|
473
|
+
for (const executor of this._subagentExecutors) executor.resetCheckpointThreadIds();
|
|
474
|
+
}
|
|
475
|
+
getChildCheckpointThreadIds() {
|
|
476
|
+
const threadIds = /* @__PURE__ */ new Set();
|
|
477
|
+
for (const executor of this._subagentExecutors) for (const threadId of executor.getChildCheckpointThreadIds()) threadIds.add(threadId);
|
|
478
|
+
return [...threadIds];
|
|
479
|
+
}
|
|
480
|
+
createSubagentResumeState(runId) {
|
|
481
|
+
return {
|
|
482
|
+
toolCallSteps: [...this.toolCallStepIds].map(([toolCallId, stepId]) => ({
|
|
483
|
+
toolCallId,
|
|
484
|
+
stepId
|
|
485
|
+
})),
|
|
486
|
+
toolSessions: [...this.sessions].map(([toolName, context]) => ({
|
|
487
|
+
toolName,
|
|
488
|
+
context: {
|
|
489
|
+
...context,
|
|
490
|
+
...context.files == null ? {} : { files: context.files.map((file) => ({ ...file })) }
|
|
491
|
+
}
|
|
492
|
+
})),
|
|
493
|
+
toolNodes: [...this._compiledToolNodes].map((node) => node.createSubagentResumeState()),
|
|
494
|
+
eagerToolUsage: [{
|
|
495
|
+
agentId: "",
|
|
496
|
+
toolUsageCounts: [...this.eagerEventToolUsageCount].map(([toolName, count]) => ({
|
|
497
|
+
toolName,
|
|
498
|
+
count
|
|
499
|
+
}))
|
|
500
|
+
}, ...[...this.eagerEventToolUsageCountsByAgentId].map(([agentId, usageCounts]) => ({
|
|
501
|
+
agentId,
|
|
502
|
+
toolUsageCounts: [...usageCounts].map(([toolName, count]) => ({
|
|
503
|
+
toolName,
|
|
504
|
+
count
|
|
505
|
+
}))
|
|
506
|
+
}))],
|
|
507
|
+
eagerToolSuppressions: [...this.eagerEventToolSuppressions],
|
|
508
|
+
...this._toolOutputRegistry == null ? {} : { toolOutputReferences: this._toolOutputRegistry.snapshotState(runId) }
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
restoreSubagentResumeState(state, runId) {
|
|
512
|
+
const toolNodesByKey = new Map([...this._compiledToolNodes].map((node) => {
|
|
513
|
+
return [node.createSubagentResumeState().stateKey, node];
|
|
514
|
+
}));
|
|
515
|
+
if (toolNodesByKey.size !== state.toolNodes.length) throw new Error("Cannot restore changed subagent tool topology.");
|
|
516
|
+
for (const nodeState of state.toolNodes) if (!toolNodesByKey.has(nodeState.stateKey)) throw new Error(`Cannot restore subagent tool state for "${nodeState.stateKey}".`);
|
|
517
|
+
const registry = state.toolOutputReferences == null ? void 0 : this.getOrCreateToolOutputRegistry();
|
|
518
|
+
if (state.toolOutputReferences != null && registry == null) throw new Error("Cannot restore disabled tool output references.");
|
|
519
|
+
this.toolCallStepIds.clear();
|
|
520
|
+
for (const { toolCallId, stepId } of state.toolCallSteps) this.toolCallStepIds.set(toolCallId, stepId);
|
|
521
|
+
this.sessions.clear();
|
|
522
|
+
for (const { toolName, context } of state.toolSessions) this.sessions.set(toolName, {
|
|
523
|
+
...context,
|
|
524
|
+
...context.files == null ? {} : { files: context.files.map((file) => ({ ...file })) }
|
|
525
|
+
});
|
|
526
|
+
for (const nodeState of state.toolNodes) toolNodesByKey.get(nodeState.stateKey).restoreSubagentResumeState(nodeState);
|
|
527
|
+
this.clearEagerEventToolUsageCounts();
|
|
528
|
+
for (const usageState of state.eagerToolUsage) {
|
|
529
|
+
const usageCounts = this.getEagerEventToolUsageCount(usageState.agentId);
|
|
530
|
+
for (const { toolName, count } of usageState.toolUsageCounts) usageCounts.set(toolName, count);
|
|
531
|
+
}
|
|
532
|
+
this.eagerEventToolSuppressions.clear();
|
|
533
|
+
for (const toolName of state.eagerToolSuppressions) this.eagerEventToolSuppressions.add(toolName);
|
|
534
|
+
if (state.toolOutputReferences != null && registry != null) registry.restoreState(runId, state.toolOutputReferences);
|
|
535
|
+
}
|
|
463
536
|
/**
|
|
464
537
|
* Returns the shared `ToolOutputReferenceRegistry` for this run,
|
|
465
538
|
* constructing it on first access. Returns `undefined` when the
|
|
@@ -501,6 +574,7 @@ var Graph = class {
|
|
|
501
574
|
* across Runs if a provider reuses call ids (Codex P2 #33).
|
|
502
575
|
*/
|
|
503
576
|
_compiledToolNodes = /* @__PURE__ */ new Set();
|
|
577
|
+
_subagentExecutors = /* @__PURE__ */ new Set();
|
|
504
578
|
getOrCreateFileCheckpointer() {
|
|
505
579
|
if (this._fileCheckpointer != null) return this._fileCheckpointer;
|
|
506
580
|
if (this.toolExecution?.engine === "local" && this.toolExecution.local?.fileCheckpointing === true) {
|
|
@@ -518,11 +592,15 @@ var Graph = class {
|
|
|
518
592
|
var StandardGraph = class StandardGraph extends Graph {
|
|
519
593
|
overrideModel;
|
|
520
594
|
subagentModelOverride;
|
|
595
|
+
graphFactory;
|
|
596
|
+
supportsMultiAgentChildren;
|
|
521
597
|
/** Optional compile options passed into workflow.compile() */
|
|
522
598
|
compileOptions;
|
|
523
599
|
/** Whether the workflow was actually compiled with a checkpointer. */
|
|
524
600
|
hasCompiledCheckpointer = false;
|
|
525
601
|
messages = [];
|
|
602
|
+
/** Whether a rebuilt resume seeded the message baseline from its checkpoint. */
|
|
603
|
+
hasRestoredCheckpointMessages = false;
|
|
526
604
|
/** Cached run messages preserved before clearHeavyState() so getRunMessages() works after cleanup. */
|
|
527
605
|
cachedRunMessages;
|
|
528
606
|
/** Per-agent discovery snapshots preserved before contexts are reset on cleanup. */
|
|
@@ -564,6 +642,8 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
564
642
|
subagentUsageSink;
|
|
565
643
|
/** See {@link t.StandardGraphInput.subagentScope}. */
|
|
566
644
|
subagentScope;
|
|
645
|
+
/** See {@link t.StandardGraphInput.subagentExecutionContext}. */
|
|
646
|
+
subagentExecutionContext;
|
|
567
647
|
/** See {@link t.StandardGraphInput.preemption}. */
|
|
568
648
|
preemption;
|
|
569
649
|
/**
|
|
@@ -667,14 +747,20 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
667
747
|
* another's turn.
|
|
668
748
|
*/
|
|
669
749
|
pendingPreemptReturn = /* @__PURE__ */ new Set();
|
|
670
|
-
constructor({ runId, signal, agents, langfuse, tokenCounter, indexTokenCountMap, calibrationRatio, subagentUsageSink, subagentScope, preemption, streamLimits }) {
|
|
750
|
+
constructor({ runId, signal, agents, langfuse, tokenCounter, indexTokenCountMap, calibrationRatio, subagentUsageSink, subagentScope, subagentExecutionContext, preemption, streamLimits }, dependencies) {
|
|
671
751
|
super();
|
|
752
|
+
this.supportsMultiAgentChildren = dependencies != null;
|
|
753
|
+
this.graphFactory = dependencies?.graphFactory ?? ((request) => {
|
|
754
|
+
if (request.kind !== "standard") throw new Error("A polymorphic graph factory is required for multi-agent graph construction.");
|
|
755
|
+
return new StandardGraph(request.input);
|
|
756
|
+
});
|
|
672
757
|
this.runId = runId;
|
|
673
758
|
this.langfuseScopeRunId = `${runId ?? "graph"}:${(0, nanoid.nanoid)()}`;
|
|
674
759
|
this.signal = signal;
|
|
675
760
|
this.langfuse = langfuse;
|
|
676
761
|
this.subagentUsageSink = subagentUsageSink;
|
|
677
762
|
this.subagentScope = subagentScope === true;
|
|
763
|
+
this.subagentExecutionContext = subagentExecutionContext;
|
|
678
764
|
this.preemption = preemption;
|
|
679
765
|
this.streamLimits = require_streamLimits.resolveStreamLimits(streamLimits);
|
|
680
766
|
if (agents.length === 0) throw new Error("At least one agent configuration is required");
|
|
@@ -686,7 +772,9 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
686
772
|
this.defaultAgentId = agents[0].agentId;
|
|
687
773
|
}
|
|
688
774
|
resetValues(keepContent, checkpointScope) {
|
|
775
|
+
this.resetSubagentCheckpointThreadIds();
|
|
689
776
|
this.messages = [];
|
|
777
|
+
this.hasRestoredCheckpointMessages = false;
|
|
690
778
|
this.cachedRunMessages = void 0;
|
|
691
779
|
this.cachedDiscoveredTools = void 0;
|
|
692
780
|
this.config = require_graph.resetIfNotEmpty(this.config, void 0);
|
|
@@ -744,6 +832,14 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
744
832
|
for (const context of this.agentContexts.values()) context.reset({ preserveOriginalToolContent });
|
|
745
833
|
this.originalToolContentCheckpointScope = hasScopedCheckpoint ? checkpointScope : void 0;
|
|
746
834
|
}
|
|
835
|
+
/** Seeds the sidecar message view that checkpoint restoration bypasses. */
|
|
836
|
+
restoreCheckpointMessages(messages, pendingMessages) {
|
|
837
|
+
if (this.messages.length > 0) return;
|
|
838
|
+
this.messages = pendingMessages == null ? [...messages] : require_reducer.messagesStateReducer(messages, pendingMessages);
|
|
839
|
+
this.startIndex = this.messages.length;
|
|
840
|
+
this.hasRestoredCheckpointMessages = true;
|
|
841
|
+
this.cachedRunMessages = void 0;
|
|
842
|
+
}
|
|
747
843
|
clearHeavyState() {
|
|
748
844
|
this.cachedRunMessages = this.messages.slice(this.startIndex);
|
|
749
845
|
this.cachedDiscoveredTools = new Map(Array.from(this.agentContexts, ([agentId, context]) => [agentId, context.getDiscoveredTools()]));
|
|
@@ -1031,6 +1127,9 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1031
1127
|
runLangfuse: this.langfuse,
|
|
1032
1128
|
agentLangfuse: agentContext?.langfuse
|
|
1033
1129
|
});
|
|
1130
|
+
const interruptingToolNames = new Set(this.interruptingToolNames ?? []);
|
|
1131
|
+
if (this.humanInTheLoop?.enabled === true && (agentContext?.subagentConfigs?.length ?? 0) > 0) interruptingToolNames.add("subagent");
|
|
1132
|
+
const effectiveInterruptingToolNames = interruptingToolNames.size > 0 ? interruptingToolNames : void 0;
|
|
1034
1133
|
if (eventDrivenMode) {
|
|
1035
1134
|
const schemaTools = require_schema.createSchemaOnlyTools(toolDefinitions);
|
|
1036
1135
|
const toolDefMap = new Map(toolDefinitions.map((def) => [def.name, def]));
|
|
@@ -1067,7 +1166,7 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1067
1166
|
eagerEventToolSuppressions: this.eagerEventToolSuppressions,
|
|
1068
1167
|
toolExecution: this.toolExecution,
|
|
1069
1168
|
directToolNames: directToolNames.size > 0 ? directToolNames : void 0,
|
|
1070
|
-
interruptingToolNames:
|
|
1169
|
+
interruptingToolNames: effectiveInterruptingToolNames,
|
|
1071
1170
|
maxContextTokens: agentContext?.maxContextTokens,
|
|
1072
1171
|
maxToolResultChars: agentContext?.maxToolResultChars,
|
|
1073
1172
|
toolOutputRegistry: this.getOrCreateToolOutputRegistry(),
|
|
@@ -1095,7 +1194,7 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1095
1194
|
sessions: this.sessions,
|
|
1096
1195
|
toolExecution: this.toolExecution,
|
|
1097
1196
|
codeSessionToolNames: this.codeSessionToolNames,
|
|
1098
|
-
interruptingToolNames:
|
|
1197
|
+
interruptingToolNames: effectiveInterruptingToolNames,
|
|
1099
1198
|
hookRegistry: this.hookRegistry,
|
|
1100
1199
|
humanInTheLoop: this.humanInTheLoop,
|
|
1101
1200
|
maxContextTokens: agentContext?.maxContextTokens,
|
|
@@ -2323,11 +2422,33 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2323
2422
|
*/
|
|
2324
2423
|
const effectiveSubagentDepth = agentContext.maxSubagentDepth ?? 1;
|
|
2325
2424
|
if (agentContext.subagentConfigs != null && agentContext.subagentConfigs.length > 0 && effectiveSubagentDepth > 0) {
|
|
2326
|
-
const
|
|
2327
|
-
if (
|
|
2425
|
+
const executableConfigs = require_childGraphConfig.normalizeSubagentConfigEntries(agentContext.subagentConfigs, agentContext);
|
|
2426
|
+
if (executableConfigs.length > 0) {
|
|
2427
|
+
if (!this.supportsMultiAgentChildren && executableConfigs.some(require_childGraphConfig.isGraphSubagentConfig)) throw new Error("Graph subagents require constructing the parent with createGraph() or an injected GraphFactory dependency.");
|
|
2328
2428
|
const getParentHandlerRegistry = () => this.handlerRegistry ?? this.parentToolHandlerRegistry;
|
|
2429
|
+
const createConfiguredChildGraph = (request) => {
|
|
2430
|
+
const childGraph = this.graphFactory(request);
|
|
2431
|
+
if (this.subagentModelOverride != null) {
|
|
2432
|
+
childGraph.overrideModel = this.subagentModelOverride;
|
|
2433
|
+
childGraph.setSubagentModelOverride(this.subagentModelOverride);
|
|
2434
|
+
}
|
|
2435
|
+
const childHandlerRegistry = createChildHandlerRegistry(getParentHandlerRegistry());
|
|
2436
|
+
require_applyGraphRuntimeConfig.applyGraphRuntimeConfig(childGraph, {
|
|
2437
|
+
hookRegistry: this.hookRegistry,
|
|
2438
|
+
humanInTheLoop: this.humanInTheLoop,
|
|
2439
|
+
toolOutputReferences: this.toolOutputReferences,
|
|
2440
|
+
eagerEventToolExecution: this.eagerEventToolExecution,
|
|
2441
|
+
codeSessionToolNames: this.codeSessionToolNames,
|
|
2442
|
+
interruptingToolNames: this.interruptingToolNames,
|
|
2443
|
+
toolExecution: this.toolExecution
|
|
2444
|
+
});
|
|
2445
|
+
if (this.humanInTheLoop?.enabled === true) childGraph.compileOptions = { checkpointer: this.compileOptions?.checkpointer };
|
|
2446
|
+
childGraph.parentToolHandlerRegistry = childHandlerRegistry;
|
|
2447
|
+
childGraph.eventToolExecutionAvailable = childHandlerRegistry?.getHandler("on_tool_execute") != null;
|
|
2448
|
+
return childGraph;
|
|
2449
|
+
};
|
|
2329
2450
|
const executor = new require_SubagentExecutor.SubagentExecutor({
|
|
2330
|
-
configs: new Map(
|
|
2451
|
+
configs: new Map(executableConfigs.map((config) => [config.type, config])),
|
|
2331
2452
|
parentSignal: this.signal,
|
|
2332
2453
|
breakerScope: { controller: () => this.breakerAbort },
|
|
2333
2454
|
hookRegistry: this.hookRegistry,
|
|
@@ -2337,53 +2458,33 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2337
2458
|
parentHandlerRegistry: getParentHandlerRegistry,
|
|
2338
2459
|
parentRunId: this.runId ?? "",
|
|
2339
2460
|
parentAgentId: agentContext.agentId,
|
|
2461
|
+
executionContext: this.subagentExecutionContext,
|
|
2340
2462
|
langfuse: this.langfuse,
|
|
2341
2463
|
tokenCounter: agentContext.tokenCounter,
|
|
2342
2464
|
usageSink: this.subagentUsageSink,
|
|
2343
2465
|
streamLimits: this.streamLimits,
|
|
2466
|
+
humanInTheLoop: this.humanInTheLoop,
|
|
2467
|
+
checkpointer: this.compileOptions?.checkpointer,
|
|
2344
2468
|
maxDepth: effectiveSubagentDepth,
|
|
2345
|
-
createChildGraph: (input) => {
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
}
|
|
2351
|
-
const toolHandlerRegistry = createToolHandlerRegistry(getParentHandlerRegistry());
|
|
2352
|
-
childGraph.hookRegistry = this.hookRegistry;
|
|
2353
|
-
/**
|
|
2354
|
-
* Do not propagate `humanInTheLoop` into the child graph yet:
|
|
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
|
-
*/
|
|
2359
|
-
childGraph.toolOutputReferences = this.toolOutputReferences;
|
|
2360
|
-
childGraph.eagerEventToolExecution = this.eagerEventToolExecution;
|
|
2361
|
-
childGraph.codeSessionToolNames = this.codeSessionToolNames;
|
|
2362
|
-
childGraph.interruptingToolNames = this.interruptingToolNames;
|
|
2363
|
-
childGraph.toolExecution = this.toolExecution;
|
|
2364
|
-
childGraph.parentToolHandlerRegistry = toolHandlerRegistry;
|
|
2365
|
-
childGraph.eventToolExecutionAvailable = toolHandlerRegistry != null;
|
|
2366
|
-
return childGraph;
|
|
2367
|
-
}
|
|
2469
|
+
createChildGraph: (input) => createConfiguredChildGraph({
|
|
2470
|
+
kind: "standard",
|
|
2471
|
+
input
|
|
2472
|
+
}),
|
|
2473
|
+
createChildGraphByKind: createConfiguredChildGraph
|
|
2368
2474
|
});
|
|
2475
|
+
this.registerSubagentExecutor(executor);
|
|
2369
2476
|
const subagentTool = (0, _langchain_core_tools.tool)(async (rawInput, config) => {
|
|
2370
2477
|
const input = rawInput;
|
|
2371
|
-
const description = typeof input.description === "string" && input.description.trim().length > 0 ? input.description :
|
|
2478
|
+
const description = typeof input.description === "string" && input.description.trim().length > 0 ? input.description : require_SubagentExecutor.DEFAULT_SUBAGENT_DESCRIPTION;
|
|
2372
2479
|
const subagentType = typeof input.subagent_type === "string" ? input.subagent_type : "";
|
|
2373
2480
|
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;
|
|
2481
|
+
/** Surface the parent call id so child checkpoints, interrupts, and
|
|
2482
|
+
* update events remain correlated across replay and resume. */
|
|
2483
|
+
const toolRuntime = config;
|
|
2484
|
+
const toolCall = toolRuntime.toolCall;
|
|
2485
|
+
let parentToolCallId;
|
|
2486
|
+
if (typeof toolRuntime.toolCallId === "string" && toolRuntime.toolCallId !== "") parentToolCallId = toolRuntime.toolCallId;
|
|
2487
|
+
else if (typeof toolCall?.id === "string" && toolCall.id !== "") parentToolCallId = toolCall.id;
|
|
2387
2488
|
/** The parent tool batch's entry-captured scope (stamped by
|
|
2388
2489
|
* ToolNode before PreToolUse hooks) — binds this child to the
|
|
2389
2490
|
* run that dispatched it, not to whatever controller a reset
|
|
@@ -2393,6 +2494,7 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2393
2494
|
description,
|
|
2394
2495
|
subagentType,
|
|
2395
2496
|
threadId,
|
|
2497
|
+
signal: config.signal,
|
|
2396
2498
|
parentToolCallId,
|
|
2397
2499
|
breaker: batchScope?.controller,
|
|
2398
2500
|
/**
|
|
@@ -2403,7 +2505,13 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2403
2505
|
*/
|
|
2404
2506
|
parentConfigurable: config.configurable
|
|
2405
2507
|
})).content;
|
|
2406
|
-
}, require_SubagentTool.buildSubagentToolParams(
|
|
2508
|
+
}, require_SubagentTool.buildSubagentToolParams(executableConfigs));
|
|
2509
|
+
const replayableSubagentTool = subagentTool;
|
|
2510
|
+
replayableSubagentTool[require_SubagentReplay.SUBAGENT_REPLAY_CONTROLLER] = {
|
|
2511
|
+
getResumeManifest: (parentToolCallIds, config) => executor.getResumeManifest(parentToolCallIds, config),
|
|
2512
|
+
getSettledOutput: (call, config) => executor.getSettledToolOutput(call, config),
|
|
2513
|
+
persistSettledOutput: (call, config, output) => executor.persistSettledToolOutput(call, config, output)
|
|
2514
|
+
};
|
|
2407
2515
|
if (!agentContext.graphTools) agentContext.graphTools = [];
|
|
2408
2516
|
agentContext.graphTools.push(subagentTool);
|
|
2409
2517
|
/**
|
|
@@ -2556,7 +2664,7 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2556
2664
|
const agentNode = this.createAgentNode(this.defaultAgentId);
|
|
2557
2665
|
return new _langchain_langgraph.StateGraph(_langchain_langgraph.Annotation.Root({ messages: (0, _langchain_langgraph.Annotation)({
|
|
2558
2666
|
reducer: (a, b) => {
|
|
2559
|
-
if (!this.messages.length) this.startIndex = a.length + b.length;
|
|
2667
|
+
if (!this.messages.length && !this.hasRestoredCheckpointMessages) this.startIndex = a.length + b.length;
|
|
2560
2668
|
const result = require_reducer.messagesStateReducer(a, b);
|
|
2561
2669
|
this.messages = result;
|
|
2562
2670
|
return result;
|