@librechat/agents 2.4.322 → 3.0.0-rc2

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 (266) hide show
  1. package/dist/cjs/agents/AgentContext.cjs +218 -0
  2. package/dist/cjs/agents/AgentContext.cjs.map +1 -0
  3. package/dist/cjs/common/enum.cjs +14 -5
  4. package/dist/cjs/common/enum.cjs.map +1 -1
  5. package/dist/cjs/events.cjs +10 -6
  6. package/dist/cjs/events.cjs.map +1 -1
  7. package/dist/cjs/graphs/Graph.cjs +309 -212
  8. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  9. package/dist/cjs/graphs/MultiAgentGraph.cjs +422 -0
  10. package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -0
  11. package/dist/cjs/llm/anthropic/index.cjs +54 -9
  12. package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
  13. package/dist/cjs/llm/anthropic/types.cjs.map +1 -1
  14. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +52 -6
  15. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
  16. package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +22 -2
  17. package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -1
  18. package/dist/cjs/llm/anthropic/utils/tools.cjs +29 -0
  19. package/dist/cjs/llm/anthropic/utils/tools.cjs.map +1 -0
  20. package/dist/cjs/llm/google/index.cjs +144 -0
  21. package/dist/cjs/llm/google/index.cjs.map +1 -0
  22. package/dist/cjs/llm/google/utils/common.cjs +477 -0
  23. package/dist/cjs/llm/google/utils/common.cjs.map +1 -0
  24. package/dist/cjs/llm/ollama/index.cjs +67 -0
  25. package/dist/cjs/llm/ollama/index.cjs.map +1 -0
  26. package/dist/cjs/llm/ollama/utils.cjs +158 -0
  27. package/dist/cjs/llm/ollama/utils.cjs.map +1 -0
  28. package/dist/cjs/llm/openai/index.cjs +389 -3
  29. package/dist/cjs/llm/openai/index.cjs.map +1 -1
  30. package/dist/cjs/llm/openai/utils/index.cjs +672 -0
  31. package/dist/cjs/llm/openai/utils/index.cjs.map +1 -0
  32. package/dist/cjs/llm/providers.cjs +15 -15
  33. package/dist/cjs/llm/providers.cjs.map +1 -1
  34. package/dist/cjs/llm/text.cjs +14 -3
  35. package/dist/cjs/llm/text.cjs.map +1 -1
  36. package/dist/cjs/llm/vertexai/index.cjs +330 -0
  37. package/dist/cjs/llm/vertexai/index.cjs.map +1 -0
  38. package/dist/cjs/main.cjs +11 -0
  39. package/dist/cjs/main.cjs.map +1 -1
  40. package/dist/cjs/run.cjs +120 -81
  41. package/dist/cjs/run.cjs.map +1 -1
  42. package/dist/cjs/stream.cjs +85 -51
  43. package/dist/cjs/stream.cjs.map +1 -1
  44. package/dist/cjs/tools/ToolNode.cjs +10 -4
  45. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  46. package/dist/cjs/tools/handlers.cjs +119 -13
  47. package/dist/cjs/tools/handlers.cjs.map +1 -1
  48. package/dist/cjs/tools/search/anthropic.cjs +40 -0
  49. package/dist/cjs/tools/search/anthropic.cjs.map +1 -0
  50. package/dist/cjs/tools/search/firecrawl.cjs +55 -9
  51. package/dist/cjs/tools/search/firecrawl.cjs.map +1 -1
  52. package/dist/cjs/tools/search/format.cjs +6 -6
  53. package/dist/cjs/tools/search/format.cjs.map +1 -1
  54. package/dist/cjs/tools/search/rerankers.cjs +7 -29
  55. package/dist/cjs/tools/search/rerankers.cjs.map +1 -1
  56. package/dist/cjs/tools/search/search.cjs +86 -16
  57. package/dist/cjs/tools/search/search.cjs.map +1 -1
  58. package/dist/cjs/tools/search/tool.cjs +4 -2
  59. package/dist/cjs/tools/search/tool.cjs.map +1 -1
  60. package/dist/cjs/tools/search/utils.cjs +1 -1
  61. package/dist/cjs/tools/search/utils.cjs.map +1 -1
  62. package/dist/cjs/utils/events.cjs +31 -0
  63. package/dist/cjs/utils/events.cjs.map +1 -0
  64. package/dist/cjs/utils/title.cjs +57 -21
  65. package/dist/cjs/utils/title.cjs.map +1 -1
  66. package/dist/cjs/utils/tokens.cjs +54 -7
  67. package/dist/cjs/utils/tokens.cjs.map +1 -1
  68. package/dist/esm/agents/AgentContext.mjs +216 -0
  69. package/dist/esm/agents/AgentContext.mjs.map +1 -0
  70. package/dist/esm/common/enum.mjs +15 -6
  71. package/dist/esm/common/enum.mjs.map +1 -1
  72. package/dist/esm/events.mjs +10 -6
  73. package/dist/esm/events.mjs.map +1 -1
  74. package/dist/esm/graphs/Graph.mjs +311 -214
  75. package/dist/esm/graphs/Graph.mjs.map +1 -1
  76. package/dist/esm/graphs/MultiAgentGraph.mjs +420 -0
  77. package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -0
  78. package/dist/esm/llm/anthropic/index.mjs +54 -9
  79. package/dist/esm/llm/anthropic/index.mjs.map +1 -1
  80. package/dist/esm/llm/anthropic/types.mjs.map +1 -1
  81. package/dist/esm/llm/anthropic/utils/message_inputs.mjs +52 -6
  82. package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
  83. package/dist/esm/llm/anthropic/utils/message_outputs.mjs +22 -2
  84. package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -1
  85. package/dist/esm/llm/anthropic/utils/tools.mjs +27 -0
  86. package/dist/esm/llm/anthropic/utils/tools.mjs.map +1 -0
  87. package/dist/esm/llm/google/index.mjs +142 -0
  88. package/dist/esm/llm/google/index.mjs.map +1 -0
  89. package/dist/esm/llm/google/utils/common.mjs +471 -0
  90. package/dist/esm/llm/google/utils/common.mjs.map +1 -0
  91. package/dist/esm/llm/ollama/index.mjs +65 -0
  92. package/dist/esm/llm/ollama/index.mjs.map +1 -0
  93. package/dist/esm/llm/ollama/utils.mjs +155 -0
  94. package/dist/esm/llm/ollama/utils.mjs.map +1 -0
  95. package/dist/esm/llm/openai/index.mjs +388 -4
  96. package/dist/esm/llm/openai/index.mjs.map +1 -1
  97. package/dist/esm/llm/openai/utils/index.mjs +666 -0
  98. package/dist/esm/llm/openai/utils/index.mjs.map +1 -0
  99. package/dist/esm/llm/providers.mjs +5 -5
  100. package/dist/esm/llm/providers.mjs.map +1 -1
  101. package/dist/esm/llm/text.mjs +14 -3
  102. package/dist/esm/llm/text.mjs.map +1 -1
  103. package/dist/esm/llm/vertexai/index.mjs +328 -0
  104. package/dist/esm/llm/vertexai/index.mjs.map +1 -0
  105. package/dist/esm/main.mjs +6 -5
  106. package/dist/esm/main.mjs.map +1 -1
  107. package/dist/esm/run.mjs +121 -83
  108. package/dist/esm/run.mjs.map +1 -1
  109. package/dist/esm/stream.mjs +87 -54
  110. package/dist/esm/stream.mjs.map +1 -1
  111. package/dist/esm/tools/ToolNode.mjs +10 -4
  112. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  113. package/dist/esm/tools/handlers.mjs +119 -15
  114. package/dist/esm/tools/handlers.mjs.map +1 -1
  115. package/dist/esm/tools/search/anthropic.mjs +37 -0
  116. package/dist/esm/tools/search/anthropic.mjs.map +1 -0
  117. package/dist/esm/tools/search/firecrawl.mjs +55 -9
  118. package/dist/esm/tools/search/firecrawl.mjs.map +1 -1
  119. package/dist/esm/tools/search/format.mjs +7 -7
  120. package/dist/esm/tools/search/format.mjs.map +1 -1
  121. package/dist/esm/tools/search/rerankers.mjs +7 -29
  122. package/dist/esm/tools/search/rerankers.mjs.map +1 -1
  123. package/dist/esm/tools/search/search.mjs +86 -16
  124. package/dist/esm/tools/search/search.mjs.map +1 -1
  125. package/dist/esm/tools/search/tool.mjs +4 -2
  126. package/dist/esm/tools/search/tool.mjs.map +1 -1
  127. package/dist/esm/tools/search/utils.mjs +1 -1
  128. package/dist/esm/tools/search/utils.mjs.map +1 -1
  129. package/dist/esm/utils/events.mjs +29 -0
  130. package/dist/esm/utils/events.mjs.map +1 -0
  131. package/dist/esm/utils/title.mjs +57 -22
  132. package/dist/esm/utils/title.mjs.map +1 -1
  133. package/dist/esm/utils/tokens.mjs +54 -8
  134. package/dist/esm/utils/tokens.mjs.map +1 -1
  135. package/dist/types/agents/AgentContext.d.ts +91 -0
  136. package/dist/types/common/enum.d.ts +15 -6
  137. package/dist/types/events.d.ts +5 -4
  138. package/dist/types/graphs/Graph.d.ts +64 -67
  139. package/dist/types/graphs/MultiAgentGraph.d.ts +37 -0
  140. package/dist/types/graphs/index.d.ts +1 -0
  141. package/dist/types/llm/anthropic/index.d.ts +11 -0
  142. package/dist/types/llm/anthropic/types.d.ts +9 -3
  143. package/dist/types/llm/anthropic/utils/message_inputs.d.ts +1 -1
  144. package/dist/types/llm/anthropic/utils/output_parsers.d.ts +4 -4
  145. package/dist/types/llm/anthropic/utils/tools.d.ts +3 -0
  146. package/dist/types/llm/google/index.d.ts +13 -0
  147. package/dist/types/llm/google/types.d.ts +32 -0
  148. package/dist/types/llm/google/utils/common.d.ts +19 -0
  149. package/dist/types/llm/google/utils/tools.d.ts +10 -0
  150. package/dist/types/llm/google/utils/zod_to_genai_parameters.d.ts +14 -0
  151. package/dist/types/llm/ollama/index.d.ts +7 -0
  152. package/dist/types/llm/ollama/utils.d.ts +7 -0
  153. package/dist/types/llm/openai/index.d.ts +72 -3
  154. package/dist/types/llm/openai/types.d.ts +10 -0
  155. package/dist/types/llm/openai/utils/index.d.ts +20 -0
  156. package/dist/types/llm/text.d.ts +1 -1
  157. package/dist/types/llm/vertexai/index.d.ts +293 -0
  158. package/dist/types/messages/reducer.d.ts +9 -0
  159. package/dist/types/run.d.ts +19 -12
  160. package/dist/types/scripts/ant_web_search.d.ts +1 -0
  161. package/dist/types/scripts/args.d.ts +2 -1
  162. package/dist/types/scripts/handoff-test.d.ts +1 -0
  163. package/dist/types/scripts/multi-agent-conditional.d.ts +1 -0
  164. package/dist/types/scripts/multi-agent-parallel.d.ts +1 -0
  165. package/dist/types/scripts/multi-agent-sequence.d.ts +1 -0
  166. package/dist/types/scripts/multi-agent-supervisor.d.ts +1 -0
  167. package/dist/types/scripts/multi-agent-test.d.ts +1 -0
  168. package/dist/types/scripts/test-custom-prompt-key.d.ts +2 -0
  169. package/dist/types/scripts/test-handoff-input.d.ts +2 -0
  170. package/dist/types/scripts/test-multi-agent-list-handoff.d.ts +2 -0
  171. package/dist/types/stream.d.ts +10 -3
  172. package/dist/types/tools/CodeExecutor.d.ts +2 -2
  173. package/dist/types/tools/ToolNode.d.ts +1 -1
  174. package/dist/types/tools/handlers.d.ts +17 -4
  175. package/dist/types/tools/search/anthropic.d.ts +16 -0
  176. package/dist/types/tools/search/firecrawl.d.ts +15 -0
  177. package/dist/types/tools/search/rerankers.d.ts +0 -1
  178. package/dist/types/tools/search/types.d.ts +30 -9
  179. package/dist/types/types/graph.d.ts +129 -15
  180. package/dist/types/types/llm.d.ts +24 -10
  181. package/dist/types/types/run.d.ts +46 -8
  182. package/dist/types/types/stream.d.ts +16 -2
  183. package/dist/types/types/tools.d.ts +1 -1
  184. package/dist/types/utils/events.d.ts +6 -0
  185. package/dist/types/utils/title.d.ts +2 -1
  186. package/dist/types/utils/tokens.d.ts +24 -0
  187. package/package.json +37 -17
  188. package/src/agents/AgentContext.ts +315 -0
  189. package/src/common/enum.ts +14 -5
  190. package/src/events.ts +24 -13
  191. package/src/graphs/Graph.ts +495 -312
  192. package/src/graphs/MultiAgentGraph.ts +498 -0
  193. package/src/graphs/index.ts +2 -1
  194. package/src/llm/anthropic/Jacob_Lee_Resume_2023.pdf +0 -0
  195. package/src/llm/anthropic/index.ts +78 -13
  196. package/src/llm/anthropic/llm.spec.ts +491 -115
  197. package/src/llm/anthropic/types.ts +39 -3
  198. package/src/llm/anthropic/utils/message_inputs.ts +67 -11
  199. package/src/llm/anthropic/utils/message_outputs.ts +21 -2
  200. package/src/llm/anthropic/utils/output_parsers.ts +25 -6
  201. package/src/llm/anthropic/utils/tools.ts +29 -0
  202. package/src/llm/google/index.ts +218 -0
  203. package/src/llm/google/types.ts +43 -0
  204. package/src/llm/google/utils/common.ts +646 -0
  205. package/src/llm/google/utils/tools.ts +160 -0
  206. package/src/llm/google/utils/zod_to_genai_parameters.ts +86 -0
  207. package/src/llm/ollama/index.ts +89 -0
  208. package/src/llm/ollama/utils.ts +193 -0
  209. package/src/llm/openai/index.ts +600 -14
  210. package/src/llm/openai/types.ts +24 -0
  211. package/src/llm/openai/utils/index.ts +912 -0
  212. package/src/llm/openai/utils/isReasoningModel.test.ts +90 -0
  213. package/src/llm/providers.ts +10 -9
  214. package/src/llm/text.ts +26 -7
  215. package/src/llm/vertexai/index.ts +360 -0
  216. package/src/messages/reducer.ts +80 -0
  217. package/src/run.ts +181 -112
  218. package/src/scripts/ant_web_search.ts +158 -0
  219. package/src/scripts/args.ts +12 -8
  220. package/src/scripts/cli4.ts +29 -21
  221. package/src/scripts/cli5.ts +29 -21
  222. package/src/scripts/code_exec.ts +54 -23
  223. package/src/scripts/code_exec_files.ts +48 -17
  224. package/src/scripts/code_exec_simple.ts +46 -27
  225. package/src/scripts/handoff-test.ts +135 -0
  226. package/src/scripts/image.ts +52 -20
  227. package/src/scripts/multi-agent-conditional.ts +220 -0
  228. package/src/scripts/multi-agent-example-output.md +110 -0
  229. package/src/scripts/multi-agent-parallel.ts +341 -0
  230. package/src/scripts/multi-agent-sequence.ts +212 -0
  231. package/src/scripts/multi-agent-supervisor.ts +361 -0
  232. package/src/scripts/multi-agent-test.ts +186 -0
  233. package/src/scripts/search.ts +1 -9
  234. package/src/scripts/simple.ts +25 -10
  235. package/src/scripts/test-custom-prompt-key.ts +145 -0
  236. package/src/scripts/test-handoff-input.ts +110 -0
  237. package/src/scripts/test-multi-agent-list-handoff.ts +258 -0
  238. package/src/scripts/tools.ts +48 -18
  239. package/src/specs/anthropic.simple.test.ts +150 -34
  240. package/src/specs/azure.simple.test.ts +325 -0
  241. package/src/specs/openai.simple.test.ts +140 -33
  242. package/src/specs/openrouter.simple.test.ts +107 -0
  243. package/src/specs/prune.test.ts +4 -9
  244. package/src/specs/reasoning.test.ts +80 -44
  245. package/src/specs/token-memoization.test.ts +39 -0
  246. package/src/stream.test.ts +94 -0
  247. package/src/stream.ts +139 -60
  248. package/src/tools/ToolNode.ts +21 -7
  249. package/src/tools/handlers.ts +192 -18
  250. package/src/tools/search/anthropic.ts +51 -0
  251. package/src/tools/search/firecrawl.ts +69 -20
  252. package/src/tools/search/format.ts +6 -8
  253. package/src/tools/search/rerankers.ts +7 -40
  254. package/src/tools/search/search.ts +97 -16
  255. package/src/tools/search/tool.ts +5 -2
  256. package/src/tools/search/types.ts +30 -10
  257. package/src/tools/search/utils.ts +1 -1
  258. package/src/types/graph.ts +315 -103
  259. package/src/types/llm.ts +25 -12
  260. package/src/types/run.ts +51 -13
  261. package/src/types/stream.ts +22 -1
  262. package/src/types/tools.ts +16 -10
  263. package/src/utils/events.ts +32 -0
  264. package/src/utils/llmConfig.ts +19 -7
  265. package/src/utils/title.ts +104 -30
  266. package/src/utils/tokens.ts +69 -10
