@librechat/agents 3.5.1 → 3.6.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 +5 -2
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +148 -22
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +2 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/main.cjs +4 -0
- package/dist/cjs/run.cjs +29 -11
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/stream.cjs +8 -6
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/tools/BashExecutor.cjs +8 -7
- package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +5 -4
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +26 -7
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +7 -6
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +33 -10
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/ToolSearch.cjs +1 -1
- package/dist/cjs/tools/ToolSearch.cjs.map +1 -1
- package/dist/cjs/tools/runStepResume.cjs +51 -0
- package/dist/cjs/tools/runStepResume.cjs.map +1 -0
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +15 -43
- 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/utils/toolSessions.cjs +63 -0
- package/dist/cjs/utils/toolSessions.cjs.map +1 -0
- package/dist/esm/agents/AgentContext.mjs +5 -2
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +148 -22
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +2 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/main.mjs +2 -2
- package/dist/esm/run.mjs +29 -11
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/stream.mjs +8 -6
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/tools/BashExecutor.mjs +9 -8
- package/dist/esm/tools/BashExecutor.mjs.map +1 -1
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs +6 -5
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +23 -8
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +8 -7
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +33 -10
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/ToolSearch.mjs +2 -2
- package/dist/esm/tools/ToolSearch.mjs.map +1 -1
- package/dist/esm/tools/runStepResume.mjs +48 -0
- package/dist/esm/tools/runStepResume.mjs.map +1 -0
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +15 -43
- 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/utils/toolSessions.mjs +62 -0
- package/dist/esm/utils/toolSessions.mjs.map +1 -0
- package/dist/types/agents/AgentContext.d.ts +4 -1
- package/dist/types/graphs/Graph.d.ts +11 -3
- package/dist/types/tools/CodeExecutor.d.ts +4 -0
- package/dist/types/tools/ProgrammaticToolCalling.d.ts +1 -1
- package/dist/types/tools/ToolNode.d.ts +3 -1
- package/dist/types/tools/runStepResume.d.ts +5 -0
- package/dist/types/tools/subagent/SubagentExecutor.d.ts +25 -0
- package/dist/types/tools/subagent/SubagentReplay.d.ts +2 -1
- package/dist/types/types/graph.d.ts +10 -1
- package/dist/types/types/stream.d.ts +18 -0
- package/dist/types/types/tools.d.ts +36 -16
- package/dist/types/utils/toolSessions.d.ts +18 -0
- package/package.json +1 -1
- package/src/agents/AgentContext.ts +7 -0
- package/src/graphs/Graph.ts +192 -13
- package/src/graphs/MultiAgentGraph.ts +1 -0
- package/src/run.ts +62 -11
- package/src/stream.ts +28 -9
- package/src/tools/BashExecutor.ts +31 -13
- package/src/tools/BashProgrammaticToolCalling.ts +19 -9
- package/src/tools/CodeExecutor.ts +57 -16
- package/src/tools/ProgrammaticToolCalling.ts +26 -12
- package/src/tools/ToolNode.ts +58 -8
- package/src/tools/ToolSearch.ts +2 -2
- package/src/tools/runStepResume.ts +121 -0
- package/src/tools/subagent/SubagentExecutor.ts +67 -65
- package/src/tools/subagent/SubagentReplay.ts +22 -1
- package/src/types/graph.ts +10 -0
- package/src/types/stream.ts +17 -0
- package/src/types/tools.ts +50 -21
- package/src/utils/toolSessions.ts +113 -0
package/src/types/tools.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
// src/types/tools.ts
|
|
2
2
|
import type { StructuredToolInterface } from '@langchain/core/tools';
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
RunnableConfig,
|
|
5
|
+
RunnableToolLike,
|
|
6
|
+
} from '@langchain/core/runnables';
|
|
4
7
|
import type { ToolCall } from '@langchain/core/messages/tool';
|
|
5
8
|
import type { ToolOutputReferenceRegistry } from '@/tools/toolOutputReferences';
|
|
6
9
|
import type { RunBreakerScope } from '@/llm/streamLimits';
|
|
7
|
-
import type {
|
|
10
|
+
import type {
|
|
11
|
+
MessageContentComplex,
|
|
12
|
+
RunStepResumeState,
|
|
13
|
+
ToolErrorData,
|
|
14
|
+
} from './stream';
|
|
8
15
|
import type { HumanInTheLoopConfig } from './hitl';
|
|
9
16
|
import type { LangfuseConfig } from './graph';
|
|
10
17
|
import type { HookRegistry } from '@/hooks';
|
|
@@ -128,6 +135,8 @@ export type ToolNodeOptions = {
|
|
|
128
135
|
toolRegistry?: LCToolRegistry;
|
|
129
136
|
/** Reference to Graph's sessions map for automatic session injection */
|
|
130
137
|
sessions?: ToolSessionMap;
|
|
138
|
+
/** Partition within `sessions` used by this agent's code tools. */
|
|
139
|
+
codeSessionKey?: string;
|
|
131
140
|
/** When true, dispatches ON_TOOL_EXECUTE events instead of invoking tools directly */
|
|
132
141
|
eventDrivenMode?: boolean;
|
|
133
142
|
/** Tool definitions for event-driven mode (used for context, not invocation) */
|
|
@@ -274,6 +283,13 @@ export type ToolNodeOptions = {
|
|
|
274
283
|
* controller.
|
|
275
284
|
*/
|
|
276
285
|
getRunScope?: () => RunBreakerScope;
|
|
286
|
+
/** SDK-owned checkpoint bridge for open run-step lifecycle state. */
|
|
287
|
+
restoreRunStepResumeState?: (
|
|
288
|
+
state?: RunStepResumeState,
|
|
289
|
+
config?: RunnableConfig
|
|
290
|
+
) => void;
|
|
291
|
+
/** SDK-owned checkpoint snapshot for open run-step lifecycle state. */
|
|
292
|
+
createRunStepResumeState?: () => RunStepResumeState;
|
|
277
293
|
};
|
|
278
294
|
|
|
279
295
|
export type ToolNodeConstructorParams = ToolRefs & ToolNodeOptions;
|
|
@@ -375,6 +391,19 @@ export type CodeEnvFile =
|
|
|
375
391
|
export type CodeExecutionToolParams =
|
|
376
392
|
| undefined
|
|
377
393
|
| {
|
|
394
|
+
/** Trusted Code API endpoint selected by the host for this agent. */
|
|
395
|
+
baseUrl?: string;
|
|
396
|
+
/**
|
|
397
|
+
* Expected Code API execution profile. Sent as a request assertion so
|
|
398
|
+
* endpoint/configuration drift fails closed instead of silently using
|
|
399
|
+
* the wrong sandbox backend.
|
|
400
|
+
*/
|
|
401
|
+
executionProfile?: CodeApiExecutionProfile;
|
|
402
|
+
/**
|
|
403
|
+
* Trusted warm-runtime affinity hint selected by the host for this
|
|
404
|
+
* agent invocation. This overrides the legacy ToolNode-injected hint.
|
|
405
|
+
*/
|
|
406
|
+
runtimeSessionHint?: string;
|
|
378
407
|
/** Execution session — see `CodeSessionContext.session_id`. */
|
|
379
408
|
session_id?: string;
|
|
380
409
|
user_id?: string;
|
|
@@ -382,16 +411,16 @@ export type CodeExecutionToolParams =
|
|
|
382
411
|
/** Optional host-supplied Code API auth headers. */
|
|
383
412
|
authHeaders?: CodeApiAuthHeaders;
|
|
384
413
|
/**
|
|
385
|
-
* Advertise
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
* `toolExecution.sandbox.statefulSessions` gate, which drives the wire
|
|
390
|
-
* hint — set both from one flag so the prompt and the backend agree.
|
|
414
|
+
* Advertise filesystem-tier stateful sessions in the tool description
|
|
415
|
+
* and allow a trusted runtime affinity hint onto the wire. Resolve this,
|
|
416
|
+
* `baseUrl`, `executionProfile`, and `runtimeSessionHint` together from
|
|
417
|
+
* the executing agent so the prompt and backend agree.
|
|
391
418
|
*/
|
|
392
419
|
statefulSessions?: boolean;
|
|
393
420
|
};
|
|
394
421
|
|
|
422
|
+
export type CodeApiExecutionProfile = 'default' | 'stateful';
|
|
423
|
+
|
|
395
424
|
export type CodeApiAuthHeaderMap = Record<string, string>;
|
|
396
425
|
|
|
397
426
|
export type CodeApiAuthHeaders =
|
|
@@ -1106,19 +1135,17 @@ export type CloudflareSandboxExecutionConfig = {
|
|
|
1106
1135
|
|
|
1107
1136
|
export type SandboxExecutionConfig = {
|
|
1108
1137
|
/**
|
|
1109
|
-
*
|
|
1110
|
-
*
|
|
1111
|
-
*
|
|
1112
|
-
*
|
|
1138
|
+
* Legacy run-scoped opt-in for warm runtime hint injection. New hosts that
|
|
1139
|
+
* need mixed execution profiles should resolve `statefulSessions`,
|
|
1140
|
+
* `baseUrl`, `executionProfile`, and `runtimeSessionHint` on each executing
|
|
1141
|
+
* agent's tool factories instead. Direct executors ignore this injected hint
|
|
1142
|
+
* unless their own factory has `statefulSessions: true`.
|
|
1113
1143
|
*
|
|
1114
1144
|
* It does NOT change the model-facing tool description. Tool descriptions are
|
|
1115
1145
|
* bound to the LLM at construction time (`createCodeExecutionTool` /
|
|
1116
1146
|
* `createBashExecutionTool`), before this run config is applied inside the
|
|
1117
1147
|
* graph, so they can only be adjusted via the tools' own `statefulSessions`
|
|
1118
|
-
* factory param.
|
|
1119
|
-
* the factory param off, the backend runs statefully while the model is still
|
|
1120
|
-
* told the environment is stateless (non-corrupting — the model just won't
|
|
1121
|
-
* exploit persistence).
|
|
1148
|
+
* factory param.
|
|
1122
1149
|
*/
|
|
1123
1150
|
statefulSessions?: boolean;
|
|
1124
1151
|
/**
|
|
@@ -1294,6 +1321,10 @@ export type BashProgrammaticToolCallingParams = ProgrammaticToolCallingParams;
|
|
|
1294
1321
|
export type ProgrammaticToolCallingParams = {
|
|
1295
1322
|
/** Code API base URL (or use CODE_BASEURL env var) */
|
|
1296
1323
|
baseUrl?: string;
|
|
1324
|
+
/** Expected Code API execution profile (host-controlled). */
|
|
1325
|
+
executionProfile?: CodeApiExecutionProfile;
|
|
1326
|
+
/** Trusted warm-runtime affinity hint for this agent invocation. */
|
|
1327
|
+
runtimeSessionHint?: string;
|
|
1297
1328
|
/** Safety limit for round-trips (default: 20) */
|
|
1298
1329
|
maxRoundTrips?: number;
|
|
1299
1330
|
/** Maximum per-sandbox-run timeout for PTC's legacy `timeout` field. */
|
|
@@ -1304,11 +1335,9 @@ export type ProgrammaticToolCallingParams = {
|
|
|
1304
1335
|
debug?: boolean;
|
|
1305
1336
|
/** Optional host-supplied Code API auth headers. */
|
|
1306
1337
|
authHeaders?: CodeApiAuthHeaders;
|
|
1307
|
-
/* No `statefulSessions` here: PTC
|
|
1308
|
-
*
|
|
1309
|
-
*
|
|
1310
|
-
* to advertise (it would be a no-op). Re-add with real behavior when PTC
|
|
1311
|
-
* stateful prompting lands. */
|
|
1338
|
+
/* No `statefulSessions` here: PTC keeps a stateless runtime prompt in v1.
|
|
1339
|
+
* An explicit stateful execution profile may still use a warm filesystem;
|
|
1340
|
+
* runtime/in-memory state never carries across calls. */
|
|
1312
1341
|
};
|
|
1313
1342
|
|
|
1314
1343
|
// ============================================================================
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type * as t from '@/types';
|
|
2
|
+
import { Constants } from '@/common';
|
|
3
|
+
|
|
4
|
+
type CodeSessionAgent = Pick<t.AgentInputs, 'codeSessionKey' | 'initialSessions'>;
|
|
5
|
+
|
|
6
|
+
function cloneToolSessionContext(
|
|
7
|
+
context: t.ToolSessionContext
|
|
8
|
+
): t.ToolSessionContext {
|
|
9
|
+
return {
|
|
10
|
+
...context,
|
|
11
|
+
...(context.files == null
|
|
12
|
+
? {}
|
|
13
|
+
: {
|
|
14
|
+
files: context.files.map((file) => ({
|
|
15
|
+
...file,
|
|
16
|
+
storage_session_id:
|
|
17
|
+
file.storage_session_id ?? context.session_id,
|
|
18
|
+
})),
|
|
19
|
+
}),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function mergeToolSessionContext(
|
|
24
|
+
sessions: t.ToolSessionMap,
|
|
25
|
+
key: string,
|
|
26
|
+
context: t.ToolSessionContext
|
|
27
|
+
): void {
|
|
28
|
+
const existing = sessions.get(key);
|
|
29
|
+
if (existing == null) {
|
|
30
|
+
sessions.set(key, cloneToolSessionContext(context));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (context.files == null || context.files.length === 0) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const seenFiles = new Set(
|
|
38
|
+
existing.files?.map(
|
|
39
|
+
(file) =>
|
|
40
|
+
`${file.storage_session_id ?? existing.session_id}\0${file.id}`
|
|
41
|
+
) ?? []
|
|
42
|
+
);
|
|
43
|
+
const files = existing.files == null ? [] : [...existing.files];
|
|
44
|
+
for (const file of context.files) {
|
|
45
|
+
const storageSessionId = file.storage_session_id ?? context.session_id;
|
|
46
|
+
const fileKey = `${storageSessionId}\0${file.id}`;
|
|
47
|
+
if (seenFiles.has(fileKey)) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
seenFiles.add(fileKey);
|
|
51
|
+
files.push({ ...file, storage_session_id: storageSessionId });
|
|
52
|
+
}
|
|
53
|
+
sessions.set(key, { ...existing, files });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Seeds a top-level graph while preserving the legacy run-wide session map.
|
|
58
|
+
* A legacy `execute_code` seed is copied into every custom agent partition
|
|
59
|
+
* unless the host already supplied an explicit seed for that partition.
|
|
60
|
+
*/
|
|
61
|
+
export function seedRunInitialSessions(args: {
|
|
62
|
+
sessions: t.ToolSessionMap;
|
|
63
|
+
initialSessions: t.ToolSessionMap;
|
|
64
|
+
agents: Iterable<Pick<t.AgentInputs, 'codeSessionKey'>>;
|
|
65
|
+
}): void {
|
|
66
|
+
const { sessions, initialSessions, agents } = args;
|
|
67
|
+
for (const [key, context] of initialSessions) {
|
|
68
|
+
mergeToolSessionContext(sessions, key, context);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const legacyCodeSession = initialSessions.get(Constants.EXECUTE_CODE);
|
|
72
|
+
if (legacyCodeSession == null) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
for (const agent of agents) {
|
|
76
|
+
const key = agent.codeSessionKey ?? Constants.EXECUTE_CODE;
|
|
77
|
+
if (
|
|
78
|
+
key === Constants.EXECUTE_CODE ||
|
|
79
|
+
initialSessions.has(key) ||
|
|
80
|
+
sessions.has(key)
|
|
81
|
+
) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
sessions.set(key, cloneToolSessionContext(legacyCodeSession));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Seeds an isolated child graph from each selected agent. Legacy code-session
|
|
90
|
+
* entries are remapped to the owning agent's partition before they are merged.
|
|
91
|
+
*/
|
|
92
|
+
export function seedAgentInitialSessions(
|
|
93
|
+
sessions: t.ToolSessionMap,
|
|
94
|
+
agents: Iterable<CodeSessionAgent>
|
|
95
|
+
): void {
|
|
96
|
+
for (const agent of agents) {
|
|
97
|
+
if (agent.initialSessions == null) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const codeSessionKey = agent.codeSessionKey ?? Constants.EXECUTE_CODE;
|
|
101
|
+
const hasExplicitCodeSession =
|
|
102
|
+
codeSessionKey !== Constants.EXECUTE_CODE &&
|
|
103
|
+
agent.initialSessions.has(codeSessionKey);
|
|
104
|
+
for (const [toolName, context] of agent.initialSessions) {
|
|
105
|
+
if (toolName === Constants.EXECUTE_CODE && hasExplicitCodeSession) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const key =
|
|
109
|
+
toolName === Constants.EXECUTE_CODE ? codeSessionKey : toolName;
|
|
110
|
+
mergeToolSessionContext(sessions, key, context);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|