@librechat/agents 3.8.4 → 3.8.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/agents/AgentContext.cjs +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 +18 -9
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/hitl/approvalReview.cjs +1 -1
- package/dist/cjs/hooks/types.cjs.map +1 -1
- package/dist/cjs/main.cjs +7 -6
- package/dist/cjs/messages/index.cjs +1 -1
- package/dist/cjs/messages/prune.cjs +1 -1
- package/dist/cjs/run.cjs +7 -3
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/stream.cjs +13 -3
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/summarization/node.cjs +3 -1
- package/dist/cjs/summarization/node.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +134 -32
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs +1 -0
- package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutionRegistry.cjs +0 -1
- package/dist/cjs/tools/subagent/SubagentExecutionRegistry.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +123 -29
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/cjs/tools/toolBatchReplay.cjs +65 -13
- package/dist/cjs/tools/toolBatchReplay.cjs.map +1 -1
- package/dist/cjs/utils/index.cjs +1 -1
- package/dist/esm/agents/AgentContext.mjs +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 +17 -8
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/hitl/approvalReview.mjs +1 -1
- package/dist/esm/hooks/types.mjs.map +1 -1
- package/dist/esm/main.mjs +6 -6
- package/dist/esm/messages/index.mjs +1 -1
- package/dist/esm/messages/prune.mjs +1 -1
- package/dist/esm/run.mjs +7 -3
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/stream.mjs +13 -3
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/summarization/node.mjs +3 -1
- package/dist/esm/summarization/node.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +135 -33
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs +1 -0
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutionRegistry.mjs +0 -1
- package/dist/esm/tools/subagent/SubagentExecutionRegistry.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +123 -29
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/esm/tools/toolBatchReplay.mjs +64 -13
- package/dist/esm/tools/toolBatchReplay.mjs.map +1 -1
- package/dist/esm/utils/index.mjs +1 -1
- package/dist/types/common/constants.d.ts +2 -0
- package/dist/types/graphs/Graph.d.ts +3 -2
- package/dist/types/hooks/types.d.ts +3 -0
- package/dist/types/run.d.ts +1 -0
- package/dist/types/summarization/node.d.ts +1 -0
- package/dist/types/tools/ToolNode.d.ts +4 -2
- package/dist/types/tools/subagent/SubagentExecutor.d.ts +7 -4
- package/dist/types/tools/toolBatchReplay.d.ts +6 -3
- package/dist/types/types/graph.d.ts +28 -0
- package/dist/types/types/run.d.ts +2 -0
- package/dist/types/types/tools.d.ts +11 -1
- package/package.json +1 -1
- package/src/common/constants.ts +3 -0
- package/src/graphs/Graph.ts +32 -18
- package/src/hooks/types.ts +3 -0
- package/src/run.ts +30 -15
- package/src/stream.ts +27 -5
- package/src/summarization/node.ts +3 -0
- package/src/tools/ToolNode.ts +528 -149
- package/src/tools/local/LocalProgrammaticToolCalling.ts +1 -0
- package/src/tools/subagent/SubagentExecutionRegistry.ts +0 -1
- package/src/tools/subagent/SubagentExecutor.ts +216 -48
- package/src/tools/toolBatchReplay.ts +121 -20
- package/src/types/graph.ts +37 -0
- package/src/types/run.ts +2 -0
- package/src/types/tools.ts +11 -1
- package/src/utils/llmConfig.ts +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { attachRunStepResumeState, getRunStepResumeState, stripRunStepResumeState } from "./runStepResume.mjs";
|
|
2
2
|
import { isToolNodeResumeState, isToolOutputReferenceState, requireValidSubagentResumeManifest, stripSubagentResumeManifest } from "./subagent/SubagentReplay.mjs";
|
|
3
3
|
import { isToolApprovalInterrupt } from "../types/hitl.mjs";
|
|
4
|
-
import { TOOL_APPROVAL_REVIEW_CONFIG_KEY, createToolApprovalReviewEvidence, getToolApprovalReviewEvidence } from "../hitl/approvalReview.mjs";
|
|
5
4
|
import "../hooks/types.mjs";
|
|
5
|
+
import { TOOL_APPROVAL_REVIEW_CONFIG_KEY, createToolApprovalReviewEvidence, getToolApprovalReviewEvidence } from "../hitl/approvalReview.mjs";
|
|
6
6
|
import { isBaseMessage } from "@langchain/core/messages";
|
|
7
7
|
import { Command, MemorySaver, isCommand } from "@langchain/langgraph";
|
|
8
8
|
//#region src/tools/toolBatchReplay.ts
|
|
@@ -13,10 +13,35 @@ const serializer = new MemorySaver().serde;
|
|
|
13
13
|
function isRecord(value) {
|
|
14
14
|
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
15
15
|
}
|
|
16
|
+
function bindLegacyReplayOwner(owner, configurable) {
|
|
17
|
+
let identity;
|
|
18
|
+
try {
|
|
19
|
+
identity = JSON.parse(owner);
|
|
20
|
+
} catch {
|
|
21
|
+
return owner;
|
|
22
|
+
}
|
|
23
|
+
if (!Array.isArray(identity) || identity.length !== 3) return owner;
|
|
24
|
+
return JSON.stringify([
|
|
25
|
+
...identity,
|
|
26
|
+
typeof configurable.user_id === "string" ? configurable.user_id : "",
|
|
27
|
+
typeof configurable.thread_id === "string" ? configurable.thread_id : ""
|
|
28
|
+
]);
|
|
29
|
+
}
|
|
30
|
+
function bindLegacyReplayState(state, configurable) {
|
|
31
|
+
if (state == null) return void 0;
|
|
32
|
+
return {
|
|
33
|
+
...state,
|
|
34
|
+
approvalOwner: state.approvalOwner == null ? void 0 : bindLegacyReplayOwner(state.approvalOwner, configurable),
|
|
35
|
+
records: state.records.map((record) => ({
|
|
36
|
+
...record,
|
|
37
|
+
owner: bindLegacyReplayOwner(record.owner, configurable)
|
|
38
|
+
}))
|
|
39
|
+
};
|
|
40
|
+
}
|
|
16
41
|
function restoreToolReplayConfig(configurable, interruptId, payload) {
|
|
17
42
|
delete configurable[TOOL_BATCH_REPLAY_KEY];
|
|
18
43
|
delete configurable[TOOL_APPROVAL_REVIEW_CONFIG_KEY];
|
|
19
|
-
const state = getToolBatchReplayState(payload);
|
|
44
|
+
const state = bindLegacyReplayState(getToolBatchReplayState(payload), configurable);
|
|
20
45
|
const publicPayload = getPublicToolInterruptPayload(payload);
|
|
21
46
|
const review = createToolApprovalReviewEvidence(interruptId, publicPayload, state?.approvalOwner);
|
|
22
47
|
if (isToolApprovalInterrupt(publicPayload) && (review == null || state != null && state.approvalOwner == null)) throw new Error("Invalid tool approval checkpoint");
|
|
@@ -26,20 +51,44 @@ function restoreToolReplayConfig(configurable, interruptId, payload) {
|
|
|
26
51
|
};
|
|
27
52
|
if (review != null) configurable[TOOL_APPROVAL_REVIEW_CONFIG_KEY] = review;
|
|
28
53
|
}
|
|
29
|
-
function
|
|
54
|
+
function getToolReplayResumeStatus(config, interruptId, isChildReplay) {
|
|
30
55
|
const resumeMap = config.configurable?.__pregel_resume_map;
|
|
31
|
-
if (interruptId != null && resumeMap != null && !Object.prototype.hasOwnProperty.call(resumeMap, interruptId)) return false;
|
|
32
|
-
if (isChildReplay && resumeMap != null) return true;
|
|
33
56
|
const scratchpad = config.configurable?.__pregel_scratchpad;
|
|
34
|
-
|
|
57
|
+
if (!isRecord(scratchpad) || !Array.isArray(scratchpad.resume)) return "unverifiable";
|
|
58
|
+
if (scratchpad.nullResume !== void 0) return "active";
|
|
59
|
+
const hasResume = scratchpad.resume.length > 0;
|
|
60
|
+
if (!isRecord(resumeMap)) return hasResume ? "unverifiable" : "stale";
|
|
61
|
+
if (interruptId == null) {
|
|
62
|
+
if (!hasResume) return "stale";
|
|
63
|
+
return Object.keys(resumeMap).length === 1 ? "active" : "unverifiable";
|
|
64
|
+
}
|
|
65
|
+
if (!Object.prototype.hasOwnProperty.call(resumeMap, interruptId)) return hasResume ? "unverifiable" : "stale";
|
|
66
|
+
if (isChildReplay) return "active";
|
|
67
|
+
return hasResume ? "active" : "stale";
|
|
35
68
|
}
|
|
36
69
|
function getToolBatchReplayOwner(config, agentId) {
|
|
37
70
|
return JSON.stringify([
|
|
38
71
|
getToolBatchReplayScope(config),
|
|
39
72
|
config.configurable?.["__librechat_tool_approval_execution_scope"] == null ? config.configurable?.checkpoint_ns ?? "" : "",
|
|
40
|
-
agentId
|
|
73
|
+
agentId,
|
|
74
|
+
typeof config.configurable?.user_id === "string" ? config.configurable.user_id : "",
|
|
75
|
+
typeof config.configurable?.thread_id === "string" ? config.configurable.thread_id : ""
|
|
41
76
|
]);
|
|
42
77
|
}
|
|
78
|
+
function clearStaleToolApprovalConfig(configurable, owner, batch) {
|
|
79
|
+
delete configurable[TOOL_APPROVAL_REVIEW_CONFIG_KEY];
|
|
80
|
+
const state = getToolBatchReplayState(configurable);
|
|
81
|
+
const records = batch == null ? [] : state?.records.filter((record) => record.owner === owner && record.batch === batch) ?? [];
|
|
82
|
+
if (state == null || records.length === 0) {
|
|
83
|
+
delete configurable[TOOL_BATCH_REPLAY_KEY];
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
configurable[TOOL_BATCH_REPLAY_KEY] = {
|
|
87
|
+
version: 1,
|
|
88
|
+
records,
|
|
89
|
+
wrappedPayload: state.wrappedPayload
|
|
90
|
+
};
|
|
91
|
+
}
|
|
43
92
|
function getToolBatchReplayScope(config) {
|
|
44
93
|
const scope = config.configurable?.["__librechat_tool_approval_execution_scope"] ?? config.configurable?.thread_id;
|
|
45
94
|
return typeof scope === "string" && scope.length > 0 ? scope : void 0;
|
|
@@ -48,7 +97,7 @@ function isChildToolReplayOwner(config, owner, trustedParentCallIds) {
|
|
|
48
97
|
const manifest = requireValidSubagentResumeManifest(config.configurable);
|
|
49
98
|
if (manifest == null || trustedParentCallIds.size === 0) return false;
|
|
50
99
|
const identity = JSON.parse(owner);
|
|
51
|
-
if (!Array.isArray(identity) || identity.length !== 3 || identity[1] !== "") return false;
|
|
100
|
+
if (!Array.isArray(identity) || identity.length !== 3 && identity.length !== 5 || identity[1] !== "") return false;
|
|
52
101
|
const pending = manifest.executions.filter((execution) => trustedParentCallIds.has(execution.parentToolCallId));
|
|
53
102
|
while (pending.length > 0) {
|
|
54
103
|
const execution = pending.pop();
|
|
@@ -57,11 +106,13 @@ function isChildToolReplayOwner(config, owner, trustedParentCallIds) {
|
|
|
57
106
|
}
|
|
58
107
|
return false;
|
|
59
108
|
}
|
|
60
|
-
function rebindToolBatchReplayScope(configurable, sourceScope, destinationScope) {
|
|
109
|
+
function rebindToolBatchReplayScope(configurable, sourceScope, destinationScope, destinationThreadId) {
|
|
61
110
|
const rebind = (key) => {
|
|
62
111
|
const parts = JSON.parse(key);
|
|
63
112
|
if (!Array.isArray(parts) || parts[0] !== sourceScope) return key;
|
|
64
|
-
|
|
113
|
+
const rebound = [destinationScope, ...parts.slice(1)];
|
|
114
|
+
if (rebound.length === 5 && destinationThreadId != null) rebound[4] = destinationThreadId;
|
|
115
|
+
return JSON.stringify(rebound);
|
|
65
116
|
};
|
|
66
117
|
const review = getToolApprovalReviewEvidence({ configurable });
|
|
67
118
|
if (review?.owner != null) configurable[TOOL_APPROVAL_REVIEW_CONFIG_KEY] = {
|
|
@@ -79,12 +130,12 @@ function rebindToolBatchReplayScope(configurable, sourceScope, destinationScope)
|
|
|
79
130
|
}))
|
|
80
131
|
};
|
|
81
132
|
}
|
|
82
|
-
function rebindToolBatchReplayPayload(payload, sourceScope, destinationScope) {
|
|
133
|
+
function rebindToolBatchReplayPayload(payload, sourceScope, destinationScope, destinationThreadId) {
|
|
83
134
|
const state = getToolBatchReplayState(payload);
|
|
84
135
|
const value = stripRunStepResumeState(payload);
|
|
85
136
|
if (state == null || !isRecord(value)) return payload;
|
|
86
137
|
const configurable = { [TOOL_BATCH_REPLAY_KEY]: state };
|
|
87
|
-
rebindToolBatchReplayScope(configurable, sourceScope, destinationScope);
|
|
138
|
+
rebindToolBatchReplayScope(configurable, sourceScope, destinationScope, destinationThreadId);
|
|
88
139
|
const rebound = {
|
|
89
140
|
...value,
|
|
90
141
|
[TOOL_BATCH_REPLAY_KEY]: configurable[TOOL_BATCH_REPLAY_KEY]
|
|
@@ -181,6 +232,6 @@ async function restoreToolBatchReplayState(config, owner) {
|
|
|
181
232
|
}));
|
|
182
233
|
}
|
|
183
234
|
//#endregion
|
|
184
|
-
export { TOOL_BATCH_REPLAY_KEY, attachToolBatchReplayState, getPublicToolInterruptPayload, getToolBatchReplayOwner, getToolBatchReplayScope, getToolBatchReplayState,
|
|
235
|
+
export { TOOL_BATCH_REPLAY_KEY, attachToolBatchReplayState, clearStaleToolApprovalConfig, getPublicToolInterruptPayload, getToolBatchReplayOwner, getToolBatchReplayScope, getToolBatchReplayState, getToolReplayResumeStatus, isChildToolReplayOwner, rebindToolBatchReplayPayload, rebindToolBatchReplayScope, restoreToolBatchReplayState, restoreToolReplayConfig, stripToolBatchReplayState };
|
|
185
236
|
|
|
186
237
|
//# sourceMappingURL=toolBatchReplay.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolBatchReplay.mjs","names":[],"sources":["../../../src/tools/toolBatchReplay.ts"],"mappings":";;;;;;;;AAyBA,MAAa,wBAAwB;AACrC,MAAM,yBAAyB;AAC/B,MAAM,yBAAyB;
|
|
1
|
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D,MAAM,IAAI,MAAM,oCAAoC;GAEtD,KAAK,IAAI,MAAM,EAAE;GACjB,MAAM,SAAS,UAAU,OAAO,MAAM,IAClC,IAAI,QAAQ;IACZ,QAAQ,OAAO,OAAO;IACtB,MAAM,OAAO,OAAO;IACpB,OAAO,OAAO,OAAO;IACrB,QAAQ,OAAO,OAAO;GACxB,CAAC,IACC,OAAO;GACX,OAAO,CACL,MAAM,IACN;IACE,GAAG;IACH,UAAU,OAAO;IACjB;IACA,oBAAoB,OAAO;GAC7B,CACF;EACF,CACF;EACA,OAAO;GACL,OAAO,OAAO;GACd;GACA,WAAW,OAAO;GAClB,gBAAgB,OAAO;EACzB;CACF,CAAC,CACL;AACF"}
|
package/dist/esm/utils/index.mjs
CHANGED
|
@@ -299,7 +299,8 @@ export declare class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode>
|
|
|
299
299
|
/** See {@link t.StandardGraphInput.subagentTasks}. */
|
|
300
300
|
subagentTasks: t.SubagentTaskConfig | undefined;
|
|
301
301
|
/** See {@link t.StandardGraphInput.subagentExecutionContext}. */
|
|
302
|
-
|
|
302
|
+
readonly subagentExecutionContext?: t.SubagentExecutionContext;
|
|
303
|
+
private readonly subagentContext?;
|
|
303
304
|
/** See {@link t.StandardGraphInput.preemption}. */
|
|
304
305
|
preemption?: t.StreamPreemption;
|
|
305
306
|
/**
|
|
@@ -436,7 +437,7 @@ export declare class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode>
|
|
|
436
437
|
* from a discard.
|
|
437
438
|
*/
|
|
438
439
|
private preemptRestartPending;
|
|
439
|
-
constructor({ runId, signal, agents, langfuse, tokenCounter, indexTokenCountMap, calibrationRatio, fadingTier, fadingTiers, subagentUsageSink, subagentTasks, subagentScope, subagentExecutionContext, preemption, streamLimits, toolExecution, }: t.StandardGraphInput, dependencies?: GraphFactoryDependencies);
|
|
440
|
+
constructor({ runId, signal, agents, langfuse, tokenCounter, indexTokenCountMap, calibrationRatio, fadingTier, fadingTiers, subagentUsageSink, subagentTasks, subagentScope, subagentExecutionContext, subagentContext, preemption, streamLimits, toolExecution, }: t.StandardGraphInput, dependencies?: GraphFactoryDependencies);
|
|
440
441
|
/**
|
|
441
442
|
* A compaction applies its remove-all inside the agent subgraph, so the
|
|
442
443
|
* subgraph's result carries only the retained tail, and an outer reducer
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { BaseMessage } from '@langchain/core/messages';
|
|
2
|
+
import type { SubagentExecutionContext } from '@/types/graph';
|
|
2
3
|
import type { InjectedMessage } from '@/types/tools';
|
|
3
4
|
/**
|
|
4
5
|
* Closed set of hook lifecycle events supported by the hooks system.
|
|
@@ -33,6 +34,8 @@ export type StopDecision = 'continue' | 'block';
|
|
|
33
34
|
* hook to a specific agent regardless of subagent scope.
|
|
34
35
|
*/
|
|
35
36
|
export interface BaseHookInput {
|
|
37
|
+
/** SDK-owned child lineage, including distinct identities for concurrent self-spawns. */
|
|
38
|
+
executionContext?: SubagentExecutionContext;
|
|
36
39
|
runId: string;
|
|
37
40
|
threadId?: string;
|
|
38
41
|
agentId?: string;
|
package/dist/types/run.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ interface CreateSummarizeNodeParams {
|
|
|
14
14
|
config?: RunnableConfig;
|
|
15
15
|
runId?: string;
|
|
16
16
|
isMultiAgent: boolean;
|
|
17
|
+
getSubagentExecutionContext?: () => t.SubagentExecutionContext | undefined;
|
|
17
18
|
hookRegistry?: HookRegistry;
|
|
18
19
|
getToolsForBinding?: (provider: t.ProviderName, clientOptions: t.ClientOptions | undefined) => t.GraphTools | undefined;
|
|
19
20
|
dispatchRunStep: (runStep: t.RunStep, config?: RunnableConfig) => Promise<void>;
|
|
@@ -161,6 +161,7 @@ export declare class ToolNode<T = any> extends RunnableCallable<T, T> {
|
|
|
161
161
|
* even where `agentId` (the subagent-scope marker) is undefined.
|
|
162
162
|
*/
|
|
163
163
|
private executingAgentId?;
|
|
164
|
+
private readonly executionContext?;
|
|
164
165
|
private executingAgentName?;
|
|
165
166
|
private rootAgentId?;
|
|
166
167
|
private rootAgentName?;
|
|
@@ -225,7 +226,7 @@ export declare class ToolNode<T = any> extends RunnableCallable<T, T> {
|
|
|
225
226
|
* other's in-flight state.
|
|
226
227
|
*/
|
|
227
228
|
private anonBatchCounter;
|
|
228
|
-
constructor({ tools, toolMap, name, tags, trace, runLangfuse, agentLangfuse, errorHandler, toolCallStepIds, handleToolErrors, loadRuntimeTools, toolRegistry, toolDefinitions, getDiscoveredToolNames, sessions, codeSessionKey, eventDrivenMode, eagerEventToolExecution, eagerEventToolExecutions, eagerEventToolUsageCount, eagerEventToolSuppressions, agentId, executingAgentId, executingAgentName, rootAgentId, rootAgentName, directToolNames, interruptingToolNames, codeSessionToolNames, maxContextTokens, maxToolResultChars, hookRegistry, humanInTheLoop, toolOutputReferences, toolOutputRegistry, toolExecution, fileCheckpointer, getBreakerSignal, getRunScope, preparedSubagents, restoreRunStepResumeState, createRunStepResumeState, }: t.ToolNodeConstructorParams);
|
|
229
|
+
constructor({ tools, toolMap, name, tags, trace, runLangfuse, agentLangfuse, errorHandler, toolCallStepIds, handleToolErrors, loadRuntimeTools, toolRegistry, toolDefinitions, getDiscoveredToolNames, sessions, codeSessionKey, eventDrivenMode, eagerEventToolExecution, eagerEventToolExecutions, eagerEventToolUsageCount, eagerEventToolSuppressions, agentId, executingAgentId, executionContext, executingAgentName, rootAgentId, rootAgentName, directToolNames, interruptingToolNames, codeSessionToolNames, maxContextTokens, maxToolResultChars, hookRegistry, humanInTheLoop, toolOutputReferences, toolOutputRegistry, toolExecution, fileCheckpointer, getBreakerSignal, getRunScope, preparedSubagents, restoreRunStepResumeState, createRunStepResumeState, }: t.ToolNodeConstructorParams);
|
|
229
230
|
invoke(input: any, options?: Partial<RunnableConfig>): Promise<any>;
|
|
230
231
|
private withToolScope;
|
|
231
232
|
/**
|
|
@@ -411,6 +412,7 @@ export declare class ToolNode<T = any> extends RunnableCallable<T, T> {
|
|
|
411
412
|
* paths derive the runtime session hint identically. */
|
|
412
413
|
private resolveRuntimeSessionHint;
|
|
413
414
|
private storeCodeSessionFromResults;
|
|
415
|
+
private retainCodeSessionInputsFromRequests;
|
|
414
416
|
/**
|
|
415
417
|
* Post-processes standard runTool outputs: dispatches ON_RUN_STEP_COMPLETED
|
|
416
418
|
* and stores code session context. Mirrors the completion handling in
|
|
@@ -531,7 +533,7 @@ export declare class ToolNode<T = any> extends RunnableCallable<T, T> {
|
|
|
531
533
|
* invocations cannot race on shared mutable state.
|
|
532
534
|
*/
|
|
533
535
|
private executeViaEvent;
|
|
534
|
-
protected run(input:
|
|
536
|
+
protected run(input: T, config: RunnableConfig, referenceReplay?: {
|
|
535
537
|
state?: ToolOutputReferenceState;
|
|
536
538
|
}): Promise<T>;
|
|
537
539
|
private isSendInput;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseMessage } from '@langchain/core/messages';
|
|
2
2
|
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
3
3
|
import type { ToolCall } from '@langchain/core/messages/tool';
|
|
4
|
-
import type { MultiAgentGraphState, HumanInTheLoopConfig, StandardGraphInput, ExecutableSubagentConfigEntry, SubagentExecutionContext, SubagentTaskConfig, SubagentTaskRuntime, SubagentUsageSink, TokenCounter } from '@/types';
|
|
4
|
+
import type { MultiAgentGraphState, HumanInTheLoopConfig, StandardGraphInput, ExecutableSubagentConfigEntry, SubagentExecutionContext, SubagentContextAdapter, SubagentContextResult, SubagentTaskConfig, SubagentTaskRuntime, SubagentUsageSink, TokenCounter } from '@/types';
|
|
5
5
|
import type { SubagentResumeManifest, SettledSubagentToolOutput } from './SubagentReplay';
|
|
6
6
|
import type { GraphFactory } from '@/graphs/graphFactory';
|
|
7
7
|
import type { StandardGraph } from '@/graphs/Graph';
|
|
@@ -71,11 +71,11 @@ export type SubagentExecuteParams = {
|
|
|
71
71
|
/** Host-restored child transcript for a fresh continuation run. @internal */
|
|
72
72
|
initialMessages?: BaseMessage[];
|
|
73
73
|
};
|
|
74
|
-
export type SubagentExecuteResult = {
|
|
75
|
-
content: string;
|
|
76
|
-
messages: BaseMessage[];
|
|
74
|
+
export type SubagentExecuteResult = SubagentContextResult & {
|
|
77
75
|
/** Tagged internal failure; foreground callers retain the legacy content. */
|
|
78
76
|
error?: string;
|
|
77
|
+
/** Completed child work whose host projection must be retried without re-execution. */
|
|
78
|
+
retryableDelivery?: true;
|
|
79
79
|
};
|
|
80
80
|
/**
|
|
81
81
|
* Factory that constructs a child graph for subagent execution. Injected
|
|
@@ -160,6 +160,7 @@ export type SubagentExecutorOptions = {
|
|
|
160
160
|
usageSink?: SubagentUsageSink;
|
|
161
161
|
/** Host-owned process-local task namespace for detached execution. */
|
|
162
162
|
taskConfig?: SubagentTaskConfig;
|
|
163
|
+
subagentContext?: SubagentContextAdapter;
|
|
163
164
|
};
|
|
164
165
|
export declare class SubagentExecutor {
|
|
165
166
|
private readonly configs;
|
|
@@ -187,6 +188,7 @@ export declare class SubagentExecutor {
|
|
|
187
188
|
private readonly createDetachedChildGraphFactory?;
|
|
188
189
|
private readonly usageSink?;
|
|
189
190
|
private readonly taskConfig?;
|
|
191
|
+
private readonly subagentContext?;
|
|
190
192
|
private readonly executions;
|
|
191
193
|
private replayCheckpointWorkflow?;
|
|
192
194
|
private readonly resolveParentHandlerRegistry?;
|
|
@@ -266,6 +268,7 @@ export declare class SubagentExecutor {
|
|
|
266
268
|
private persistChildCheckpointMarker;
|
|
267
269
|
execute(params: SubagentExecuteParams): Promise<SubagentExecuteResult>;
|
|
268
270
|
private executeOnce;
|
|
271
|
+
private completeHostContext;
|
|
269
272
|
/**
|
|
270
273
|
* Emits a single {@link GraphEvents.ON_SUBAGENT_UPDATE} envelope through the
|
|
271
274
|
* parent's handler registry. Silent no-op when no parent registry is set.
|
|
@@ -24,6 +24,7 @@ export interface ToolBatchReplayRecord {
|
|
|
24
24
|
turnState?: SubagentToolNodeResumeState;
|
|
25
25
|
referenceState?: ToolOutputReferenceState;
|
|
26
26
|
}
|
|
27
|
+
export type ToolReplayResumeStatus = 'active' | 'stale' | 'unverifiable';
|
|
27
28
|
interface ToolBatchReplayState {
|
|
28
29
|
version: 1;
|
|
29
30
|
approvalOwner?: string;
|
|
@@ -40,15 +41,17 @@ export declare function restoreToolReplayConfig(configurable: Record<string, unk
|
|
|
40
41
|
* steps, so the presence of replay evidence alone does not imply a resume.
|
|
41
42
|
* A parent replaying a checkpointed child has no local resume value.
|
|
42
43
|
*/
|
|
43
|
-
export declare function
|
|
44
|
+
export declare function getToolReplayResumeStatus(config: RunnableConfig, interruptId: string | undefined, isChildReplay: boolean): ToolReplayResumeStatus;
|
|
44
45
|
export declare function getToolBatchReplayOwner(config: RunnableConfig, agentId: string): string;
|
|
46
|
+
/** Remove stale authorization while retaining only settled results for this batch. */
|
|
47
|
+
export declare function clearStaleToolApprovalConfig(configurable: Record<string, unknown>, owner: string, batch: string | undefined): void;
|
|
45
48
|
export declare function getToolBatchReplayScope(config: RunnableConfig): string | undefined;
|
|
46
49
|
/** Foreign replay evidence may only transit a checkpoint-proven child path. */
|
|
47
50
|
export declare function isChildToolReplayOwner(config: RunnableConfig, owner: string, trustedParentCallIds: ReadonlySet<string>): boolean;
|
|
48
51
|
/** Rebind only the checkpoint-proven source execution when a child fork is created. */
|
|
49
|
-
export declare function rebindToolBatchReplayScope(configurable: Record<string, unknown>, sourceScope: string, destinationScope: string): void;
|
|
52
|
+
export declare function rebindToolBatchReplayScope(configurable: Record<string, unknown>, sourceScope: string, destinationScope: string, destinationThreadId?: string): void;
|
|
50
53
|
/** A fork may be paused again before it consumes its pending interrupt. */
|
|
51
|
-
export declare function rebindToolBatchReplayPayload(payload: unknown, sourceScope: string, destinationScope: string): unknown;
|
|
54
|
+
export declare function rebindToolBatchReplayPayload(payload: unknown, sourceScope: string, destinationScope: string, destinationThreadId?: string): unknown;
|
|
52
55
|
export declare function getToolBatchReplayState(payload: unknown): ToolBatchReplayState | undefined;
|
|
53
56
|
export declare function stripToolBatchReplayState(payload: unknown): unknown;
|
|
54
57
|
/** Decode outer execution metadata before shape-sensitive child wrappers. */
|
|
@@ -278,6 +278,8 @@ export type StandardGraphInput = {
|
|
|
278
278
|
* do not inherit it, keeping background nesting disabled for the MVP.
|
|
279
279
|
*/
|
|
280
280
|
subagentTasks?: SubagentTaskConfig;
|
|
281
|
+
/** Host-owned context and result projection for each isolated child execution. */
|
|
282
|
+
subagentContext?: SubagentContextAdapter;
|
|
281
283
|
/**
|
|
282
284
|
* True when this graph IS a subagent child run (set by `SubagentExecutor`
|
|
283
285
|
* when it constructs the child graph). Drives the hook-input `agentId`
|
|
@@ -499,6 +501,32 @@ export interface SubagentExecutionContext {
|
|
|
499
501
|
readonly depth: number;
|
|
500
502
|
readonly ancestry: readonly SubagentAncestryEntry[];
|
|
501
503
|
}
|
|
504
|
+
/** Trusted identity supplied before a child can access host-owned resources. */
|
|
505
|
+
export interface SubagentContextInput {
|
|
506
|
+
executionContext: SubagentExecutionContext;
|
|
507
|
+
parentThreadId?: string;
|
|
508
|
+
memberAgentIds: readonly string[];
|
|
509
|
+
signal: AbortSignal;
|
|
510
|
+
resumed: boolean;
|
|
511
|
+
}
|
|
512
|
+
export interface PreparedSubagentContext {
|
|
513
|
+
/** Added to the initial child input; checkpoint recovery does not add them again. */
|
|
514
|
+
messages?: BaseMessage[];
|
|
515
|
+
/** Host configuration; SDK execution and checkpoint identities remain authoritative. */
|
|
516
|
+
configurable?: RunnableConfig['configurable'];
|
|
517
|
+
/** Each entry replaces that member's inherited code partition and initial sessions. */
|
|
518
|
+
agentSessions?: Readonly<Record<string, Pick<AgentInputs, 'codeSessionKey' | 'initialSessions'>>>;
|
|
519
|
+
}
|
|
520
|
+
export interface SubagentContextResult {
|
|
521
|
+
content: string;
|
|
522
|
+
messages: BaseMessage[];
|
|
523
|
+
}
|
|
524
|
+
export interface SubagentContextAdapter {
|
|
525
|
+
/** Reauthorizes reconstructed executions; durable work must be idempotent by child run ID. */
|
|
526
|
+
prepare(input: SubagentContextInput): Promise<PreparedSubagentContext>;
|
|
527
|
+
/** Projects durable references into the result returned to the parent. */
|
|
528
|
+
complete?(input: SubagentContextInput, result: SubagentContextResult): Promise<Pick<SubagentContextResult, 'content'>>;
|
|
529
|
+
}
|
|
502
530
|
/**
|
|
503
531
|
* Wrapper event emitted when a subagent's child graph dispatches activity.
|
|
504
532
|
* Lets hosts show subagent progress in a UI surface separate from the parent
|
|
@@ -272,6 +272,8 @@ export type RunConfig = {
|
|
|
272
272
|
* Omit to preserve foreground-only subagent behavior.
|
|
273
273
|
*/
|
|
274
274
|
subagentTasks?: SubagentTaskConfig;
|
|
275
|
+
/** Authorizes and supplies host-owned context to isolated child runs. */
|
|
276
|
+
subagentContext?: g.SubagentContextAdapter;
|
|
275
277
|
/**
|
|
276
278
|
* Pre-constructed hook registry for this run. Hooks fire at lifecycle
|
|
277
279
|
* points in `processStream` (RunStart, UserPromptSubmit, Stop,
|
|
@@ -3,10 +3,10 @@ import type { StructuredToolInterface } from '@langchain/core/tools';
|
|
|
3
3
|
import type { ToolCall } from '@langchain/core/messages/tool';
|
|
4
4
|
import type { MessageContentComplex, RunStepResumeState, ToolErrorData } from './stream';
|
|
5
5
|
import type { ToolOutputReferenceRegistry } from '@/tools/toolOutputReferences';
|
|
6
|
+
import type { LangfuseConfig, SubagentExecutionContext } from './graph';
|
|
6
7
|
import type { PreparedSubagents } from '@/tools/preparedSubagents';
|
|
7
8
|
import type { RunBreakerScope } from '@/llm/streamLimits';
|
|
8
9
|
import type { HumanInTheLoopConfig } from './hitl';
|
|
9
|
-
import type { LangfuseConfig } from './graph';
|
|
10
10
|
import type { HookRegistry } from '@/hooks';
|
|
11
11
|
/** Replacement type for `import type { ToolCall } from '@langchain/core/messages/tool'` in order to have stringified args typed */
|
|
12
12
|
export type CustomToolCall = {
|
|
@@ -63,6 +63,7 @@ export type EagerEventToolExecution = {
|
|
|
63
63
|
toolName: string;
|
|
64
64
|
args: Record<string, unknown>;
|
|
65
65
|
request: ToolCallRequest;
|
|
66
|
+
codeSessionBaselineByName?: ReadonlyMap<string, string>;
|
|
66
67
|
promise: Promise<EagerEventToolExecutionOutcome>;
|
|
67
68
|
/**
|
|
68
69
|
* True when the streaming eager path already emitted the user-visible
|
|
@@ -139,6 +140,8 @@ export type ToolNodeOptions = {
|
|
|
139
140
|
/** ID of the agent that owns this tool node, surfaced to hooks as `executingAgentId`
|
|
140
141
|
* so a batch can be attributed to a specific agent even where `agentId` is undefined. */
|
|
141
142
|
executingAgentId?: string;
|
|
143
|
+
/** SDK-owned identity of the child execution, independent of reusable agent IDs. */
|
|
144
|
+
executionContext?: SubagentExecutionContext;
|
|
142
145
|
/** Name of the agent that owns this tool node, used for active Langfuse attribution. */
|
|
143
146
|
executingAgentName?: string;
|
|
144
147
|
/** Root graph-agent identity retained alongside the currently executing tool owner. */
|
|
@@ -529,6 +532,10 @@ export type ToolCallRequest = {
|
|
|
529
532
|
session_id: string;
|
|
530
533
|
files?: CodeEnvFile[];
|
|
531
534
|
};
|
|
535
|
+
/** Request-time execution session used to detect host session refreshes. */
|
|
536
|
+
codeSessionBaselineId?: string;
|
|
537
|
+
/** Preserve request-provisioned code inputs after an eager identity mismatch. */
|
|
538
|
+
retainCodeSessionInputs?: true;
|
|
532
539
|
/**
|
|
533
540
|
* Stable runtime session hint for stateful sandbox sessions. Orthogonal to
|
|
534
541
|
* `codeSessionContext` (which threads the transient exec-session for file
|
|
@@ -550,6 +557,8 @@ export type CallerCapabilityProjectionSnapshot = {
|
|
|
550
557
|
};
|
|
551
558
|
/** Batch request containing ALL tool calls for a graph step */
|
|
552
559
|
export type ToolExecuteBatchRequest = {
|
|
560
|
+
/** SDK-owned child lineage. Unset for tools in the root graph. */
|
|
561
|
+
executionContext?: SubagentExecutionContext;
|
|
553
562
|
/** All tool calls from the AIMessage */
|
|
554
563
|
toolCalls: ToolCallRequest[];
|
|
555
564
|
/** User ID for context */
|
|
@@ -1134,6 +1143,7 @@ export type ProgrammaticHookContext = {
|
|
|
1134
1143
|
runId: string;
|
|
1135
1144
|
threadId?: string;
|
|
1136
1145
|
agentId?: string;
|
|
1146
|
+
executionContext?: SubagentExecutionContext;
|
|
1137
1147
|
executingAgentId?: string;
|
|
1138
1148
|
};
|
|
1139
1149
|
/** Search mode: code_interpreter uses external sandbox, local uses safe substring matching */
|
package/package.json
CHANGED
package/src/common/constants.ts
CHANGED