@@ -1,77 +1,241 @@
1
1
  // src/types/graph.ts
2
- import type { StateGraphArgs, StateGraph, CompiledStateGraph } from '@langchain/langgraph';
3
- import type { BaseMessage, AIMessageChunk } from '@langchain/core/messages';
2
+ import type {
3
+ START,
4
+ StateType,
5
+ UpdateType,
6
+ StateGraph,
7
+ StateGraphArgs,
8
+ StateDefinition,
9
+ CompiledStateGraph,
10
+ BinaryOperatorAggregate,
11
+ } from '@langchain/langgraph';
12
+ import type { BindToolsInput } from '@langchain/core/language_models/chat_models';
13
+ import type {
14
+ BaseMessage,
15
+ AIMessageChunk,
16
+ SystemMessage,
17
+ } from '@langchain/core/messages';
18
+ import type { RunnableConfig, Runnable } from '@langchain/core/runnables';
4
19
  import type { ChatGenerationChunk } from '@langchain/core/outputs';
5
- import type { RunnableConfig } from '@langchain/core/runnables';
6
- import type { ToolMap, GenericTool } from '@/types/tools';
20
+ import type { GoogleAIToolType } from '@langchain/google-common';
21
+ import type { ToolMap, ToolEndEvent, GenericTool } from '@/types/tools';
22
+ import type { Providers, Callback, GraphNodeKeys } from '@/common';
23
+ import type { StandardGraph, MultiAgentGraph } from '@/graphs';
7
24
  import type { ClientOptions } from '@/types/llm';
