@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
package/dist/cjs/run.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const require_SubagentReplay = require("./tools/subagent/SubagentReplay.cjs");
|
|
1
2
|
const require_langfuseRuntimeContext = require("./langfuseRuntimeContext.cjs");
|
|
2
3
|
const require_langfuseConfig = require("./langfuseConfig.cjs");
|
|
3
4
|
const require_langfuseRuntimeScope = require("./langfuseRuntimeScope.cjs");
|
|
@@ -8,16 +9,16 @@ require("./common/index.cjs");
|
|
|
8
9
|
const require_activityLabel = require("./prompts/activityLabel.cjs");
|
|
9
10
|
const require_callbacks = require("./utils/callbacks.cjs");
|
|
10
11
|
const require_title = require("./utils/title.cjs");
|
|
12
|
+
const require_applyGraphRuntimeConfig = require("./graphs/applyGraphRuntimeConfig.cjs");
|
|
11
13
|
const require_tokens = require("./utils/tokens.cjs");
|
|
12
14
|
const require_instrumentation = require("./instrumentation.cjs");
|
|
13
15
|
const require_llm = require("./utils/llm.cjs");
|
|
14
|
-
const require_preempt = require("./llm/preempt.cjs");
|
|
15
16
|
const require_events = require("./events.cjs");
|
|
17
|
+
const require_preempt = require("./llm/preempt.cjs");
|
|
16
18
|
const require_init = require("./llm/init.cjs");
|
|
17
19
|
const require_executeHooks = require("./hooks/executeHooks.cjs");
|
|
18
20
|
require("./hooks/index.cjs");
|
|
19
|
-
const
|
|
20
|
-
const require_MultiAgentGraph = require("./graphs/MultiAgentGraph.cjs");
|
|
21
|
+
const require_createGraph = require("./graphs/createGraph.cjs");
|
|
21
22
|
let nanoid = require("nanoid");
|
|
22
23
|
let _langchain_core_prompts = require("@langchain/core/prompts");
|
|
23
24
|
let _langchain_core_runnables = require("@langchain/core/runnables");
|
|
@@ -69,6 +70,30 @@ function isLangGraphResumeMapForInterrupt(value, interruptId) {
|
|
|
69
70
|
if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
70
71
|
return Object.prototype.hasOwnProperty.call(value, interruptId);
|
|
71
72
|
}
|
|
73
|
+
function getInterruptHookSessionId(payload) {
|
|
74
|
+
const publicPayload = require_SubagentReplay.stripSubagentResumeManifest(payload);
|
|
75
|
+
if (publicPayload == null || typeof publicPayload !== "object" || publicPayload.type !== "tool_approval") return;
|
|
76
|
+
const sessionId = publicPayload.hook_session_id;
|
|
77
|
+
return typeof sessionId === "string" && sessionId.length > 0 ? sessionId : void 0;
|
|
78
|
+
}
|
|
79
|
+
function getFirstPersistedInterrupt(snapshot) {
|
|
80
|
+
for (const task of snapshot.tasks ?? []) for (const pendingInterrupt of task.interrupts ?? []) if (typeof pendingInterrupt.id === "string" && pendingInterrupt.id.length > 0) return {
|
|
81
|
+
id: pendingInterrupt.id,
|
|
82
|
+
value: pendingInterrupt.value
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function getPersistedMessages(snapshot) {
|
|
86
|
+
const messages = snapshot.values?.messages;
|
|
87
|
+
if (!Array.isArray(messages) || !messages.every(_langchain_core_messages.BaseMessage.isInstance)) return;
|
|
88
|
+
return messages;
|
|
89
|
+
}
|
|
90
|
+
function getResumeUpdateMessages(update) {
|
|
91
|
+
if (update == null) return;
|
|
92
|
+
const messages = Array.isArray(update) ? update.find(([key]) => key === "messages")?.[1] : update.messages;
|
|
93
|
+
if (_langchain_core_messages.BaseMessage.isInstance(messages)) return [messages];
|
|
94
|
+
if (!Array.isArray(messages) || !messages.every(_langchain_core_messages.BaseMessage.isInstance)) return;
|
|
95
|
+
return messages;
|
|
96
|
+
}
|
|
72
97
|
var Run = class Run {
|
|
73
98
|
id;
|
|
74
99
|
tokenCounter;
|
|
@@ -140,10 +165,7 @@ var Run = class Run {
|
|
|
140
165
|
} else {
|
|
141
166
|
/** Default to legacy graph for 'standard' or undefined type */
|
|
142
167
|
this.graphRunnable = this.createLegacyGraph(config.graphConfig);
|
|
143
|
-
if (this.Graph)
|
|
144
|
-
this.Graph.compileOptions = config.graphConfig.compileOptions ?? this.Graph.compileOptions;
|
|
145
|
-
this.Graph.handlerRegistry = handlerRegistry;
|
|
146
|
-
}
|
|
168
|
+
if (this.Graph) this.Graph.handlerRegistry = handlerRegistry;
|
|
147
169
|
}
|
|
148
170
|
if (config.initialSessions && this.Graph) for (const [key, value] of config.initialSessions) this.Graph.sessions.set(key, value);
|
|
149
171
|
this.returnContent = config.returnContent ?? false;
|
|
@@ -170,54 +192,64 @@ var Run = class Run {
|
|
|
170
192
|
};
|
|
171
193
|
signal = legacySignal;
|
|
172
194
|
}
|
|
173
|
-
const standardGraph =
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
195
|
+
const standardGraph = require_createGraph.createGraph({
|
|
196
|
+
kind: "standard",
|
|
197
|
+
input: {
|
|
198
|
+
signal,
|
|
199
|
+
runId: this.id,
|
|
200
|
+
agents: [agentConfig],
|
|
201
|
+
langfuse: this.langfuse,
|
|
202
|
+
tokenCounter: this.tokenCounter,
|
|
203
|
+
indexTokenCountMap: this.indexTokenCountMap,
|
|
204
|
+
calibrationRatio: this.calibrationRatio,
|
|
205
|
+
subagentUsageSink: this.subagentUsageSink,
|
|
206
|
+
preemption: this.preemption,
|
|
207
|
+
streamLimits: this.streamLimits
|
|
208
|
+
}
|
|
184
209
|
});
|
|
185
210
|
/** Propagate compile options from graph config */
|
|
186
211
|
standardGraph.compileOptions = this.applyHITLCheckpointerFallback(config.compileOptions);
|
|
187
212
|
this.hasCheckpointer = standardGraph.compileOptions?.checkpointer != null;
|
|
188
|
-
standardGraph
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
213
|
+
require_applyGraphRuntimeConfig.applyGraphRuntimeConfig(standardGraph, {
|
|
214
|
+
hookRegistry: this.hookRegistry,
|
|
215
|
+
humanInTheLoop: this.humanInTheLoop,
|
|
216
|
+
toolOutputReferences: this.toolOutputReferences,
|
|
217
|
+
eagerEventToolExecution: this.eagerEventToolExecution,
|
|
218
|
+
codeSessionToolNames: this.codeSessionToolNames,
|
|
219
|
+
interruptingToolNames: this.interruptingToolNames,
|
|
220
|
+
toolExecution: this.toolExecution
|
|
221
|
+
});
|
|
195
222
|
this.Graph = standardGraph;
|
|
196
223
|
return standardGraph.createWorkflow();
|
|
197
224
|
}
|
|
198
225
|
createMultiAgentGraph(config) {
|
|
199
226
|
const { agents, edges, compileOptions } = config;
|
|
200
|
-
const multiAgentGraph =
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
227
|
+
const multiAgentGraph = require_createGraph.createGraph({
|
|
228
|
+
kind: "multi-agent",
|
|
229
|
+
input: {
|
|
230
|
+
runId: this.id,
|
|
231
|
+
agents,
|
|
232
|
+
edges,
|
|
233
|
+
langfuse: this.langfuse,
|
|
234
|
+
tokenCounter: this.tokenCounter,
|
|
235
|
+
indexTokenCountMap: this.indexTokenCountMap,
|
|
236
|
+
calibrationRatio: this.calibrationRatio,
|
|
237
|
+
subagentUsageSink: this.subagentUsageSink,
|
|
238
|
+
preemption: this.preemption,
|
|
239
|
+
streamLimits: this.streamLimits
|
|
240
|
+
}
|
|
211
241
|
});
|
|
212
242
|
multiAgentGraph.compileOptions = this.applyHITLCheckpointerFallback(compileOptions);
|
|
213
243
|
this.hasCheckpointer = multiAgentGraph.compileOptions?.checkpointer != null;
|
|
214
|
-
multiAgentGraph
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
244
|
+
require_applyGraphRuntimeConfig.applyGraphRuntimeConfig(multiAgentGraph, {
|
|
245
|
+
hookRegistry: this.hookRegistry,
|
|
246
|
+
humanInTheLoop: this.humanInTheLoop,
|
|
247
|
+
toolOutputReferences: this.toolOutputReferences,
|
|
248
|
+
eagerEventToolExecution: this.eagerEventToolExecution,
|
|
249
|
+
codeSessionToolNames: this.codeSessionToolNames,
|
|
250
|
+
interruptingToolNames: this.interruptingToolNames,
|
|
251
|
+
toolExecution: this.toolExecution
|
|
252
|
+
});
|
|
221
253
|
this.Graph = multiAgentGraph;
|
|
222
254
|
return multiAgentGraph.createWorkflow();
|
|
223
255
|
}
|
|
@@ -380,6 +412,9 @@ var Run = class Run {
|
|
|
380
412
|
if (!this.Graph) throw new Error("Graph not initialized. Make sure to use Run.create() to instantiate the Run.");
|
|
381
413
|
return this.Graph.getRunMessages();
|
|
382
414
|
}
|
|
415
|
+
getChildCheckpointThreadIds() {
|
|
416
|
+
return this.Graph?.getChildCheckpointThreadIds() ?? [];
|
|
417
|
+
}
|
|
383
418
|
/**
|
|
384
419
|
* Returns a defensive snapshot of tools discovered by the current run.
|
|
385
420
|
* Pass an agent id for that context, or omit it for the ordered union across
|
|
@@ -498,6 +533,10 @@ var Run = class Run {
|
|
|
498
533
|
recursionLimit,
|
|
499
534
|
configurable: { ...callerConfig.configurable }
|
|
500
535
|
};
|
|
536
|
+
if (!isResume) {
|
|
537
|
+
delete config.configurable?.[require_SubagentReplay.SUBAGENT_RESUME_ATTEMPT_CONFIG_KEY];
|
|
538
|
+
delete config.configurable?.[require_SubagentReplay.SUBAGENT_RESUME_MANIFEST_CONFIG_KEY];
|
|
539
|
+
}
|
|
501
540
|
/**
|
|
502
541
|
* Cancellation can arrive either at graph construction or per-call through
|
|
503
542
|
* `callerConfig.signal`, and boundary hooks need to observe both — for a
|
|
@@ -855,7 +894,11 @@ var Run = class Run {
|
|
|
855
894
|
* fields.
|
|
856
895
|
*/
|
|
857
896
|
getInterrupt() {
|
|
858
|
-
|
|
897
|
+
if (this._interrupt == null) return;
|
|
898
|
+
return {
|
|
899
|
+
...this._interrupt,
|
|
900
|
+
payload: require_SubagentReplay.stripSubagentResumeManifest(this._interrupt.payload)
|
|
901
|
+
};
|
|
859
902
|
}
|
|
860
903
|
/**
|
|
861
904
|
* Returns the reason a hook halted the run via
|
|
@@ -926,29 +969,42 @@ var Run = class Run {
|
|
|
926
969
|
* tool-node resume). Intended for custom, Command-routed graphs.
|
|
927
970
|
*/
|
|
928
971
|
async resume(resumeValue, callerConfig, streamOptions, commandOptions) {
|
|
972
|
+
const resumeConfig = await this.resolveInterruptResumeConfig(callerConfig, commandOptions?.update);
|
|
929
973
|
const interruptId = this._interrupt?.interruptId;
|
|
930
974
|
const scopedResume = typeof interruptId === "string" && interruptId.length > 0 && !isLangGraphResumeMapForInterrupt(resumeValue, interruptId) ? { [interruptId]: resumeValue } : resumeValue;
|
|
931
|
-
const resumeConfig = await this.resolveInterruptResumeConfig(callerConfig);
|
|
932
975
|
return this.processStream(new _langchain_langgraph.Command({
|
|
933
976
|
resume: scopedResume,
|
|
934
977
|
...commandOptions?.update !== void 0 ? { update: commandOptions.update } : {},
|
|
935
978
|
...commandOptions?.goto !== void 0 ? { goto: commandOptions.goto } : {}
|
|
936
979
|
}), resumeConfig, streamOptions);
|
|
937
980
|
}
|
|
938
|
-
async resolveInterruptResumeConfig(callerConfig) {
|
|
981
|
+
async resolveInterruptResumeConfig(callerConfig, resumeUpdate) {
|
|
982
|
+
await this.restoreInterruptFromCheckpoint(callerConfig, resumeUpdate);
|
|
939
983
|
const interrupt = this._interrupt;
|
|
984
|
+
const resumeManifest = require_SubagentReplay.requireValidSubagentResumeManifest(interrupt?.payload);
|
|
985
|
+
const resumeConfigurable = { ...callerConfig.configurable };
|
|
986
|
+
delete resumeConfigurable[require_SubagentReplay.SUBAGENT_RESUME_ATTEMPT_CONFIG_KEY];
|
|
987
|
+
delete resumeConfigurable[require_SubagentReplay.SUBAGENT_RESUME_MANIFEST_CONFIG_KEY];
|
|
988
|
+
resumeConfigurable[require_SubagentReplay.SUBAGENT_RESUME_ATTEMPT_CONFIG_KEY] = (0, nanoid.nanoid)();
|
|
989
|
+
if (resumeManifest != null) resumeConfigurable[require_SubagentReplay.SUBAGENT_RESUME_MANIFEST_CONFIG_KEY] = resumeManifest;
|
|
990
|
+
const manifestConfig = {
|
|
991
|
+
...callerConfig,
|
|
992
|
+
configurable: resumeConfigurable
|
|
993
|
+
};
|
|
994
|
+
const hookSessionId = getInterruptHookSessionId(interrupt?.payload);
|
|
995
|
+
if (hookSessionId != null) this.hookRegistry?.copySession(hookSessionId, this.id);
|
|
940
996
|
const interruptId = interrupt?.interruptId;
|
|
941
997
|
const stateHistory = this.graphRunnable?.getStateHistory;
|
|
942
998
|
if (interrupt?.checkpointId != null && interrupt.checkpointId.length > 0) return {
|
|
943
|
-
...
|
|
999
|
+
...manifestConfig,
|
|
944
1000
|
configurable: {
|
|
945
|
-
...
|
|
1001
|
+
...manifestConfig.configurable,
|
|
946
1002
|
checkpoint_id: interrupt.checkpointId,
|
|
947
1003
|
...typeof interrupt.checkpointNs === "string" ? { checkpoint_ns: interrupt.checkpointNs } : {}
|
|
948
1004
|
}
|
|
949
1005
|
};
|
|
950
|
-
if (interrupt == null || typeof interruptId !== "string" || interruptId.length === 0 || typeof stateHistory !== "function") return
|
|
951
|
-
for await (const snapshot of stateHistory.call(this.graphRunnable,
|
|
1006
|
+
if (interrupt == null || typeof interruptId !== "string" || interruptId.length === 0 || typeof stateHistory !== "function") return manifestConfig;
|
|
1007
|
+
for await (const snapshot of stateHistory.call(this.graphRunnable, manifestConfig)) {
|
|
952
1008
|
const hasMatchingInterrupt = snapshot.tasks?.some((task) => task.interrupts?.some((interrupt) => interrupt.id === interruptId) === true) === true;
|
|
953
1009
|
const checkpointConfigurable = snapshot.config?.configurable;
|
|
954
1010
|
if (!hasMatchingInterrupt || checkpointConfigurable == null) continue;
|
|
@@ -961,16 +1017,37 @@ var Run = class Run {
|
|
|
961
1017
|
...typeof checkpointNs === "string" ? { checkpointNs } : {}
|
|
962
1018
|
};
|
|
963
1019
|
return {
|
|
964
|
-
...
|
|
1020
|
+
...manifestConfig,
|
|
965
1021
|
configurable: {
|
|
966
|
-
...
|
|
1022
|
+
...manifestConfig.configurable,
|
|
967
1023
|
checkpoint_id: checkpointId,
|
|
968
1024
|
...typeof checkpointNs === "string" ? { checkpoint_ns: checkpointNs } : {}
|
|
969
1025
|
}
|
|
970
1026
|
};
|
|
971
1027
|
}
|
|
972
1028
|
}
|
|
973
|
-
return
|
|
1029
|
+
return manifestConfig;
|
|
1030
|
+
}
|
|
1031
|
+
async restoreInterruptFromCheckpoint(callerConfig, resumeUpdate) {
|
|
1032
|
+
if (this._interrupt != null || this.humanInTheLoop?.enabled !== true) return;
|
|
1033
|
+
const workflow = this.graphRunnable;
|
|
1034
|
+
if (typeof workflow?.getState !== "function") return;
|
|
1035
|
+
const snapshot = await workflow.getState(callerConfig);
|
|
1036
|
+
const persistedInterrupt = getFirstPersistedInterrupt(snapshot);
|
|
1037
|
+
if (persistedInterrupt == null) return;
|
|
1038
|
+
const persistedMessages = getPersistedMessages(snapshot);
|
|
1039
|
+
if (persistedMessages != null) this.Graph?.restoreCheckpointMessages(persistedMessages, getResumeUpdateMessages(resumeUpdate));
|
|
1040
|
+
const checkpointConfigurable = snapshot.config?.configurable;
|
|
1041
|
+
const checkpointId = checkpointConfigurable?.checkpoint_id;
|
|
1042
|
+
const checkpointNs = checkpointConfigurable?.checkpoint_ns;
|
|
1043
|
+
const threadId = callerConfig.configurable?.thread_id;
|
|
1044
|
+
this._interrupt = {
|
|
1045
|
+
interruptId: persistedInterrupt.id,
|
|
1046
|
+
payload: persistedInterrupt.value,
|
|
1047
|
+
...typeof threadId === "string" ? { threadId } : {},
|
|
1048
|
+
...typeof checkpointId === "string" ? { checkpointId } : {},
|
|
1049
|
+
...typeof checkpointNs === "string" ? { checkpointNs } : {}
|
|
1050
|
+
};
|
|
974
1051
|
}
|
|
975
1052
|
createSystemCallback(clientCallbacks, key) {
|
|
976
1053
|
return ((...args) => {
|