@librechat/agents 3.5.0 → 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.
Files changed (188) hide show
  1. package/dist/cjs/agents/AgentContext.cjs +5 -2
  2. package/dist/cjs/agents/AgentContext.cjs.map +1 -1
  3. package/dist/cjs/graphs/Graph.cjs +148 -22
  4. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  5. package/dist/cjs/graphs/MultiAgentGraph.cjs +2 -1
  6. package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
  7. package/dist/cjs/main.cjs +4 -0
  8. package/dist/cjs/run.cjs +29 -11
  9. package/dist/cjs/run.cjs.map +1 -1
  10. package/dist/cjs/stream.cjs +8 -6
  11. package/dist/cjs/stream.cjs.map +1 -1
  12. package/dist/cjs/tools/BashExecutor.cjs +8 -7
  13. package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
  14. package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +5 -4
  15. package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -1
  16. package/dist/cjs/tools/CodeExecutor.cjs +26 -7
  17. package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
  18. package/dist/cjs/tools/ProgrammaticToolCalling.cjs +7 -6
  19. package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
  20. package/dist/cjs/tools/ToolNode.cjs +33 -10
  21. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  22. package/dist/cjs/tools/ToolSearch.cjs +1 -1
  23. package/dist/cjs/tools/ToolSearch.cjs.map +1 -1
  24. package/dist/cjs/tools/runStepResume.cjs +51 -0
  25. package/dist/cjs/tools/runStepResume.cjs.map +1 -0
  26. package/dist/cjs/tools/subagent/SubagentExecutor.cjs +15 -43
  27. package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
  28. package/dist/cjs/tools/subagent/SubagentReplay.cjs +6 -1
  29. package/dist/cjs/tools/subagent/SubagentReplay.cjs.map +1 -1
  30. package/dist/cjs/utils/toolSessions.cjs +63 -0
  31. package/dist/cjs/utils/toolSessions.cjs.map +1 -0
  32. package/dist/esm/agents/AgentContext.mjs +5 -2
  33. package/dist/esm/agents/AgentContext.mjs.map +1 -1
  34. package/dist/esm/graphs/Graph.mjs +148 -22
  35. package/dist/esm/graphs/Graph.mjs.map +1 -1
  36. package/dist/esm/graphs/MultiAgentGraph.mjs +2 -1
  37. package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
  38. package/dist/esm/main.mjs +2 -2
  39. package/dist/esm/run.mjs +29 -11
  40. package/dist/esm/run.mjs.map +1 -1
  41. package/dist/esm/stream.mjs +8 -6
  42. package/dist/esm/stream.mjs.map +1 -1
  43. package/dist/esm/tools/BashExecutor.mjs +9 -8
  44. package/dist/esm/tools/BashExecutor.mjs.map +1 -1
  45. package/dist/esm/tools/BashProgrammaticToolCalling.mjs +6 -5
  46. package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -1
  47. package/dist/esm/tools/CodeExecutor.mjs +23 -8
  48. package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
  49. package/dist/esm/tools/ProgrammaticToolCalling.mjs +8 -7
  50. package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
  51. package/dist/esm/tools/ToolNode.mjs +33 -10
  52. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  53. package/dist/esm/tools/ToolSearch.mjs +2 -2
  54. package/dist/esm/tools/ToolSearch.mjs.map +1 -1
  55. package/dist/esm/tools/runStepResume.mjs +48 -0
  56. package/dist/esm/tools/runStepResume.mjs.map +1 -0
  57. package/dist/esm/tools/subagent/SubagentExecutor.mjs +15 -43
  58. package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
  59. package/dist/esm/tools/subagent/SubagentReplay.mjs +6 -1
  60. package/dist/esm/tools/subagent/SubagentReplay.mjs.map +1 -1
  61. package/dist/esm/utils/toolSessions.mjs +62 -0
  62. package/dist/esm/utils/toolSessions.mjs.map +1 -0
  63. package/dist/types/agents/AgentContext.d.ts +7 -4
  64. package/dist/types/agents/projection.d.ts +1 -1
  65. package/dist/types/events.d.ts +2 -2
  66. package/dist/types/graphs/Graph.d.ts +22 -14
  67. package/dist/types/graphs/MultiAgentGraph.d.ts +2 -2
  68. package/dist/types/graphs/createGraph.d.ts +4 -4
  69. package/dist/types/graphs/graphFactory.d.ts +1 -1
  70. package/dist/types/hitl/askUserQuestion.d.ts +1 -1
  71. package/dist/types/hitl/askUserQuestions.d.ts +1 -1
  72. package/dist/types/hitl/askUserQuestionsInterrupt.d.ts +1 -1
  73. package/dist/types/hooks/types.d.ts +1 -1
  74. package/dist/types/instrumentation.d.ts +1 -1
  75. package/dist/types/langfuse.d.ts +3 -3
  76. package/dist/types/langfuseConfig.d.ts +2 -2
  77. package/dist/types/langfuseRuntimeContext.d.ts +1 -1
  78. package/dist/types/langfuseRuntimeScope.d.ts +2 -2
  79. package/dist/types/langfuseSpanRegistry.d.ts +1 -1
  80. package/dist/types/langfuseToolOutputTracing.d.ts +3 -3
  81. package/dist/types/llm/anthropic/index.d.ts +1 -1
  82. package/dist/types/llm/bedrock/index.d.ts +1 -1
  83. package/dist/types/llm/bedrock/toolCache.d.ts +2 -2
  84. package/dist/types/llm/contextOverflowRecovery.d.ts +2 -2
  85. package/dist/types/llm/google/index.d.ts +1 -1
  86. package/dist/types/llm/init.d.ts +2 -2
  87. package/dist/types/llm/invoke.d.ts +6 -6
  88. package/dist/types/llm/mistral/index.d.ts +1 -1
  89. package/dist/types/llm/openai/index.d.ts +2 -2
  90. package/dist/types/llm/openrouter/index.d.ts +2 -2
  91. package/dist/types/llm/openrouter/toolCache.d.ts +2 -2
  92. package/dist/types/llm/providers.d.ts +2 -2
  93. package/dist/types/llm/request.d.ts +2 -2
  94. package/dist/types/llm/stream/chunkAdapters.d.ts +1 -1
  95. package/dist/types/llm/streamLimits.d.ts +1 -1
  96. package/dist/types/llm/truncation.d.ts +1 -1
  97. package/dist/types/llm/vertexai/index.d.ts +1 -1
  98. package/dist/types/messages/alternation.d.ts +1 -1
  99. package/dist/types/messages/anthropicToolCache.d.ts +2 -2
  100. package/dist/types/messages/assistantPhase.d.ts +3 -3
  101. package/dist/types/messages/budget.d.ts +1 -1
  102. package/dist/types/messages/cache.d.ts +1 -1
  103. package/dist/types/messages/contextPruning.d.ts +2 -2
  104. package/dist/types/messages/core.d.ts +2 -2
  105. package/dist/types/messages/format.d.ts +2 -2
  106. package/dist/types/messages/ids.d.ts +2 -2
  107. package/dist/types/messages/injected.d.ts +1 -1
  108. package/dist/types/messages/langchain.d.ts +1 -1
  109. package/dist/types/messages/prune.d.ts +3 -3
  110. package/dist/types/openai/index.d.ts +1 -1
  111. package/dist/types/prompts/activityLabel.d.ts +2 -2
  112. package/dist/types/responses/index.d.ts +1 -1
  113. package/dist/types/run.d.ts +3 -3
  114. package/dist/types/session/handlers.d.ts +1 -1
  115. package/dist/types/session/types.d.ts +1 -1
  116. package/dist/types/stream.d.ts +4 -4
  117. package/dist/types/summarization/index.d.ts +1 -1
  118. package/dist/types/summarization/node.d.ts +6 -6
  119. package/dist/types/tools/BashExecutor.d.ts +2 -2
  120. package/dist/types/tools/BashProgrammaticToolCalling.d.ts +2 -2
  121. package/dist/types/tools/CodeExecutor.d.ts +7 -3
  122. package/dist/types/tools/CodeSessionFileSummary.d.ts +1 -1
  123. package/dist/types/tools/ProgrammaticToolCalling.d.ts +3 -3
  124. package/dist/types/tools/ReadFile.d.ts +1 -1
  125. package/dist/types/tools/SkillTool.d.ts +1 -1
  126. package/dist/types/tools/SubagentTool.d.ts +3 -3
  127. package/dist/types/tools/ToolNode.d.ts +8 -6
  128. package/dist/types/tools/ToolSearch.d.ts +2 -2
  129. package/dist/types/tools/cloudflare/CloudflareBridgeRuntime.d.ts +1 -1
  130. package/dist/types/tools/cloudflare/CloudflareProgrammaticToolCalling.d.ts +1 -1
  131. package/dist/types/tools/cloudflare/CloudflareSandboxExecutionEngine.d.ts +2 -2
  132. package/dist/types/tools/cloudflare/CloudflareSandboxTools.d.ts +1 -1
  133. package/dist/types/tools/eagerEventExecution.d.ts +1 -1
  134. package/dist/types/tools/handlers.d.ts +3 -3
  135. package/dist/types/tools/intentArg.d.ts +1 -1
  136. package/dist/types/tools/local/CompileCheckTool.d.ts +2 -2
  137. package/dist/types/tools/local/FileCheckpointer.d.ts +1 -1
  138. package/dist/types/tools/local/LocalCodingTools.d.ts +2 -2
  139. package/dist/types/tools/local/LocalExecutionEngine.d.ts +1 -1
  140. package/dist/types/tools/local/LocalExecutionTools.d.ts +1 -1
  141. package/dist/types/tools/local/LocalProgrammaticToolCalling.d.ts +1 -1
  142. package/dist/types/tools/local/bashAst.d.ts +1 -1
  143. package/dist/types/tools/local/resolveLocalExecutionTools.d.ts +1 -1
  144. package/dist/types/tools/local/syntaxCheck.d.ts +1 -1
  145. package/dist/types/tools/ptcTimeout.d.ts +1 -1
  146. package/dist/types/tools/runStepResume.d.ts +5 -0
  147. package/dist/types/tools/schema.d.ts +1 -1
  148. package/dist/types/tools/search/anthropic.d.ts +1 -1
  149. package/dist/types/tools/skillCatalog.d.ts +1 -1
  150. package/dist/types/tools/subagent/SubagentExecutor.d.ts +30 -5
  151. package/dist/types/tools/subagent/SubagentReplay.d.ts +4 -3
  152. package/dist/types/tools/subagent/childGraphConfig.d.ts +2 -2
  153. package/dist/types/types/activityLabel.d.ts +3 -3
  154. package/dist/types/types/graph.d.ts +16 -7
  155. package/dist/types/types/llm.d.ts +9 -9
  156. package/dist/types/types/run.d.ts +7 -7
  157. package/dist/types/types/stream.d.ts +23 -5
  158. package/dist/types/types/summarize.d.ts +2 -2
  159. package/dist/types/types/tools.d.ts +41 -21
  160. package/dist/types/utils/errors.d.ts +1 -1
  161. package/dist/types/utils/events.d.ts +1 -1
  162. package/dist/types/utils/handlers.d.ts +3 -3
  163. package/dist/types/utils/llm.d.ts +1 -1
  164. package/dist/types/utils/llmConfig.d.ts +1 -1
  165. package/dist/types/utils/title.d.ts +1 -1
  166. package/dist/types/utils/toolSessions.d.ts +18 -0
  167. package/package.json +28 -32
  168. package/src/agents/AgentContext.ts +7 -0
  169. package/src/graphs/Graph.ts +192 -13
  170. package/src/graphs/MultiAgentGraph.ts +1 -0
  171. package/src/run.ts +62 -11
  172. package/src/stream.ts +28 -9
  173. package/src/tools/BashExecutor.ts +31 -13
  174. package/src/tools/BashProgrammaticToolCalling.ts +19 -9
  175. package/src/tools/CodeExecutor.ts +57 -16
  176. package/src/tools/ProgrammaticToolCalling.ts +26 -12
  177. package/src/tools/ToolNode.ts +58 -8
  178. package/src/tools/ToolSearch.ts +2 -2
  179. package/src/tools/runStepResume.ts +121 -0
  180. package/src/tools/subagent/SubagentExecutor.ts +67 -65
  181. package/src/tools/subagent/SubagentReplay.ts +22 -1
  182. package/src/types/graph.ts +10 -0
  183. package/src/types/stream.ts +17 -0
  184. package/src/types/tools.ts +50 -21
  185. package/src/utils/toolSessions.ts +113 -0
  186. package/dist/types/agents/__tests__/promptCacheLiveHelpers.d.ts +0 -52
  187. package/dist/types/test/mockTools.d.ts +0 -28
  188. package/dist/types/utils/__tests__/fixtures/contextOverflowSignatures.d.ts +0 -40