8
- import type { Providers } from '@/common';
9
- import type { Graph } from '@/graphs';
10
- // import type { RunnableConfig } from '@langchain/core/runnables';
25
+ import type {
26
+ RunStep,
27
+ RunStepDeltaEvent,
28
+ MessageDeltaEvent,
29
+ ReasoningDeltaEvent,
30
+ } from '@/types/stream';
31
+ import type { TokenCounter } from '@/types/run';
32
+
33
+ /** Interface for bound model with stream and invoke methods */
34
+ export interface ChatModel {
35
+ stream?: (
36
+ messages: BaseMessage[],
37
+ config?: RunnableConfig
38
+ ) => Promise<AsyncIterable<AIMessageChunk>>;
39
+ invoke: (
40
+ messages: BaseMessage[],
41
+ config?: RunnableConfig
42
+ ) => Promise<AIMessageChunk>;
43
+ }
44
+
45
+ export type GraphNode = GraphNodeKeys | typeof START;
46
+ export type ClientCallback<T extends unknown[]> = (
47
+ graph: StandardGraph,
48
+ ...args: T
49
+ ) => void;
50
+
51
+ export type ClientCallbacks = {
52
+ [Callback.TOOL_ERROR]?: ClientCallback<[Error, string]>;
53
+ [Callback.TOOL_START]?: ClientCallback<unknown[]>;
54
+ [Callback.TOOL_END]?: ClientCallback<unknown[]>;
55
+ };
56
+
57
+ export type SystemCallbacks = {
58
+ [K in keyof ClientCallbacks]: ClientCallbacks[K] extends ClientCallback<
59
+ infer Args
60
+ >
61
+ ? (...args: Args) => void
62
+ : never;
63
+ };
11
64
 
