@librechat/agents 4.1.1 → 4.2.0
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 +9 -1
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/common/constants.cjs +2 -0
- package/dist/cjs/common/constants.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +15 -12
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +1 -1
- package/dist/cjs/hitl/approvalReview.cjs +10 -2
- package/dist/cjs/hitl/approvalReview.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/defaults.cjs +12 -0
- package/dist/cjs/llm/anthropic/defaults.cjs.map +1 -0
- package/dist/cjs/llm/anthropic/index.cjs +6 -0
- package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +1 -1
- package/dist/cjs/llm/google/utils/common.cjs +1 -1
- package/dist/cjs/llm/init.cjs +5 -2
- package/dist/cjs/llm/init.cjs.map +1 -1
- package/dist/cjs/llm/invoke.cjs +17 -15
- package/dist/cjs/llm/invoke.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs +1 -1
- package/dist/cjs/llm/openai/utils/index.cjs.map +1 -1
- package/dist/cjs/llm/request.cjs +13 -0
- package/dist/cjs/llm/request.cjs.map +1 -1
- package/dist/cjs/llm/stream/chunkAdapters.cjs +2 -3
- package/dist/cjs/llm/stream/chunkAdapters.cjs.map +1 -1
- package/dist/cjs/llm/truncation.cjs +12 -2
- package/dist/cjs/llm/truncation.cjs.map +1 -1
- package/dist/cjs/main.cjs +7 -4
- package/dist/cjs/messages/core.cjs +1 -1
- package/dist/cjs/messages/format.cjs +1 -1
- package/dist/cjs/messages/index.cjs +1 -1
- package/dist/cjs/messages/prune.cjs +2 -2
- package/dist/cjs/messages/reasoningTypes.cjs +20 -0
- package/dist/cjs/messages/reasoningTypes.cjs.map +1 -1
- package/dist/cjs/messages/recency.cjs +68 -7
- package/dist/cjs/messages/recency.cjs.map +1 -1
- package/dist/cjs/run.cjs +135 -54
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/session/AgentSession.cjs +7 -10
- package/dist/cjs/session/AgentSession.cjs.map +1 -1
- package/dist/cjs/stream.cjs +3 -2
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/summarization/input.cjs +87 -0
- package/dist/cjs/summarization/input.cjs.map +1 -0
- package/dist/cjs/summarization/node.cjs +470 -135
- package/dist/cjs/summarization/node.cjs.map +1 -1
- package/dist/cjs/summarization/retry.cjs +172 -0
- package/dist/cjs/summarization/retry.cjs.map +1 -0
- package/dist/cjs/summarization/shared.cjs +6 -2
- package/dist/cjs/summarization/shared.cjs.map +1 -1
- package/dist/cjs/summarization/toolBudget.cjs +45 -0
- package/dist/cjs/summarization/toolBudget.cjs.map +1 -0
- package/dist/cjs/summarization/usage.cjs +70 -0
- package/dist/cjs/summarization/usage.cjs.map +1 -0
- package/dist/cjs/tools/ToolNode.cjs +46 -16
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/cloudflare/CloudflareBridgeRuntime.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +155 -18
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentReplay.cjs +6 -1
- package/dist/cjs/tools/subagent/SubagentReplay.cjs.map +1 -1
- package/dist/cjs/tools/subagent/childGraphConfig.cjs +2 -1
- package/dist/cjs/tools/subagent/childGraphConfig.cjs.map +1 -1
- package/dist/cjs/tools/toolBatchReplay.cjs +182 -6
- package/dist/cjs/tools/toolBatchReplay.cjs.map +1 -1
- package/dist/cjs/utils/errors.cjs +21 -0
- package/dist/cjs/utils/errors.cjs.map +1 -1
- package/dist/cjs/utils/index.cjs +1 -1
- package/dist/cjs/utils/schema.cjs +4 -6
- package/dist/cjs/utils/schema.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +9 -1
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/common/constants.mjs +2 -1
- package/dist/esm/common/constants.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +16 -13
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +1 -1
- package/dist/esm/hitl/approvalReview.mjs +10 -2
- package/dist/esm/hitl/approvalReview.mjs.map +1 -1
- package/dist/esm/llm/anthropic/defaults.mjs +12 -0
- package/dist/esm/llm/anthropic/defaults.mjs.map +1 -0
- package/dist/esm/llm/anthropic/index.mjs +6 -0
- package/dist/esm/llm/anthropic/index.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs +1 -1
- package/dist/esm/llm/google/utils/common.mjs +1 -1
- package/dist/esm/llm/init.mjs +5 -2
- package/dist/esm/llm/init.mjs.map +1 -1
- package/dist/esm/llm/invoke.mjs +18 -16
- package/dist/esm/llm/invoke.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +1 -1
- package/dist/esm/llm/openai/utils/index.mjs.map +1 -1
- package/dist/esm/llm/request.mjs +13 -1
- package/dist/esm/llm/request.mjs.map +1 -1
- package/dist/esm/llm/stream/chunkAdapters.mjs +2 -3
- package/dist/esm/llm/stream/chunkAdapters.mjs.map +1 -1
- package/dist/esm/llm/truncation.mjs +12 -3
- package/dist/esm/llm/truncation.mjs.map +1 -1
- package/dist/esm/main.mjs +8 -8
- package/dist/esm/messages/core.mjs +1 -1
- package/dist/esm/messages/format.mjs +1 -1
- package/dist/esm/messages/index.mjs +1 -1
- package/dist/esm/messages/prune.mjs +2 -2
- package/dist/esm/messages/reasoningTypes.mjs +19 -1
- package/dist/esm/messages/reasoningTypes.mjs.map +1 -1
- package/dist/esm/messages/recency.mjs +68 -8
- package/dist/esm/messages/recency.mjs.map +1 -1
- package/dist/esm/run.mjs +135 -54
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/session/AgentSession.mjs +7 -10
- package/dist/esm/session/AgentSession.mjs.map +1 -1
- package/dist/esm/stream.mjs +3 -2
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/summarization/input.mjs +84 -0
- package/dist/esm/summarization/input.mjs.map +1 -0
- package/dist/esm/summarization/node.mjs +469 -133
- package/dist/esm/summarization/node.mjs.map +1 -1
- package/dist/esm/summarization/retry.mjs +169 -0
- package/dist/esm/summarization/retry.mjs.map +1 -0
- package/dist/esm/summarization/shared.mjs +6 -2
- package/dist/esm/summarization/shared.mjs.map +1 -1
- package/dist/esm/summarization/toolBudget.mjs +45 -0
- package/dist/esm/summarization/toolBudget.mjs.map +1 -0
- package/dist/esm/summarization/usage.mjs +69 -0
- package/dist/esm/summarization/usage.mjs.map +1 -0
- package/dist/esm/tools/ToolNode.mjs +46 -16
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/cloudflare/CloudflareBridgeRuntime.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +156 -19
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentReplay.mjs +6 -1
- package/dist/esm/tools/subagent/SubagentReplay.mjs.map +1 -1
- package/dist/esm/tools/subagent/childGraphConfig.mjs +2 -1
- package/dist/esm/tools/subagent/childGraphConfig.mjs.map +1 -1
- package/dist/esm/tools/toolBatchReplay.mjs +178 -7
- package/dist/esm/tools/toolBatchReplay.mjs.map +1 -1
- package/dist/esm/utils/errors.mjs +21 -1
- package/dist/esm/utils/errors.mjs.map +1 -1
- package/dist/esm/utils/index.mjs +1 -1
- package/dist/esm/utils/schema.mjs +2 -4
- package/dist/esm/utils/schema.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +2 -0
- package/dist/types/common/constants.d.ts +2 -0
- package/dist/types/hitl/approvalReview.d.ts +1 -1
- package/dist/types/llm/anthropic/defaults.d.ts +11 -0
- package/dist/types/llm/init.d.ts +2 -1
- package/dist/types/llm/invoke.d.ts +8 -1
- package/dist/types/llm/request.d.ts +12 -0
- package/dist/types/llm/stream/chunkAdapters.d.ts +1 -1
- package/dist/types/llm/truncation.d.ts +2 -0
- package/dist/types/messages/reasoningTypes.d.ts +6 -0
- package/dist/types/messages/recency.d.ts +2 -0
- package/dist/types/run.d.ts +3 -0
- package/dist/types/summarization/input.d.ts +16 -0
- package/dist/types/summarization/node.d.ts +2 -1
- package/dist/types/summarization/retry.d.ts +22 -0
- package/dist/types/summarization/shared.d.ts +3 -3
- package/dist/types/summarization/toolBudget.d.ts +8 -0
- package/dist/types/summarization/usage.d.ts +9 -0
- package/dist/types/tools/subagent/SubagentReplay.d.ts +3 -1
- package/dist/types/tools/toolBatchReplay.d.ts +14 -1
- package/dist/types/types/graph.d.ts +2 -1
- package/dist/types/types/hitl.d.ts +2 -0
- package/dist/types/types/llm.d.ts +3 -0
- package/dist/types/types/run.d.ts +1 -1
- package/dist/types/types/summarize.d.ts +15 -3
- package/dist/types/utils/errors.d.ts +2 -0
- package/dist/types/utils/schema.d.ts +1 -1
- package/package.json +12 -6
- package/src/agents/AgentContext.ts +7 -0
- package/src/common/constants.ts +3 -0
- package/src/graphs/Graph.ts +16 -21
- package/src/hitl/approvalReview.ts +10 -2
- package/src/llm/anthropic/defaults.ts +22 -0
- package/src/llm/anthropic/index.ts +15 -2
- package/src/llm/init.ts +16 -2
- package/src/llm/invoke.ts +33 -14
- package/src/llm/openai/utils/index.ts +2 -4
- package/src/llm/request.ts +44 -0
- package/src/llm/stream/chunkAdapters.ts +14 -18
- package/src/llm/truncation.ts +33 -17
- package/src/messages/reasoningTypes.ts +71 -0
- package/src/messages/recency.ts +78 -0
- package/src/run.ts +190 -81
- package/src/session/AgentSession.ts +8 -11
- package/src/stream.ts +1 -0
- package/src/summarization/input.ts +98 -0
- package/src/summarization/node.ts +749 -356
- package/src/summarization/retry.ts +294 -0
- package/src/summarization/shared.ts +9 -2
- package/src/summarization/toolBudget.ts +87 -0
- package/src/summarization/usage.ts +117 -0
- package/src/tools/ToolNode.ts +84 -23
- package/src/tools/cloudflare/CloudflareBridgeRuntime.ts +2 -2
- package/src/tools/subagent/SubagentExecutor.ts +227 -32
- package/src/tools/subagent/SubagentReplay.ts +30 -1
- package/src/tools/subagent/childGraphConfig.ts +9 -2
- package/src/tools/toolBatchReplay.ts +237 -7
- package/src/types/graph.ts +2 -1
- package/src/types/hitl.ts +4 -0
- package/src/types/llm.ts +4 -0
- package/src/types/run.ts +6 -3
- package/src/types/summarize.ts +22 -3
- package/src/utils/errors.ts +45 -0
- package/src/utils/schema.ts +7 -11
package/src/tools/ToolNode.ts
CHANGED
|
@@ -55,7 +55,12 @@ import type { RunBreakerScope } from '@/llm/streamLimits';
|
|
|
55
55
|
import type * as t from '@/types';
|
|
56
56
|
import {
|
|
57
57
|
TOOL_BATCH_REPLAY_KEY,
|
|
58
|
+
TOOL_REPLAY_CONFIGS_KEY,
|
|
59
|
+
TOOL_PENDING_APPROVAL_KEY,
|
|
60
|
+
getCheckpointPendingApproval,
|
|
61
|
+
matchesToolReplayBatch,
|
|
58
62
|
getToolBatchReplayOwner,
|
|
63
|
+
getToolReplayConfig,
|
|
59
64
|
getToolBatchReplayScope,
|
|
60
65
|
attachToolBatchReplayState,
|
|
61
66
|
restoreToolBatchReplayState,
|
|
@@ -81,6 +86,13 @@ import {
|
|
|
81
86
|
serializeStructuredValueBounded,
|
|
82
87
|
serializeToolContentBounded,
|
|
83
88
|
} from '@/utils/toolContent';
|
|
89
|
+
import {
|
|
90
|
+
attachSubagentResumeManifest,
|
|
91
|
+
SUBAGENT_RESUME_MANIFEST_CONFIG_KEY,
|
|
92
|
+
SUBAGENT_RESUME_ATTEMPT_CONFIG_KEY,
|
|
93
|
+
SUBAGENT_PARENT_BATCH_CONFIG_KEY,
|
|
94
|
+
SUBAGENT_REPLAY_CONTROLLER,
|
|
95
|
+
} from '@/tools/subagent/SubagentReplay';
|
|
84
96
|
import {
|
|
85
97
|
getReviewedToolApproval,
|
|
86
98
|
getToolApprovalReviewEvidence,
|
|
@@ -96,11 +108,6 @@ import {
|
|
|
96
108
|
recordArgsEqual,
|
|
97
109
|
stableStringify,
|
|
98
110
|
} from '@/tools/eagerEventExecution';
|
|
99
|
-
import {
|
|
100
|
-
attachSubagentResumeManifest,
|
|
101
|
-
SUBAGENT_PARENT_BATCH_CONFIG_KEY,
|
|
102
|
-
SUBAGENT_REPLAY_CONTROLLER,
|
|
103
|
-
} from '@/tools/subagent/SubagentReplay';
|
|
104
111
|
import {
|
|
105
112
|
INTENT_ARG,
|
|
106
113
|
readOutcomeFields,
|
|
@@ -142,13 +149,23 @@ function stripToolApprovalReviewConfig(
|
|
|
142
149
|
if (
|
|
143
150
|
configurable == null ||
|
|
144
151
|
(!(TOOL_APPROVAL_REVIEW_CONFIG_KEY in configurable) &&
|
|
145
|
-
!(TOOL_BATCH_REPLAY_KEY in configurable)
|
|
152
|
+
!(TOOL_BATCH_REPLAY_KEY in configurable) &&
|
|
153
|
+
!(TOOL_REPLAY_CONFIGS_KEY in configurable) &&
|
|
154
|
+
!(TOOL_PENDING_APPROVAL_KEY in configurable) &&
|
|
155
|
+
!(SUBAGENT_RESUME_MANIFEST_CONFIG_KEY in configurable) &&
|
|
156
|
+
!(SUBAGENT_RESUME_ATTEMPT_CONFIG_KEY in configurable) &&
|
|
157
|
+
!(SUBAGENT_PARENT_BATCH_CONFIG_KEY in configurable))
|
|
146
158
|
) {
|
|
147
159
|
return configurable;
|
|
148
160
|
}
|
|
149
161
|
const {
|
|
150
162
|
[TOOL_APPROVAL_REVIEW_CONFIG_KEY]: _review,
|
|
151
163
|
[TOOL_BATCH_REPLAY_KEY]: _replay,
|
|
164
|
+
[TOOL_REPLAY_CONFIGS_KEY]: _configs,
|
|
165
|
+
[TOOL_PENDING_APPROVAL_KEY]: _pending,
|
|
166
|
+
[SUBAGENT_RESUME_MANIFEST_CONFIG_KEY]: _manifest,
|
|
167
|
+
[SUBAGENT_RESUME_ATTEMPT_CONFIG_KEY]: _attempt,
|
|
168
|
+
[SUBAGENT_PARENT_BATCH_CONFIG_KEY]: _parentBatch,
|
|
152
169
|
...rest
|
|
153
170
|
} = configurable;
|
|
154
171
|
return rest;
|
|
@@ -516,9 +533,24 @@ type AskEntry = {
|
|
|
516
533
|
*/
|
|
517
534
|
function buildToolApprovalInterruptPayload(
|
|
518
535
|
askEntries: ReadonlyArray<AskEntry>,
|
|
519
|
-
hookSessionId?: string
|
|
536
|
+
hookSessionId?: string,
|
|
537
|
+
executionContext?: t.SubagentExecutionContext,
|
|
538
|
+
executingAgentId?: string
|
|
520
539
|
): t.ToolApprovalInterruptPayload {
|
|
540
|
+
const leaf = executionContext?.ancestry[executionContext.ancestry.length - 1];
|
|
521
541
|
return {
|
|
542
|
+
...(leaf?.subagentKind === 'graph' &&
|
|
543
|
+
executingAgentId != null &&
|
|
544
|
+
executingAgentId !== ''
|
|
545
|
+
? {
|
|
546
|
+
subagent: {
|
|
547
|
+
run_id: leaf.subagentRunId,
|
|
548
|
+
agent_id: executingAgentId,
|
|
549
|
+
subagent_type: leaf.subagentType,
|
|
550
|
+
parent_tool_call_id: leaf.parentToolCallId,
|
|
551
|
+
},
|
|
552
|
+
}
|
|
553
|
+
: {}),
|
|
522
554
|
type: 'tool_approval',
|
|
523
555
|
...(hookSessionId == null || hookSessionId === ''
|
|
524
556
|
? {}
|
|
@@ -1046,6 +1078,7 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
|
|
|
1046
1078
|
config,
|
|
1047
1079
|
this.executingAgentId ?? this.agentId ?? ''
|
|
1048
1080
|
);
|
|
1081
|
+
config = getToolReplayConfig(config, replayOwner, activeReplayKey, assistantBatch?.message.id);
|
|
1049
1082
|
let reviewEvidence = getToolApprovalReviewEvidence(config);
|
|
1050
1083
|
const replayState = getToolBatchReplayState(config.configurable);
|
|
1051
1084
|
const ownsParentBatch =
|
|
@@ -1101,6 +1134,20 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
|
|
|
1101
1134
|
'Cannot verify the active tool approval resume — failing closed'
|
|
1102
1135
|
);
|
|
1103
1136
|
}
|
|
1137
|
+
const checkpointPending = getCheckpointPendingApproval(config);
|
|
1138
|
+
const pendingBatch = checkpointPending != null && (
|
|
1139
|
+
replayState?.records.some((record) => matchesToolReplayBatch(record.batch, activeReplayKey, assistantBatch?.message.id)) === true || ((replayState?.records.length ?? 0) === 0 &&
|
|
1140
|
+
assistantBatch?.message.tool_calls?.some((call) =>
|
|
1141
|
+
getReviewedToolApproval(checkpointPending.payload, call.id) != null
|
|
1142
|
+
) === true)
|
|
1143
|
+
);
|
|
1144
|
+
if (pendingBatch && checkpointPending.owner != null && checkpointPending.owner !== replayOwner && !isChildReplay) {
|
|
1145
|
+
throw new Error('Tool approval execution owner changed before resume — failing closed');
|
|
1146
|
+
}
|
|
1147
|
+
if (pendingBatch && checkpointPending.owner === replayOwner &&
|
|
1148
|
+
(replayState?.records.length ?? 0) > 0 && !ownsParentBatch) {
|
|
1149
|
+
throw new Error('Tool batch proposal changed before approval replay — failing closed');
|
|
1150
|
+
}
|
|
1104
1151
|
if (replayResumeStatus === 'stale') {
|
|
1105
1152
|
const configurable = { ...config.configurable };
|
|
1106
1153
|
clearStaleToolApprovalConfig(
|
|
@@ -1108,6 +1155,7 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
|
|
|
1108
1155
|
replayOwner,
|
|
1109
1156
|
activeReplayKey
|
|
1110
1157
|
);
|
|
1158
|
+
if (pendingBatch) configurable[TOOL_PENDING_APPROVAL_KEY] = checkpointPending;
|
|
1111
1159
|
config = {
|
|
1112
1160
|
...config,
|
|
1113
1161
|
configurable,
|
|
@@ -1581,6 +1629,9 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
|
|
|
1581
1629
|
this.executingAgentId ?? '',
|
|
1582
1630
|
this.agentId ?? '',
|
|
1583
1631
|
this.name,
|
|
1632
|
+
...(this.codeSessionKey === Constants.EXECUTE_CODE
|
|
1633
|
+
? []
|
|
1634
|
+
: [this.codeSessionKey]),
|
|
1584
1635
|
]),
|
|
1585
1636
|
toolUsageCounts: [...this.toolUsageCount].map(([toolName, count]) => ({
|
|
1586
1637
|
toolName,
|
|
@@ -2410,13 +2461,14 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
|
|
|
2410
2461
|
approvalReplaySessionId,
|
|
2411
2462
|
approvalReplayKey
|
|
2412
2463
|
);
|
|
2413
|
-
const
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
)
|
|
2419
|
-
|
|
2464
|
+
const replayOwner = getToolBatchReplayOwner(config, this.executingAgentId ?? this.agentId ?? '');
|
|
2465
|
+
const approvalReviewEvidence = getToolApprovalReviewEvidence(config, replayOwner);
|
|
2466
|
+
const checkpointPending = getCheckpointPendingApproval(config);
|
|
2467
|
+
if (approvalReviewEvidence == null && checkpointPending != null &&
|
|
2468
|
+
(checkpointPending.owner == null || checkpointPending.owner === replayOwner) &&
|
|
2469
|
+
getReviewedToolApproval(checkpointPending.payload, call.id) != null) {
|
|
2470
|
+
throw new GraphInterrupt([{ id: checkpointPending.interruptId, value: checkpointPending.value }]);
|
|
2471
|
+
}
|
|
2420
2472
|
const reviewedApproval = getReviewedToolApproval(
|
|
2421
2473
|
approvalReviewEvidence?.payload,
|
|
2422
2474
|
call.id
|
|
@@ -2733,7 +2785,9 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
|
|
|
2733
2785
|
reason: askReason,
|
|
2734
2786
|
allowedDecisions,
|
|
2735
2787
|
};
|
|
2736
|
-
const payload = buildToolApprovalInterruptPayload(
|
|
2788
|
+
const payload = buildToolApprovalInterruptPayload(
|
|
2789
|
+
[askEntry], runId, this.executionContext, this.executingAgentId
|
|
2790
|
+
);
|
|
2737
2791
|
const resumeValue = AsyncLocalStorageProviderSingleton.runWithConfig(
|
|
2738
2792
|
config,
|
|
2739
2793
|
() =>
|
|
@@ -3594,13 +3648,14 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
|
|
|
3594
3648
|
config,
|
|
3595
3649
|
runId
|
|
3596
3650
|
);
|
|
3597
|
-
const
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
)
|
|
3603
|
-
|
|
3651
|
+
const replayOwner = getToolBatchReplayOwner(config, this.executingAgentId ?? this.agentId ?? '');
|
|
3652
|
+
const approvalReviewEvidence = getToolApprovalReviewEvidence(config, replayOwner);
|
|
3653
|
+
const checkpointPending = getCheckpointPendingApproval(config);
|
|
3654
|
+
if (approvalReviewEvidence == null && checkpointPending != null &&
|
|
3655
|
+
(checkpointPending.owner == null || checkpointPending.owner === replayOwner) &&
|
|
3656
|
+
preToolCalls.some((entry) => getReviewedToolApproval(checkpointPending.payload, entry.call.id) != null)) {
|
|
3657
|
+
throw new GraphInterrupt([{ id: checkpointPending.interruptId, value: checkpointPending.value }]);
|
|
3658
|
+
}
|
|
3604
3659
|
const hasPendingApproval = preToolCalls.some(
|
|
3605
3660
|
(entry) =>
|
|
3606
3661
|
entry.call.id != null &&
|
|
@@ -3932,6 +3987,10 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
|
|
|
3932
3987
|
entry.call.id
|
|
3933
3988
|
);
|
|
3934
3989
|
if (reviewedApproval != null) {
|
|
3990
|
+
if (this.humanInTheLoop?.enabled !== true) {
|
|
3991
|
+
blockEntry(entry, 'Foreground tool approval is disabled');
|
|
3992
|
+
continue;
|
|
3993
|
+
}
|
|
3935
3994
|
if (hookResult.updatedInput == null) {
|
|
3936
3995
|
entry.args = this.coerceEventToolArgs(
|
|
3937
3996
|
entry.call.name,
|
|
@@ -3967,7 +4026,9 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
|
|
|
3967
4026
|
* consumed one-shot hooks replay their pending approval aggregate.
|
|
3968
4027
|
*/
|
|
3969
4028
|
if (askEntries.length > 0) {
|
|
3970
|
-
const payload = buildToolApprovalInterruptPayload(
|
|
4029
|
+
const payload = buildToolApprovalInterruptPayload(
|
|
4030
|
+
askEntries, runId, this.executionContext, this.executingAgentId
|
|
4031
|
+
);
|
|
3971
4032
|
|
|
3972
4033
|
/**
|
|
3973
4034
|
* `interrupt()` reads the current `RunnableConfig` from
|
|
@@ -157,7 +157,7 @@ function commandWithEnv(
|
|
|
157
157
|
|
|
158
158
|
async function collectReadableStream(
|
|
159
159
|
stream: ReadableStream<Uint8Array>
|
|
160
|
-
): Promise<Uint8Array
|
|
160
|
+
): Promise<ReturnType<typeof Uint8Array.from>> {
|
|
161
161
|
const reader = stream.getReader();
|
|
162
162
|
const chunks: Uint8Array[] = [];
|
|
163
163
|
let total = 0;
|
|
@@ -183,7 +183,7 @@ async function collectReadableStream(
|
|
|
183
183
|
async function normalizeWriteBody(
|
|
184
184
|
content: string | ReadableStream<Uint8Array>,
|
|
185
185
|
options?: { encoding?: string }
|
|
186
|
-
): Promise<Uint8Array
|
|
186
|
+
): Promise<ReturnType<typeof Uint8Array.from>> {
|
|
187
187
|
if (typeof content !== 'string') {
|
|
188
188
|
return collectReadableStream(content);
|
|
189
189
|
}
|
|
@@ -2,6 +2,7 @@ import { nanoid } from 'nanoid';
|
|
|
2
2
|
import { createHash } from 'crypto';
|
|
3
3
|
import { BaseCallbackHandler } from '@langchain/core/callbacks/base';
|
|
4
4
|
import { AsyncLocalStorageProviderSingleton } from '@langchain/core/singletons';
|
|
5
|
+
import { convertToOpenAITool, isLangChainTool } from '@langchain/core/utils/function_calling';
|
|
5
6
|
import {
|
|
6
7
|
AIMessage,
|
|
7
8
|
BaseMessage,
|
|
@@ -116,6 +117,13 @@ import {
|
|
|
116
117
|
SUBAGENT_RESUME_ATTEMPT_CONFIG_KEY,
|
|
117
118
|
SUBAGENT_RESUME_MANIFEST_CONFIG_KEY,
|
|
118
119
|
} from './SubagentReplay';
|
|
120
|
+
import {
|
|
121
|
+
TOOL_REPLAY_CONFIGS_KEY,
|
|
122
|
+
TOOL_PENDING_APPROVAL_KEY,
|
|
123
|
+
rebindToolBatchReplayPayload,
|
|
124
|
+
restoreToolReplayConfigs,
|
|
125
|
+
getPublicToolInterruptPayload,
|
|
126
|
+
} from '@/tools/toolBatchReplay';
|
|
119
127
|
import {
|
|
120
128
|
logSubagentResolutionFailure,
|
|
121
129
|
SubagentResolutionError,
|
|
@@ -128,11 +136,6 @@ import {
|
|
|
128
136
|
pickSubagentHostArgInput,
|
|
129
137
|
getSubagentHostArgsDigest,
|
|
130
138
|
} from './hostArgs';
|
|
131
|
-
import {
|
|
132
|
-
rebindToolBatchReplayScope,
|
|
133
|
-
rebindToolBatchReplayPayload,
|
|
134
|
-
restoreToolReplayConfig,
|
|
135
|
-
} from '@/tools/toolBatchReplay';
|
|
136
139
|
import {
|
|
137
140
|
executeHooks,
|
|
138
141
|
HookRegistry,
|
|
@@ -157,6 +160,7 @@ import {
|
|
|
157
160
|
createChildGraphPlan,
|
|
158
161
|
isGraphSubagentConfig,
|
|
159
162
|
} from './childGraphConfig';
|
|
163
|
+
import { cloneToolApprovalInterruptPayload } from '@/hitl/approvalReview';
|
|
160
164
|
import { ProviderTextProtectionError } from '@/protection/providerText';
|
|
161
165
|
import { stripRunStepResumeState } from '@/tools/runStepResume';
|
|
162
166
|
import { seedAgentInitialSessions } from '@/utils/toolSessions';
|
|
@@ -430,6 +434,152 @@ type SubagentCheckpointMarker = {
|
|
|
430
434
|
settledOutput?: PersistedToolOutput;
|
|
431
435
|
};
|
|
432
436
|
|
|
437
|
+
/** Hash serializable options; executable or opaque inputs require a host revision. */
|
|
438
|
+
function getRuntimeOptionsIdentity(
|
|
439
|
+
options: unknown
|
|
440
|
+
): { digest: string; requiresRevision: boolean } {
|
|
441
|
+
const hash = createHash('sha256');
|
|
442
|
+
const ancestors = new Set<object>();
|
|
443
|
+
let requiresRevision = false;
|
|
444
|
+
const opaque = (): void => {
|
|
445
|
+
requiresRevision = true;
|
|
446
|
+
hash.update('host-revision');
|
|
447
|
+
};
|
|
448
|
+
const visit = (value: unknown, depth: number): void => {
|
|
449
|
+
if (value == null) {
|
|
450
|
+
hash.update(value === null ? 'null' : 'undefined');
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
const kind = typeof value;
|
|
454
|
+
if (kind === 'string' || kind === 'boolean' || (kind === 'number' && Number.isFinite(value))) {
|
|
455
|
+
hash.update(`${kind}:${JSON.stringify(value)};`);
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
if (kind !== 'object') {
|
|
459
|
+
opaque();
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
const object = value as object;
|
|
463
|
+
if (depth >= 64 || ancestors.has(object)) {
|
|
464
|
+
opaque();
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
const prototype = Object.getPrototypeOf(object);
|
|
468
|
+
if (prototype !== Object.prototype && prototype !== null &&
|
|
469
|
+
!(Array.isArray(value) && prototype === Array.prototype)) {
|
|
470
|
+
opaque();
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
ancestors.add(object);
|
|
474
|
+
if (Object.getOwnPropertySymbols(object).length > 0) opaque();
|
|
475
|
+
if (Array.isArray(value)) {
|
|
476
|
+
hash.update('[');
|
|
477
|
+
for (let index = 0; index < value.length; index++) {
|
|
478
|
+
const property = Object.getOwnPropertyDescriptor(value, String(index));
|
|
479
|
+
if (property?.get != null || property?.set != null) opaque();
|
|
480
|
+
else visit(property?.value, depth + 1);
|
|
481
|
+
}
|
|
482
|
+
hash.update(']');
|
|
483
|
+
} else {
|
|
484
|
+
hash.update('{');
|
|
485
|
+
const descriptors = Object.getOwnPropertyDescriptors(object);
|
|
486
|
+
for (const key of Object.keys(descriptors).sort()) {
|
|
487
|
+
const property = descriptors[key];
|
|
488
|
+
if (property.enumerable !== true) continue;
|
|
489
|
+
if ('value' in property && property.value === undefined) continue;
|
|
490
|
+
hash.update(`${JSON.stringify(key)}:`);
|
|
491
|
+
if (property.get != null || property.set != null) opaque();
|
|
492
|
+
else visit(property.value, depth + 1);
|
|
493
|
+
}
|
|
494
|
+
hash.update('}');
|
|
495
|
+
}
|
|
496
|
+
ancestors.delete(object);
|
|
497
|
+
};
|
|
498
|
+
visit(options, 0);
|
|
499
|
+
return { digest: hash.digest('hex'), requiresRevision };
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
const MEMBER_IDENTITY_EXCLUSIONS = new Set([
|
|
503
|
+
'tools', 'toolMap', 'graphTools', 'toolRegistry', 'toolDefinitions',
|
|
504
|
+
'codeSessionKey', 'toolEnd', 'summarizeOnly', 'discoveredTools',
|
|
505
|
+
'initialSessions', 'initialSummary', 'subagentConfigs', 'maxSubagentDepth',
|
|
506
|
+
'langfuse',
|
|
507
|
+
]);
|
|
508
|
+
|
|
509
|
+
/** Sessions refresh on resume; scrubbed parent state and tracing are non-authoritative. */
|
|
510
|
+
function getMemberExecutionIdentity(
|
|
511
|
+
agent: AgentInputs
|
|
512
|
+
): ReturnType<typeof getRuntimeOptionsIdentity> {
|
|
513
|
+
const descriptors = Object.fromEntries(
|
|
514
|
+
Object.entries(Object.getOwnPropertyDescriptors(agent)).filter(
|
|
515
|
+
([key]) => !MEMBER_IDENTITY_EXCLUSIONS.has(key)
|
|
516
|
+
)
|
|
517
|
+
);
|
|
518
|
+
return getRuntimeOptionsIdentity(Object.defineProperties({}, descriptors));
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
function hasExecutableMemberTools(agent: AgentInputs): boolean {
|
|
522
|
+
return (agent.toolMap?.size ?? 0) > 0 ||
|
|
523
|
+
(agent.graphTools?.length ?? 0) > 0 ||
|
|
524
|
+
agent.tools?.some(isLangChainTool) === true;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/** Declarative graph identity plus the host's revision for executable implementations. */
|
|
528
|
+
function getSubagentDefinitionId(
|
|
529
|
+
config: ExecutableSubagentConfigEntry | undefined
|
|
530
|
+
): string | undefined {
|
|
531
|
+
if (!config || !isGraphSubagentConfig(config)) return config?.configId;
|
|
532
|
+
const declaration = {
|
|
533
|
+
revision: config.configId,
|
|
534
|
+
type: config.type,
|
|
535
|
+
maxTurns: config.maxTurns,
|
|
536
|
+
entry: config.entryAgentId,
|
|
537
|
+
result: config.resultAgentId,
|
|
538
|
+
edges: config.edges.map((edge) => ({
|
|
539
|
+
...edge,
|
|
540
|
+
prompt: typeof edge.prompt === 'function'
|
|
541
|
+
? { revision: config.configId }
|
|
542
|
+
: edge.prompt,
|
|
543
|
+
})),
|
|
544
|
+
members: config.agents.map((agent) => ({
|
|
545
|
+
id: agent.agentId,
|
|
546
|
+
provider: agent.provider,
|
|
547
|
+
codeSessionKey: agent.codeSessionKey ?? Constants.EXECUTE_CODE,
|
|
548
|
+
toolEnd: agent.toolEnd ?? false,
|
|
549
|
+
summarizeOnly: agent.summarizeOnly ?? false,
|
|
550
|
+
model: resolveClientOptionsModel(agent.clientOptions),
|
|
551
|
+
executionOptions: getMemberExecutionIdentity(agent).digest,
|
|
552
|
+
instructions: agent.instructions,
|
|
553
|
+
additionalInstructions: agent.additional_instructions,
|
|
554
|
+
maxContextTokens: agent.maxContextTokens,
|
|
555
|
+
discoveredTools: [...new Set(agent.discoveredTools ?? [])].sort(),
|
|
556
|
+
toolDefinitions: agent.toolDefinitions,
|
|
557
|
+
toolRegistry: Object.fromEntries(
|
|
558
|
+
Array.from(agent.toolRegistry ?? [], ([key, definition]) => [
|
|
559
|
+
key,
|
|
560
|
+
{
|
|
561
|
+
...definition,
|
|
562
|
+
allowed_callers: [
|
|
563
|
+
...new Set(definition.allowed_callers ?? ['direct']),
|
|
564
|
+
].sort(),
|
|
565
|
+
},
|
|
566
|
+
])
|
|
567
|
+
),
|
|
568
|
+
toolMap: Object.fromEntries(
|
|
569
|
+
Array.from(agent.toolMap ?? [], ([key, tool]) => [
|
|
570
|
+
key,
|
|
571
|
+
convertToOpenAITool(tool),
|
|
572
|
+
])
|
|
573
|
+
),
|
|
574
|
+
tools: agent.tools?.map(
|
|
575
|
+
(tool) => (isLangChainTool(tool) ? convertToOpenAITool(tool) : tool)
|
|
576
|
+
),
|
|
577
|
+
graphTools: agent.graphTools?.map((tool) => convertToOpenAITool(tool)),
|
|
578
|
+
})),
|
|
579
|
+
};
|
|
580
|
+
return `graph:${createHash('sha256').update(stableStringify(declaration)).digest('hex')}`;
|
|
581
|
+
}
|
|
582
|
+
|
|
433
583
|
function isResumeExecutionCompatible(
|
|
434
584
|
resumeExecution: SubagentResumeExecution | undefined,
|
|
435
585
|
subagentType: string | undefined,
|
|
@@ -442,7 +592,7 @@ function isResumeExecutionCompatible(
|
|
|
442
592
|
if (
|
|
443
593
|
subagentType == null ||
|
|
444
594
|
executableConfig == null ||
|
|
445
|
-
resumeExecution.configId !== executableConfig
|
|
595
|
+
resumeExecution.configId !== getSubagentDefinitionId(executableConfig)
|
|
446
596
|
) {
|
|
447
597
|
return false;
|
|
448
598
|
}
|
|
@@ -2051,6 +2201,19 @@ export class SubagentExecutor {
|
|
|
2051
2201
|
checkpoints,
|
|
2052
2202
|
graphState,
|
|
2053
2203
|
approvalReplays,
|
|
2204
|
+
...(activeRun == null
|
|
2205
|
+
? {}
|
|
2206
|
+
: {
|
|
2207
|
+
pendingInterruptIds: [...new Set(activeRun.pendingInterrupts.flatMap(
|
|
2208
|
+
(pending) => pending.id == null ? [] : [pending.id]
|
|
2209
|
+
))],
|
|
2210
|
+
pendingInterrupts: activeRun.pendingInterrupts.flatMap((pending) =>
|
|
2211
|
+
pending.id == null ? [] : [{
|
|
2212
|
+
interruptId: pending.id,
|
|
2213
|
+
payload: cloneToolApprovalInterruptPayload(getPublicToolInterruptPayload(pending.value)),
|
|
2214
|
+
}]
|
|
2215
|
+
),
|
|
2216
|
+
}),
|
|
2054
2217
|
...(descendant == null ? {} : { descendant }),
|
|
2055
2218
|
});
|
|
2056
2219
|
}
|
|
@@ -2321,7 +2484,7 @@ export class SubagentExecutor {
|
|
|
2321
2484
|
return undefined;
|
|
2322
2485
|
}
|
|
2323
2486
|
}
|
|
2324
|
-
const configId = executableConfig
|
|
2487
|
+
const configId = getSubagentDefinitionId(executableConfig);
|
|
2325
2488
|
const bound = this.bindExecutionDefinition(
|
|
2326
2489
|
execution,
|
|
2327
2490
|
{
|
|
@@ -2429,9 +2592,9 @@ export class SubagentExecutor {
|
|
|
2429
2592
|
const configId =
|
|
2430
2593
|
resolvedSubagentType == null
|
|
2431
2594
|
? (execution.binding?.configId ??
|
|
2432
|
-
executableConfig
|
|
2595
|
+
getSubagentDefinitionId(executableConfig) ??
|
|
2433
2596
|
resumeExecution?.configId)
|
|
2434
|
-
: executableConfig
|
|
2597
|
+
: getSubagentDefinitionId(executableConfig);
|
|
2435
2598
|
if (subagentType == null) {
|
|
2436
2599
|
return;
|
|
2437
2600
|
}
|
|
@@ -2586,22 +2749,50 @@ export class SubagentExecutor {
|
|
|
2586
2749
|
);
|
|
2587
2750
|
}
|
|
2588
2751
|
if (
|
|
2752
|
+
this.humanInTheLoop?.enabled === true &&
|
|
2753
|
+
(params.parentToolCallId == null || params.parentToolCallId === '')
|
|
2754
|
+
) {
|
|
2755
|
+
return Promise.resolve(
|
|
2756
|
+
createSubagentFailure(
|
|
2757
|
+
'Error: Resumable subagent execution requires a parent tool call ID.'
|
|
2758
|
+
)
|
|
2759
|
+
);
|
|
2760
|
+
}
|
|
2761
|
+
if (
|
|
2762
|
+
this.humanInTheLoop?.enabled === true &&
|
|
2589
2763
|
isGraphSubagentConfig(executableConfig) &&
|
|
2590
|
-
|
|
2764
|
+
executableConfig.configId == null &&
|
|
2765
|
+
executableConfig.edges.some((edge) => typeof edge.prompt === 'function')
|
|
2591
2766
|
) {
|
|
2592
2767
|
return Promise.resolve(
|
|
2593
2768
|
createSubagentFailure(
|
|
2594
|
-
'Error:
|
|
2769
|
+
'Error: Resumable graph subagents with functional prompts require a configId revision.'
|
|
2595
2770
|
)
|
|
2596
2771
|
);
|
|
2597
2772
|
}
|
|
2598
2773
|
if (
|
|
2599
2774
|
this.humanInTheLoop?.enabled === true &&
|
|
2600
|
-
(
|
|
2775
|
+
isGraphSubagentConfig(executableConfig) &&
|
|
2776
|
+
executableConfig.configId == null &&
|
|
2777
|
+
executableConfig.agents.some(
|
|
2778
|
+
(agent) => getMemberExecutionIdentity(agent).requiresRevision
|
|
2779
|
+
)
|
|
2601
2780
|
) {
|
|
2602
2781
|
return Promise.resolve(
|
|
2603
2782
|
createSubagentFailure(
|
|
2604
|
-
'Error: Resumable
|
|
2783
|
+
'Error: Resumable graph subagents with executable member options require a configId revision.'
|
|
2784
|
+
)
|
|
2785
|
+
);
|
|
2786
|
+
}
|
|
2787
|
+
if (
|
|
2788
|
+
this.humanInTheLoop?.enabled === true &&
|
|
2789
|
+
isGraphSubagentConfig(executableConfig) &&
|
|
2790
|
+
executableConfig.configId == null &&
|
|
2791
|
+
executableConfig.agents.some(hasExecutableMemberTools)
|
|
2792
|
+
) {
|
|
2793
|
+
return Promise.resolve(
|
|
2794
|
+
createSubagentFailure(
|
|
2795
|
+
'Error: Resumable graph subagents with executable member tools require a configId revision.'
|
|
2605
2796
|
)
|
|
2606
2797
|
);
|
|
2607
2798
|
}
|
|
@@ -2615,9 +2806,9 @@ export class SubagentExecutor {
|
|
|
2615
2806
|
{
|
|
2616
2807
|
description: params.description,
|
|
2617
2808
|
subagentType: params.subagentType,
|
|
2618
|
-
...(executableConfig
|
|
2809
|
+
...(getSubagentDefinitionId(executableConfig) == null
|
|
2619
2810
|
? {}
|
|
2620
|
-
: { configId: executableConfig
|
|
2811
|
+
: { configId: getSubagentDefinitionId(executableConfig) }),
|
|
2621
2812
|
...(hostArgsDigest == null ? {} : { hostArgsDigest }),
|
|
2622
2813
|
},
|
|
2623
2814
|
() =>
|
|
@@ -2792,9 +2983,9 @@ export class SubagentExecutor {
|
|
|
2792
2983
|
execution,
|
|
2793
2984
|
{
|
|
2794
2985
|
subagentType,
|
|
2795
|
-
...(executableConfig
|
|
2986
|
+
...(getSubagentDefinitionId(executableConfig) == null
|
|
2796
2987
|
? {}
|
|
2797
|
-
: { configId: executableConfig
|
|
2988
|
+
: { configId: getSubagentDefinitionId(executableConfig) }),
|
|
2798
2989
|
},
|
|
2799
2990
|
'effective'
|
|
2800
2991
|
);
|
|
@@ -2894,18 +3085,21 @@ export class SubagentExecutor {
|
|
|
2894
3085
|
)) {
|
|
2895
3086
|
const member = childPlan.memberInputs.get(agentId);
|
|
2896
3087
|
if (member == null) throw new Error('Unknown subagent context member.');
|
|
3088
|
+
member.codeSessionKey = sessions.codeSessionKey;
|
|
3089
|
+
member.initialSessions = sessions.initialSessions;
|
|
3090
|
+
}
|
|
3091
|
+
for (const member of childPlan.agents) {
|
|
2897
3092
|
const activeMember =
|
|
2898
|
-
execution.activeRun?.graph.agentContexts.get(agentId);
|
|
3093
|
+
execution.activeRun?.graph.agentContexts.get(member.agentId);
|
|
2899
3094
|
if (
|
|
2900
3095
|
activeMember != null &&
|
|
2901
|
-
activeMember.codeSessionKey
|
|
3096
|
+
(activeMember.codeSessionKey ?? Constants.EXECUTE_CODE) !==
|
|
3097
|
+
(member.codeSessionKey ?? Constants.EXECUTE_CODE)
|
|
2902
3098
|
) {
|
|
2903
3099
|
throw new Error(
|
|
2904
3100
|
'Subagent session partition changed during execution.'
|
|
2905
3101
|
);
|
|
2906
3102
|
}
|
|
2907
|
-
member.codeSessionKey = sessions.codeSessionKey;
|
|
2908
|
-
member.initialSessions = sessions.initialSessions;
|
|
2909
3103
|
}
|
|
2910
3104
|
} catch (error) {
|
|
2911
3105
|
if (childSignal.aborted) {
|
|
@@ -3014,7 +3208,6 @@ export class SubagentExecutor {
|
|
|
3014
3208
|
if (params.taskRuntime != null) {
|
|
3015
3209
|
childGraph.hookRegistry = this.hookRegistry;
|
|
3016
3210
|
}
|
|
3017
|
-
seedChildGraphSessions(childGraph, childPlan.agents);
|
|
3018
3211
|
let forwarding: ForwarderCallback | undefined;
|
|
3019
3212
|
if (forwardingEnabled) {
|
|
3020
3213
|
forwarding = this.createForwarderCallback({
|
|
@@ -3114,6 +3307,7 @@ export class SubagentExecutor {
|
|
|
3114
3307
|
currentHookSessionId
|
|
3115
3308
|
);
|
|
3116
3309
|
}
|
|
3310
|
+
seedChildGraphSessions(childGraph, childPlan.agents);
|
|
3117
3311
|
const childConfigurable: Record<string, unknown> = {
|
|
3118
3312
|
...inheritedConfigurable,
|
|
3119
3313
|
...sanitizePreparedConfigurable(preparedContext?.configurable),
|
|
@@ -3184,7 +3378,11 @@ export class SubagentExecutor {
|
|
|
3184
3378
|
checkpointMessages,
|
|
3185
3379
|
executionSuffix
|
|
3186
3380
|
);
|
|
3187
|
-
|
|
3381
|
+
const values = persistedState.values as MultiAgentGraphState;
|
|
3382
|
+
result = {
|
|
3383
|
+
messages: persistedMessages,
|
|
3384
|
+
...(childPlan.kind === 'graph' ? { subagentResult: values.subagentResult } : {}),
|
|
3385
|
+
};
|
|
3188
3386
|
recoveredComplete = true;
|
|
3189
3387
|
childAlreadyStarted = true;
|
|
3190
3388
|
childAlreadyCompleted = marker?.lifecycleComplete === true;
|
|
@@ -3205,18 +3403,13 @@ export class SubagentExecutor {
|
|
|
3205
3403
|
}
|
|
3206
3404
|
let childInput: BaseGraphState | Command | null;
|
|
3207
3405
|
if (childResumeMap != null) {
|
|
3208
|
-
|
|
3209
|
-
activeChildRun.pendingInterrupts.find(
|
|
3210
|
-
(entry) =>
|
|
3211
|
-
entry.id != null &&
|
|
3212
|
-
Object.prototype.hasOwnProperty.call(childResumeMap, entry.id)
|
|
3213
|
-
) ?? activeChildRun.pendingInterrupts[0];
|
|
3214
|
-
restoreToolReplayConfig(childConfigurable, pending.id, pending.value);
|
|
3215
|
-
rebindToolBatchReplayScope(
|
|
3406
|
+
restoreToolReplayConfigs(
|
|
3216
3407
|
childConfigurable,
|
|
3408
|
+
activeChildRun.pendingInterrupts,
|
|
3217
3409
|
resumeExecution?.approvalExecutionScope ?? approvalExecutionScope,
|
|
3218
3410
|
approvalExecutionScope,
|
|
3219
|
-
childThreadId
|
|
3411
|
+
childThreadId,
|
|
3412
|
+
new Set(Object.keys(childResumeMap))
|
|
3220
3413
|
);
|
|
3221
3414
|
childInput = new Command({ resume: childResumeMap });
|
|
3222
3415
|
} else if (recoveredInProgress) {
|
|
@@ -4108,6 +4301,8 @@ function isLangGraphRuntimeConfigKey(key: string): boolean {
|
|
|
4108
4301
|
key === SUBAGENT_RESUME_MANIFEST_CONFIG_KEY ||
|
|
4109
4302
|
key === SUBAGENT_PARENT_BATCH_CONFIG_KEY ||
|
|
4110
4303
|
key === TOOL_APPROVAL_EXECUTION_SCOPE_CONFIG_KEY ||
|
|
4304
|
+
key === TOOL_REPLAY_CONFIGS_KEY ||
|
|
4305
|
+
key === TOOL_PENDING_APPROVAL_KEY ||
|
|
4111
4306
|
/** The parent batch's breaker scope must not leak into the child
|
|
4112
4307
|
* workflow's configurable — children own separate controllers. */
|
|
4113
4308
|
key === RUN_BREAKER_SCOPE_CONFIG_KEY
|
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
FadingTier,
|
|
5
5
|
FadingTiers,
|
|
6
6
|
RunStepResumeState,
|
|
7
|
+
RunInterruptResult,
|
|
7
8
|
ToolSessionContext,
|
|
8
9
|
} from '@/types';
|
|
9
10
|
import type { ToolOutputReferenceState } from '@/tools/toolOutputReferences';
|
|
@@ -90,6 +91,10 @@ export interface SubagentResumeExecution {
|
|
|
90
91
|
checkpoints: SubagentCheckpointReference[];
|
|
91
92
|
graphState: SubagentGraphResumeState;
|
|
92
93
|
approvalReplays: ToolApprovalReplaySnapshot[];
|
|
94
|
+
pendingInterruptIds?: string[];
|
|
95
|
+
pendingInterrupts?: Array<
|
|
96
|
+
Pick<RunInterruptResult<unknown>, 'interruptId' | 'payload'>
|
|
97
|
+
>;
|
|
93
98
|
descendant?: SubagentResumeManifest;
|
|
94
99
|
}
|
|
95
100
|
|
|
@@ -345,6 +350,15 @@ function isGraphResumeState(value: unknown): value is SubagentGraphResumeState {
|
|
|
345
350
|
);
|
|
346
351
|
}
|
|
347
352
|
|
|
353
|
+
function isPendingInterrupt(
|
|
354
|
+
value: unknown
|
|
355
|
+
): value is NonNullable<SubagentResumeExecution['pendingInterrupts']>[number] {
|
|
356
|
+
if (value == null || typeof value !== 'object') return false;
|
|
357
|
+
const pending = value as Partial<RunInterruptResult<unknown>>;
|
|
358
|
+
return isString(pending.interruptId) &&
|
|
359
|
+
Object.prototype.hasOwnProperty.call(pending, 'payload');
|
|
360
|
+
}
|
|
361
|
+
|
|
348
362
|
function isSubagentResumeExecution(
|
|
349
363
|
value: unknown,
|
|
350
364
|
seen: Set<object>,
|
|
@@ -375,7 +389,22 @@ function isSubagentResumeExecution(
|
|
|
375
389
|
checkpoints.length === 0 ||
|
|
376
390
|
!checkpoints.every(isCheckpointReference) ||
|
|
377
391
|
!isGraphResumeState(graphState) ||
|
|
378
|
-
!Array.isArray(approvalReplays)
|
|
392
|
+
!Array.isArray(approvalReplays) ||
|
|
393
|
+
(execution.pendingInterruptIds != null &&
|
|
394
|
+
(!Array.isArray(execution.pendingInterruptIds) ||
|
|
395
|
+
!execution.pendingInterruptIds.every(isString) ||
|
|
396
|
+
new Set(execution.pendingInterruptIds).size !==
|
|
397
|
+
execution.pendingInterruptIds.length)) ||
|
|
398
|
+
(execution.pendingInterrupts != null &&
|
|
399
|
+
(!Array.isArray(execution.pendingInterrupts) ||
|
|
400
|
+
!execution.pendingInterrupts.every(isPendingInterrupt) ||
|
|
401
|
+
new Set(execution.pendingInterrupts.map((pending) => pending.interruptId)).size !==
|
|
402
|
+
execution.pendingInterrupts.length ||
|
|
403
|
+
(execution.pendingInterruptIds != null &&
|
|
404
|
+
(execution.pendingInterruptIds.length !== execution.pendingInterrupts.length ||
|
|
405
|
+
execution.pendingInterrupts.some(
|
|
406
|
+
(pending) => execution.pendingInterruptIds?.includes(pending.interruptId) !== true
|
|
407
|
+
)))))
|
|
379
408
|
) {
|
|
380
409
|
return false;
|
|
381
410
|
}
|