@@ -1,10 +1,17 @@
1
1
  // src/types/tools.ts
2
2
  import type { StructuredToolInterface } from '@langchain/core/tools';
3
- import type { RunnableToolLike } from '@langchain/core/runnables';
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 { MessageContentComplex, ToolErrorData } from './stream';
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 best-effort stateful sessions in the tool description
386
- * (variables/files may persist between calls, may reset). Prompt text
387
- * only, and it must be set here because the description is bound to the
388
- * LLM at construction time. Pair it with the run-scoped
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
- * Opt into best-effort stateful runtime sessions on the remote Code API
1110
- * (its warm per-session MicroVM backend). This gate is run-scoped: it only
1111
- * controls the wire behavior (ToolNode injecting the session hint on
1112
- * execute_code/bash calls). The transport is otherwise unchanged.
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. Set BOTH from one flag (as LibreChat does): with this on but
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 is stateless in v1. The initial
1308
- * /exec/programmatic request still forwards a ToolNode-injected
1309
- * `_runtime_session_hint` when present, but there is no factory-level opt-in
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
+ }
@@ -1,52 +0,0 @@
1
- import type { UsageMetadata } from '@langchain/core/messages';
2
- import type { ClientOptions } from '@langchain/openai';
3
- import type { ChatOpenRouterInput } from '../../llm/openrouter';
4
- import type * as t from '../../types';
5
- import { Providers } from '../../common';
6
- type LivePromptCacheProvider = Providers.ANTHROPIC | Providers.BEDROCK | Providers.OPENROUTER;
7
- type PromptCacheExpectedSystemBlock = {
8
- type: 'text';
9
- text: string;
10
- cache_control?: {
11
- type: 'ephemeral';
12
- ttl?: '1h';
13
- };
14
- } | {
15
- cachePoint: {
16
- type: 'default';
17
- ttl?: '1h';
18
- };
19
- };
20
- type LivePromptCacheClientOptions = t.ClientOptions | t.BedrockAnthropicClientOptions | (ChatOpenRouterInput & {
21
- configuration?: ClientOptions;
22
- });
23
- export declare function buildStableInstructions({ nonce, providerLabel, }: {
24
- nonce: string;
25
- providerLabel: string;
26
- }): string;
27
- export declare function buildDynamicInstructions({ marker, tailDescription, }: {
28
- marker: string;
29
- tailDescription: string;
30
- }): string;
31
- export declare function waitForCachePropagation(): Promise<void>;
32
- export declare function assertSystemPayloadShape({ agentId, provider, clientOptions, stableInstructions, dynamicInstructions, expectedContent, }: {
33
- agentId: string;
34
- provider: LivePromptCacheProvider;
35
- clientOptions: LivePromptCacheClientOptions;
36
- stableInstructions: string;
37
- dynamicInstructions: string;
38
- expectedContent: PromptCacheExpectedSystemBlock[];
39
- }): Promise<void>;
40
- export declare function runLiveTurn({ provider, providerLabel, clientOptions, runId, threadId, stableInstructions, dynamicInstructions, }: {
41
- provider: LivePromptCacheProvider;
42
- providerLabel: string;
43
- clientOptions: LivePromptCacheClientOptions;
44
- runId: string;
45
- threadId: string;
46
- stableInstructions: string;
47
- dynamicInstructions: string;
48
- }): Promise<{
49
- text: string;
50
- usage: UsageMetadata;
51
- }>;
52
- export {};
@@ -1,28 +0,0 @@
1
- import type { StructuredToolInterface } from '@langchain/core/tools';
2
- import type { LCToolRegistry } from '../types';
3
- /**
4
- * Mock get_team_members tool - returns list of team members
5
- */
6
- export declare function createGetTeamMembersTool(): StructuredToolInterface;
7
- /**
8
- * Mock get_expenses tool - returns expense records for a user
9
- */
10
- export declare function createGetExpensesTool(): StructuredToolInterface;
11
- /**
12
- * Mock get_weather tool - returns weather data for a city
13
- */
14
- export declare function createGetWeatherTool(): StructuredToolInterface;
15
- /**
16
- * Mock calculator tool - evaluates mathematical expressions
17
- */
18
- export declare function createCalculatorTool(): StructuredToolInterface;
19
- /**
20
- * Creates a tool registry for programmatic tool calling tests.
21
- * Tools are configured with allowed_callers to demonstrate classification.
22
- */
23
- export declare function createProgrammaticToolRegistry(): LCToolRegistry;
24
- /**
25
- * Creates a sample tool registry for tool search tests.
26
- * Includes mix of deferred and non-deferred tools.
27
- */
28
- export declare function createToolSearchToolRegistry(): LCToolRegistry;
@@ -1,40 +0,0 @@
1
- /**
2
- * Provider error signatures captured from live over-limit requests.
3
- *
4
- * Every entry below was produced by `src/scripts/context-overflow-probe.ts`
5
- * sending a prompt past the model's context window and recording what came
6
- * back. Account identifiers and request ids have been replaced with
7
- * placeholders; the wording, status codes, and nesting are verbatim.
8
- *
9
- * Treat these as evidence, not examples: if a provider changes its wording,
10
- * re-run the probe and update the fixture rather than loosening the matcher.
11
- */
12
- import { Providers } from '../../../common';
13
- export interface OverflowSignature {
14
- provider: Providers;
15
- model: string;
16
- /** Class the SDK actually threw, for reference in review. */
17
- thrownAs: string;
18
- /**
19
- * Stand-in for the thrown error carrying exactly the fields the classifier
20
- * reads. Nested bodies are kept as the strings the SDKs attach.
21
- */
22
- error: Record<string, unknown>;
23
- expected: {
24
- kind: 'context_window' | 'request_too_large';
25
- limitTokens?: number;
26
- requestedTokens?: number;
27
- };
28
- /** Set when the signature is only decidable with caller-side corroboration. */
29
- requiresContextPressure?: boolean;
30
- }
31
- export declare const OVERFLOW_SIGNATURES: readonly OverflowSignature[];
32
- /**
33
- * Errors that mention limits, sizes, or tokens but are NOT fixed by
34
- * compaction. The first two were captured live alongside the signatures
35
- * above; the rest are the adjacent failures a loose matcher would swallow.
36
- */
37
- export declare const NON_OVERFLOW_SIGNATURES: readonly {
38
- label: string;
39
- error: Record<string, unknown>;
40
- }[];