12
65
  export type BaseGraphState = {
13
66
  messages: BaseMessage[];
14
- // [key: string]: unknown;
15
67
  };
16
68
 
17
- export type IState = BaseGraphState;
69
+ export type MultiAgentGraphState = BaseGraphState & {
70
+ agentMessages?: BaseMessage[];
71
+ };
18
72
 
19
- // export interface IState extends BaseGraphState {
20
- // instructions?: string;
21
- // additional_instructions?: string;
22
- // }
73
+ export type IState = BaseGraphState;
23
74
 
24
75
  export interface EventHandler {
25
- handle(event: string, data: StreamEventData | ModelEndData, metadata?: Record<string, unknown>, graph?: Graph): void;
76
+ handle(
77
+ event: string,
78
+ data:
79
+ | StreamEventData
80
+ | ModelEndData
81
+ | RunStep
82
+ | RunStepDeltaEvent
83
+ | MessageDeltaEvent
84
+ | ReasoningDeltaEvent
85
+ | { result: ToolEndEvent },
86
+ metadata?: Record<string, unknown>,
87
+ graph?: StandardGraph | MultiAgentGraph
88
+ ): void | Promise<void>;
26
89
  }
27
90
 
28
- export type GraphStateChannels<T extends BaseGraphState> = StateGraphArgs<T>['channels'];
91
+ export type GraphStateChannels<T extends BaseGraphState> =
92
+ StateGraphArgs<T>['channels'];
93
+
94
+ export type Workflow<
95
+ T extends BaseGraphState = BaseGraphState,
96
+ U extends Partial<T> = Partial<T>,
97
+ N extends string = string,
98
+ > = StateGraph<T, U, N>;
99
+
100
+ export type CompiledWorkflow<
101
+ T extends BaseGraphState = BaseGraphState,
102
+ U extends Partial<T> = Partial<T>,
103
+ N extends string = string,
104
+ > = CompiledStateGraph<T, U, N>;
105
+
106
+ export type CompiledStateWorkflow = CompiledStateGraph<
107
+ StateType<{
108
+ messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
109
+ }>,
110
+ UpdateType<{
111
+ messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
112
+ }>,
113
+ string,
114
+ {
115
+ messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
116
+ },
117
+ {
118
+ messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
119
+ },
120
+ StateDefinition
121
+ >;
122
+
123
+ export type CompiledMultiAgentWorkflow = CompiledStateGraph<
124
+ StateType<{
125
+ messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
126
+ agentMessages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
127
+ }>,
128
+ UpdateType<{
129
+ messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
130
+ agentMessages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
131
+ }>,
132
+ string,
133
+ {
134
+ messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
135
+ agentMessages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
136
+ },
137
+ {
138
+ messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
139
+ agentMessages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
140
+ },
141
+ StateDefinition
142
+ >;
29
143
 
30
- export type Workflow<T extends BaseGraphState = BaseGraphState, U extends Partial<T> = Partial<T>, N extends string = string> = StateGraph<T, U, N>;
144
+ export type CompiledAgentWorfklow = CompiledStateGraph<
145
+ {
146
+ messages: BaseMessage[];
147
+ },
148
+ {
149
+ messages?: BaseMessage[] | undefined;
150
+ },
151
+ '__start__' | `agent=${string}` | `tools=${string}`,
152
+ {
153
+ messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
154
+ },
155
+ {
156
+ messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
157
+ },
158
+ StateDefinition,
159
+ {
160
+ [x: `agent=${string}`]: Partial<BaseGraphState>;
161
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
162
+ [x: `tools=${string}`]: any;
163
+ }
164
+ >;
31
165
 
32
- export type CompiledWorkflow<T extends BaseGraphState = BaseGraphState, U extends Partial<T> = Partial<T>, N extends string = string> = CompiledStateGraph<T, U, N>;
166
+ export type SystemRunnable =
167
+ | Runnable<
168
+ BaseMessage[],
169
+ (BaseMessage | SystemMessage)[],
170
+ RunnableConfig<Record<string, unknown>>
171
+ >
172
+ | undefined;
33
173
 
34
- export type EventStreamCallbackHandlerInput = Parameters<CompiledWorkflow['streamEvents']>[2] extends Omit<infer T, 'autoClose'> ? T : never;
174
+ /**
175
+ * Optional compile options passed to workflow.compile().
176
+ * These are intentionally untyped to avoid coupling to library internals.
177
+ */
178
+ export type CompileOptions = {
179
+ // A checkpointer instance (e.g., MemorySaver, SQL saver)
180
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
181
+ checkpointer?: any;
182
+ interruptBefore?: string[];
183
+ interruptAfter?: string[];
184
+ };
185
+
186
+ export type EventStreamCallbackHandlerInput =
187
+ Parameters<CompiledWorkflow['streamEvents']>[2] extends Omit<
188
+ infer T,
189
+ 'autoClose'
190
+ >
191
+ ? T
192
+ : never;
35
193
 
36
- export type StreamChunk = ChatGenerationChunk & {
37
- message: AIMessageChunk;
38
- } | AIMessageChunk;
194
+ export type StreamChunk =
195
+ | (ChatGenerationChunk & {
196
+ message: AIMessageChunk;
197
+ })
198
+ | AIMessageChunk;
39
199
 
40
200
  /**
41
201
  * Data associated with a StreamEvent.
42
202
  */
43
203
  export type StreamEventData = {
44
- /**
45
- * The input passed to the runnable that generated the event.
46
- * Inputs will sometimes be available at the *START* of the runnable, and
47
- * sometimes at the *END* of the runnable.
48
- * If a runnable is able to stream its inputs, then its input by definition
49
- * won't be known until the *END* of the runnable when it has finished streaming
50
- * its inputs.
51
- */
52
- input?: unknown;
53
- /**
54
- * The output of the runnable that generated the event.
55
- * Outputs will only be available at the *END* of the runnable.
56
- * For most runnables, this field can be inferred from the `chunk` field,
57
- * though there might be some exceptions for special cased runnables (e.g., like
58
- * chat models), which may return more information.
59
- */
60
- output?: unknown;
61
- /**
62
- * A streaming chunk from the output that generated the event.
63
- * chunks support addition in general, and adding them up should result
64
- * in the output of the runnable that generated the event.
65
- */
66
- chunk?: StreamChunk;
67
- /**
68
- * Runnable config for invoking other runnables within handlers.
69
- */
70
- config?: RunnableConfig;
71
- /**
72
- * Custom result from the runnable that generated the event.
73
- */
74
- result?: unknown;
204
+ /**
205
+ * The input passed to the runnable that generated the event.
206
+ * Inputs will sometimes be available at the *START* of the runnable, and
207
+ * sometimes at the *END* of the runnable.
208
+ * If a runnable is able to stream its inputs, then its input by definition
209
+ * won't be known until the *END* of the runnable when it has finished streaming
210
+ * its inputs.
211
+ */
212
+ input?: unknown;
213
+ /**
214
+ * The output of the runnable that generated the event.
215
+ * Outputs will only be available at the *END* of the runnable.
216
+ * For most runnables, this field can be inferred from the `chunk` field,
217
+ * though there might be some exceptions for special cased runnables (e.g., like
218
+ * chat models), which may return more information.
219
+ */
220
+ output?: unknown;
221
+ /**
222
+ * A streaming chunk from the output that generated the event.
223
+ * chunks support addition in general, and adding them up should result
224
+ * in the output of the runnable that generated the event.
225
+ */
226
+ chunk?: StreamChunk;
227
+ /**
228
+ * Runnable config for invoking other runnables within handlers.
229
+ */
230
+ config?: RunnableConfig;
231
+ /**
232
+ * Custom result from the runnable that generated the event.
233
+ */
234
+ result?: unknown;
235
+ /**
236
+ * Custom field to indicate the event was manually emitted, and may have been handled already
237
+ */
238
+ emitted?: boolean;
75
239
  };
76
240
 
77
241
  /**
@@ -80,54 +244,54 @@ export type StreamEventData = {
80
244
  * Schema of a streaming event which is produced from the streamEvents method.
81
245
  */
82
246
  export type StreamEvent = {
83
- /**
84
- * Event names are of the format: on_[runnable_type]_(start|stream|end).
85
- *
86
- * Runnable types are one of:
87
- * - llm - used by non chat models
88
- * - chat_model - used by chat models
89
- * - prompt -- e.g., ChatPromptTemplate
90
- * - tool -- LangChain tools
91
- * - chain - most Runnables are of this type
92
- *
93
- * Further, the events are categorized as one of:
94
- * - start - when the runnable starts
95
- * - stream - when the runnable is streaming
96
- * - end - when the runnable ends
97
- *
98
- * start, stream and end are associated with slightly different `data` payload.
99
- *
100
- * Please see the documentation for `EventData` for more details.
101
- */
102
- event: string;
103
- /** The name of the runnable that generated the event. */
104
- name: string;
105
- /**
106
- * An randomly generated ID to keep track of the execution of the given runnable.
107
- *
108
- * Each child runnable that gets invoked as part of the execution of a parent runnable
109
- * is assigned its own unique ID.
110
- */
111
- run_id: string;
112
- /**
113
- * Tags associated with the runnable that generated this event.
114
- * Tags are always inherited from parent runnables.
115
- */
116
- tags?: string[];
117
- /** Metadata associated with the runnable that generated this event. */
118
- metadata: Record<string, unknown>;
119
- /**
120
- * Event data.
121
- *
122
- * The contents of the event data depend on the event type.
123
- */
124
- data: StreamEventData;
247
+ /**
248
+ * Event names are of the format: on_[runnable_type]_(start|stream|end).
249
+ *
250
+ * Runnable types are one of:
251
+ * - llm - used by non chat models
252
+ * - chat_model - used by chat models
253
+ * - prompt -- e.g., ChatPromptTemplate
254
+ * - tool -- LangChain tools
255
+ * - chain - most Runnables are of this type
256
+ *
257
+ * Further, the events are categorized as one of:
258
+ * - start - when the runnable starts
259
+ * - stream - when the runnable is streaming
260
+ * - end - when the runnable ends
261
+ *
262
+ * start, stream and end are associated with slightly different `data` payload.
263
+ *
264
+ * Please see the documentation for `EventData` for more details.
265
+ */
266
+ event: string;
267
+ /** The name of the runnable that generated the event. */
268
+ name: string;
269
+ /**
270
+ * An randomly generated ID to keep track of the execution of the given runnable.
271
+ *
272
+ * Each child runnable that gets invoked as part of the execution of a parent runnable
273
+ * is assigned its own unique ID.
274
+ */
275
+ run_id: string;
276
+ /**
277
+ * Tags associated with the runnable that generated this event.
278
+ * Tags are always inherited from parent runnables.
279
+ */
280
+ tags?: string[];
281
+ /** Metadata associated with the runnable that generated this event. */
282
+ metadata: Record<string, unknown>;
283
+ /**
284
+ * Event data.
285
+ *
286
+ * The contents of the event data depend on the event type.
287
+ */
288
+ data: StreamEventData;
125
289
  };
126
290
 
127
291
  export type GraphConfig = {
128
- provider: string;
129
- thread_id?: string;
130
- run_id?: string;
292
+ provider: string;
293
+ thread_id?: string;
294
+ run_id?: string;
131
295
  };
132
296
 
133
297
  export type PartMetadata = {
@@ -138,18 +302,66 @@ export type PartMetadata = {
138
302
  output?: string;
139
303
  };
140
304
 
141
- export type ModelEndData = StreamEventData & { output: AIMessageChunk | undefined } | undefined;
142
-
305
+ export type ModelEndData =
306
+ | (StreamEventData & { output: AIMessageChunk | undefined })
307
+ | undefined;
308
+ export type GraphTools = GenericTool[] | BindToolsInput[] | GoogleAIToolType[];
143
309
  export type StandardGraphInput = {
144
310
  runId?: string;
311
+ signal?: AbortSignal;
312
+ agents: AgentInputs[];
313
+ tokenCounter?: TokenCounter;
314
+ indexTokenCountMap?: Record<string, number>;
315
+ };
316
+
317
+ export type GraphEdge = {
318
+ /** Agent ID, use a list for multiple sources */
319
+ from: string | string[];
320
+ /** Agent ID, use a list for multiple destinations */
321
+ to: string | string[];
322
+ description?: string;
323
+ /** Can return boolean or specific destination(s) */
324
+ condition?: (state: BaseGraphState) => boolean | string | string[];
325
+ /** 'handoff' creates tools for dynamic routing, 'direct' creates direct edges, which also allow parallel execution */
326
+ edgeType?: 'handoff' | 'direct';
327
+ /**
328
+ * For direct edges: Optional prompt to add when transitioning through this edge.
329
+ * String prompts can include variables like {results} which will be replaced with
330
+ * messages from startIndex onwards. When {results} is used, excludeResults defaults to true.
331
+ *
332
+ * For handoff edges: Description for the input parameter that the handoff tool accepts,
333
+ * allowing the supervisor to pass specific instructions/context to the transferred agent.
334
+ */
335
+ prompt?:
336
+ | string
337
+ | ((messages: BaseMessage[], runStartIndex: number) => string | undefined);
338
+ /**
339
+ * When true, excludes messages from startIndex when adding prompt.
340
+ * Automatically set to true when {results} variable is used in prompt.
341
+ */
342
+ excludeResults?: boolean;
343
+ /**
344
+ * For handoff edges: Customizes the parameter name for the handoff input.
345
+ * Defaults to "instructions" if not specified.
346
+ * Only applies when prompt is provided for handoff edges.
347
+ */
348
+ promptKey?: string;
349
+ };
350
+
351
+ export type MultiAgentGraphInput = StandardGraphInput & {
352
+ edges: GraphEdge[];
353
+ };
354
+
355
+ export interface AgentInputs {
356
+ agentId: string;
145
357
  toolEnd?: boolean;
146
358
  toolMap?: ToolMap;
359
+ tools?: GraphTools;
147
360
  provider: Providers;
148
- signal?: AbortSignal;
149
361
  instructions?: string;
150
362
  streamBuffer?: number;
151
- tools?: GenericTool[];
152
- clientOptions: ClientOptions;
363
+ maxContextTokens?: number;
364
+ clientOptions?: ClientOptions;
153
365
  additional_instructions?: string;
154
366
  reasoningKey?: 'reasoning_content' | 'reasoning';
155
- };
367
+ }
package/src/types/llm.ts CHANGED
@@ -1,10 +1,7 @@
1
1
  // src/types/llm.ts
2
2
  import { ChatOllama } from '@langchain/ollama';
3
- import { ChatAnthropic } from '@langchain/anthropic';
4
3
  import { ChatMistralAI } from '@langchain/mistralai';
5
4
  import { ChatBedrockConverse } from '@langchain/aws';
6
- import { ChatVertexAI } from '@langchain/google-vertexai';
7
- import { ChatGoogleGenerativeAI } from '@langchain/google-genai';
8
5
  import { BedrockChat } from '@langchain/community/chat_models/bedrock/web';
9
6
  import type {
10
7
  BindToolsInput,
@@ -18,11 +15,13 @@ import type {
18
15
  } from '@langchain/openai';
19
16
  import type { BedrockChatFields } from '@langchain/community/chat_models/bedrock/web';
20
17
  import type { GoogleGenerativeAIChatInput } from '@langchain/google-genai';
18
+ import type { GeminiGenerationConfig } from '@langchain/google-common';
21
19
  import type { ChatVertexAIInput } from '@langchain/google-vertexai';
22
20
  import type { ChatDeepSeekCallOptions } from '@langchain/deepseek';
23
21
  import type { ChatOpenRouterCallOptions } from '@/llm/openrouter';
24
22
  import type { ChatBedrockConverseInput } from '@langchain/aws';
25
23
  import type { ChatMistralAIInput } from '@langchain/mistralai';
24
+ import type { RequestOptions } from '@google/generative-ai';
26
25
  import type { StructuredTool } from '@langchain/core/tools';
27
26
  import type { AnthropicInput } from '@langchain/anthropic';
28
27
  import type { Runnable } from '@langchain/core/runnables';
@@ -30,12 +29,15 @@ import type { ChatOllamaInput } from '@langchain/ollama';
30
29
  import type { OpenAI as OpenAIClient } from 'openai';
31
30
  import type { ChatXAIInput } from '@langchain/xai';
32
31
  import {
33
- ChatXAI,
34
- ChatOpenAI,
35
- ChatDeepSeek,
36
32
  AzureChatOpenAI,
33
+ ChatDeepSeek,
34
+ ChatOpenAI,
35
+ ChatXAI,
37
36
  } from '@/llm/openai';
37
+ import { CustomChatGoogleGenerativeAI } from '@/llm/google';
38
+ import { CustomAnthropic } from '@/llm/anthropic';
38
39
  import { ChatOpenRouter } from '@/llm/openrouter';
40
+ import { ChatVertexAI } from '@/llm/vertexai';
39
41
  import { Providers } from '@/common';
40
42
 
41
43
  export type AzureClientOptions = Partial<OpenAIChatInput> &
@@ -60,14 +62,19 @@ export type OpenAIClientOptions = ChatOpenAIFields;
60
62
  export type OllamaClientOptions = ChatOllamaInput;
61
63
  export type AnthropicClientOptions = AnthropicInput;
62
64
  export type MistralAIClientOptions = ChatMistralAIInput;
63
- export type VertexAIClientOptions = ChatVertexAIInput;
65
+ export type VertexAIClientOptions = ChatVertexAIInput & {
66
+ includeThoughts?: boolean;
67
+ };
64
68
  export type BedrockClientOptions = BedrockChatFields;
65
69
  export type BedrockAnthropicInput = ChatBedrockConverseInput & {
66
70
  additionalModelRequestFields?: ChatBedrockConverseInput['additionalModelRequestFields'] &
67
71
  AnthropicReasoning;
68
72
  };
69
73
  export type BedrockConverseClientOptions = ChatBedrockConverseInput;
70
- export type GoogleClientOptions = GoogleGenerativeAIChatInput;
74
+ export type GoogleClientOptions = GoogleGenerativeAIChatInput & {
75
+ customHeaders?: RequestOptions['customHeaders'];
76
+ thinkingConfig?: GeminiGenerationConfig['thinkingConfig'];
77
+ };
71
78
  export type DeepSeekClientOptions = ChatDeepSeekCallOptions;
72
79
  export type XAIClientOptions = ChatXAIInput;
73
80
 
@@ -84,9 +91,15 @@ export type ClientOptions =
84
91
  | DeepSeekClientOptions
85
92
  | XAIClientOptions;
86
93
 
87
- export type LLMConfig = {
94
+ export type SharedLLMConfig = {
88
95
  provider: Providers;
89
- } & ClientOptions;
96
+ };
97
+
98
+ export type LLMConfig = SharedLLMConfig &
99
+ ClientOptions & {
100
+ /** Optional provider fallbacks in order of attempt */
101
+ fallbacks?: Array<{ provider: Providers; clientOptions?: ClientOptions }>;
102
+ };
90
103
 
91
104
  export type ProviderOptionsMap = {
92
105
  [Providers.AZURE]: AzureClientOptions;
@@ -111,13 +124,13 @@ export type ChatModelMap = {
111
124
  [Providers.AZURE]: AzureChatOpenAI;
112
125
  [Providers.DEEPSEEK]: ChatDeepSeek;
113
126
  [Providers.VERTEXAI]: ChatVertexAI;
114
- [Providers.ANTHROPIC]: ChatAnthropic;
127
+ [Providers.ANTHROPIC]: CustomAnthropic;
115
128
  [Providers.MISTRALAI]: ChatMistralAI;
116
129
  [Providers.MISTRAL]: ChatMistralAI;
117
130
  [Providers.OPENROUTER]: ChatOpenRouter;
118
131
  [Providers.BEDROCK_LEGACY]: BedrockChat;
119
132
  [Providers.BEDROCK]: ChatBedrockConverse;
120
- [Providers.GOOGLE]: ChatGoogleGenerativeAI;
133
+ [Providers.GOOGLE]: CustomChatGoogleGenerativeAI;
121
134
  };
122
135
 
123
136
  export type ChatModelConstructorMap = {
package/src/types/run.ts CHANGED
@@ -7,7 +7,6 @@ import type {
7
7
  BaseCallbackHandler,
8
8
  CallbackHandlerMethods,
9
9
  } from '@langchain/core/callbacks/base';
10
- import type * as graph from '@/graphs/Graph';
11
10
  import type * as s from '@/types/stream';
12
11
  import type * as e from '@/common/enum';
13
12
  import type * as g from '@/types/graph';
@@ -16,21 +15,58 @@ import type * as l from '@/types/llm';
16
15
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
16
  export type ZodObjectAny = z.ZodObject<any, any, any, any>;
18
17
  export type BaseGraphConfig = {
19
- type?: 'standard';
20
18
  llmConfig: l.LLMConfig;
21
19
  provider?: e.Providers;
22
20
  clientOptions?: l.ClientOptions;
21
+ /** Optional compile options for workflow.compile() */
22
+ compileOptions?: g.CompileOptions;
23
23
  };
24
- export type StandardGraphConfig = BaseGraphConfig &
25
- Omit<g.StandardGraphInput, 'provider' | 'clientOptions'>;
24
+ export type LegacyGraphConfig = BaseGraphConfig & {
25
+ type?: 'standard';
26
+ } & Omit<g.StandardGraphInput, 'provider' | 'clientOptions' | 'agents'> &
27
+ Omit<g.AgentInputs, 'provider' | 'clientOptions' | 'agentId'>;
28
+
29
+ /* Supervised graph (opt-in) */
30
+ export type SupervisedGraphConfig = BaseGraphConfig & {
31
+ type: 'supervised';
32
+ /** Enable supervised router; when false, fall back to standard loop */
33
+ routerEnabled?: boolean;
34
+ /** Table-driven routing policy per stage */
35
+ routingPolicies?: Array<{
36
+ stage: string;
37
+ agents?: string[];
38
+ model?: e.Providers;
39
+ parallel?: boolean;
40
+ /** Optional simple condition on content/tools */
41
+ when?:
42
+ | 'always'
43
+ | 'has_tools'
44
+ | 'no_tools'
45
+ | { includes?: string[]; excludes?: string[] };
46
+ }>;
47
+ /** Opt-in feature flags */
48
+ featureFlags?: {
49
+ multi_model_routing?: boolean;
50
+ fan_out?: boolean;
51
+ fan_out_retries?: number;
52
+ fan_out_backoff_ms?: number;
53
+ fan_out_concurrency?: number;
54
+ };
55
+ /** Optional per-stage model configs */
56
+ models?: Record<string, l.LLMConfig>;
57
+ } & Omit<g.StandardGraphInput, 'provider' | 'clientOptions'>;
26
58
 
27
59
  export type RunTitleOptions = {
28
60
  inputText: string;
61
+ provider: e.Providers;
29
62
  contentParts: (s.MessageContentComplex | undefined)[];
30
63
  titlePrompt?: string;
31
64
  skipLanguage?: boolean;
32
65
  clientOptions?: l.ClientOptions;
33
66
  chainOptions?: Partial<RunnableConfig> | undefined;
67
+ omitOptions?: Set<string>;
68
+ titleMethod?: e.TitleMethod;
69
+ titlePromptTemplate?: string;
34
70
  };
35
71
 
36
72
  export interface AgentStateChannels {
@@ -60,14 +96,20 @@ export type TaskManagerGraphConfig = {
60
96
  supervisorConfig: { systemPrompt?: string; llmConfig: l.LLMConfig };
61
97
  };
62
98
 
99
+ export type MultiAgentGraphConfig = {
100
+ type: 'multi-agent';
101
+ compileOptions?: g.CompileOptions;
102
+ agents: g.AgentInputs[];
103
+ edges: g.GraphEdge[];
104
+ };
105
+
63
106
  export type RunConfig = {
64
107
  runId: string;
65
- graphConfig:
66
- | StandardGraphConfig
67
- | CollaborativeGraphConfig
68
- | TaskManagerGraphConfig;
108
+ graphConfig: LegacyGraphConfig | MultiAgentGraphConfig;
69
109
  customHandlers?: Record<string, g.EventHandler>;
70
110
  returnContent?: boolean;
111
+ tokenCounter?: TokenCounter;
112
+ indexTokenCountMap?: Record<string, number>;
71
113
  };
72
114
 
73
115
  export type ProvidedCallbacks =
@@ -76,10 +118,6 @@ export type ProvidedCallbacks =
76
118
 
77
119
  export type TokenCounter = (message: BaseMessage) => number;
78
120
  export type EventStreamOptions = {
79
- callbacks?: graph.ClientCallbacks;
121
+ callbacks?: g.ClientCallbacks;
80
122
  keepContent?: boolean;
81
- /* Context Management */
82
- maxContextTokens?: number;
83
- tokenCounter?: TokenCounter;
84
- indexTokenCountMap?: Record<string, number>;
85
123
  };