@librechat/agents 2.4.322 → 3.0.0-rc1

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 (258) 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 +322 -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 +320 -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-test.d.ts +1 -0
  167. package/dist/types/stream.d.ts +10 -3
  168. package/dist/types/tools/CodeExecutor.d.ts +2 -2
  169. package/dist/types/tools/ToolNode.d.ts +1 -1
  170. package/dist/types/tools/handlers.d.ts +17 -4
  171. package/dist/types/tools/search/anthropic.d.ts +16 -0
  172. package/dist/types/tools/search/firecrawl.d.ts +15 -0
  173. package/dist/types/tools/search/rerankers.d.ts +0 -1
  174. package/dist/types/tools/search/types.d.ts +30 -9
  175. package/dist/types/types/graph.d.ts +95 -15
  176. package/dist/types/types/llm.d.ts +24 -10
  177. package/dist/types/types/run.d.ts +46 -8
  178. package/dist/types/types/stream.d.ts +16 -2
  179. package/dist/types/types/tools.d.ts +1 -1
  180. package/dist/types/utils/events.d.ts +6 -0
  181. package/dist/types/utils/title.d.ts +2 -1
  182. package/dist/types/utils/tokens.d.ts +24 -0
  183. package/package.json +33 -17
  184. package/src/agents/AgentContext.ts +315 -0
  185. package/src/common/enum.ts +14 -5
  186. package/src/events.ts +24 -13
  187. package/src/graphs/Graph.ts +495 -312
  188. package/src/graphs/MultiAgentGraph.ts +381 -0
  189. package/src/graphs/index.ts +2 -1
  190. package/src/llm/anthropic/Jacob_Lee_Resume_2023.pdf +0 -0
  191. package/src/llm/anthropic/index.ts +78 -13
  192. package/src/llm/anthropic/llm.spec.ts +491 -115
  193. package/src/llm/anthropic/types.ts +39 -3
  194. package/src/llm/anthropic/utils/message_inputs.ts +67 -11
  195. package/src/llm/anthropic/utils/message_outputs.ts +21 -2
  196. package/src/llm/anthropic/utils/output_parsers.ts +25 -6
  197. package/src/llm/anthropic/utils/tools.ts +29 -0
  198. package/src/llm/google/index.ts +218 -0
  199. package/src/llm/google/types.ts +43 -0
  200. package/src/llm/google/utils/common.ts +646 -0
  201. package/src/llm/google/utils/tools.ts +160 -0
  202. package/src/llm/google/utils/zod_to_genai_parameters.ts +86 -0
  203. package/src/llm/ollama/index.ts +89 -0
  204. package/src/llm/ollama/utils.ts +193 -0
  205. package/src/llm/openai/index.ts +600 -14
  206. package/src/llm/openai/types.ts +24 -0
  207. package/src/llm/openai/utils/index.ts +912 -0
  208. package/src/llm/openai/utils/isReasoningModel.test.ts +90 -0
  209. package/src/llm/providers.ts +10 -9
  210. package/src/llm/text.ts +26 -7
  211. package/src/llm/vertexai/index.ts +360 -0
  212. package/src/messages/reducer.ts +80 -0
  213. package/src/run.ts +181 -112
  214. package/src/scripts/ant_web_search.ts +158 -0
  215. package/src/scripts/args.ts +12 -8
  216. package/src/scripts/cli4.ts +29 -21
  217. package/src/scripts/cli5.ts +29 -21
  218. package/src/scripts/code_exec.ts +54 -23
  219. package/src/scripts/code_exec_files.ts +48 -17
  220. package/src/scripts/code_exec_simple.ts +46 -27
  221. package/src/scripts/handoff-test.ts +135 -0
  222. package/src/scripts/image.ts +52 -20
  223. package/src/scripts/multi-agent-conditional.ts +220 -0
  224. package/src/scripts/multi-agent-example-output.md +110 -0
  225. package/src/scripts/multi-agent-parallel.ts +337 -0
  226. package/src/scripts/multi-agent-sequence.ts +212 -0
  227. package/src/scripts/multi-agent-test.ts +186 -0
  228. package/src/scripts/search.ts +1 -9
  229. package/src/scripts/simple.ts +25 -10
  230. package/src/scripts/tools.ts +48 -18
  231. package/src/specs/anthropic.simple.test.ts +150 -34
  232. package/src/specs/azure.simple.test.ts +325 -0
  233. package/src/specs/openai.simple.test.ts +140 -33
  234. package/src/specs/openrouter.simple.test.ts +107 -0
  235. package/src/specs/prune.test.ts +4 -9
  236. package/src/specs/reasoning.test.ts +80 -44
  237. package/src/specs/token-memoization.test.ts +39 -0
  238. package/src/stream.test.ts +94 -0
  239. package/src/stream.ts +139 -60
  240. package/src/tools/ToolNode.ts +21 -7
  241. package/src/tools/handlers.ts +192 -18
  242. package/src/tools/search/anthropic.ts +51 -0
  243. package/src/tools/search/firecrawl.ts +69 -20
  244. package/src/tools/search/format.ts +6 -8
  245. package/src/tools/search/rerankers.ts +7 -40
  246. package/src/tools/search/search.ts +97 -16
  247. package/src/tools/search/tool.ts +5 -2
  248. package/src/tools/search/types.ts +30 -10
  249. package/src/tools/search/utils.ts +1 -1
  250. package/src/types/graph.ts +272 -103
  251. package/src/types/llm.ts +25 -12
  252. package/src/types/run.ts +51 -13
  253. package/src/types/stream.ts +22 -1
  254. package/src/types/tools.ts +16 -10
  255. package/src/utils/events.ts +32 -0
  256. package/src/utils/llmConfig.ts +19 -7
  257. package/src/utils/title.ts +104 -30
  258. package/src/utils/tokens.ts +69 -10
@@ -1,77 +1,216 @@
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
69
  export type IState = BaseGraphState;
18
70
 
19
- // export interface IState extends BaseGraphState {
20
- // instructions?: string;
21
- // additional_instructions?: string;
22
- // }
23
-
24
71
  export interface EventHandler {
25
- handle(event: string, data: StreamEventData | ModelEndData, metadata?: Record<string, unknown>, graph?: Graph): void;
72
+ handle(
73
+ event: string,
74
+ data:
75
+ | StreamEventData
76
+ | ModelEndData
77
+ | RunStep
78
+ | RunStepDeltaEvent
79
+ | MessageDeltaEvent
80
+ | ReasoningDeltaEvent
81
+ | { result: ToolEndEvent },
82
+ metadata?: Record<string, unknown>,
83
+ graph?: StandardGraph | MultiAgentGraph
84
+ ): void | Promise<void>;
26
85
  }
27
86
 
28
- export type GraphStateChannels<T extends BaseGraphState> = StateGraphArgs<T>['channels'];
87
+ export type GraphStateChannels<T extends BaseGraphState> =
88
+ StateGraphArgs<T>['channels'];
89
+
90
+ export type Workflow<
91
+ T extends BaseGraphState = BaseGraphState,
92
+ U extends Partial<T> = Partial<T>,
93
+ N extends string = string,
94
+ > = StateGraph<T, U, N>;
29
95
 
30
- export type Workflow<T extends BaseGraphState = BaseGraphState, U extends Partial<T> = Partial<T>, N extends string = string> = StateGraph<T, U, N>;
96
+ export type CompiledWorkflow<
97
+ T extends BaseGraphState = BaseGraphState,
98
+ U extends Partial<T> = Partial<T>,
99
+ N extends string = string,
100
+ > = CompiledStateGraph<T, U, N>;
31
101
 
32
- export type CompiledWorkflow<T extends BaseGraphState = BaseGraphState, U extends Partial<T> = Partial<T>, N extends string = string> = CompiledStateGraph<T, U, N>;
102
+ export type CompiledStateWorkflow = CompiledStateGraph<
103
+ StateType<{
104
+ messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
105
+ }>,
106
+ UpdateType<{
107
+ messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
108
+ }>,
109
+ string,
110
+ {
111
+ messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
112
+ },
113
+ {
114
+ messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
115
+ },
116
+ StateDefinition
117
+ >;
33
118
 
34
- export type EventStreamCallbackHandlerInput = Parameters<CompiledWorkflow['streamEvents']>[2] extends Omit<infer T, 'autoClose'> ? T : never;
119
+ export type CompiledAgentWorfklow = CompiledStateGraph<
120
+ {
121
+ messages: BaseMessage[];
122
+ },
123
+ {
124
+ messages?: BaseMessage[] | undefined;
125
+ },
126
+ '__start__' | `agent=${string}` | `tools=${string}`,
127
+ {
128
+ messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
129
+ },
130
+ {
131
+ messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
132
+ },
133
+ StateDefinition,
134
+ {
135
+ [x: `agent=${string}`]: Partial<BaseGraphState>;
136
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
137
+ [x: `tools=${string}`]: any;
138
+ }
139
+ >;
35
140
 
36
- export type StreamChunk = ChatGenerationChunk & {
37
- message: AIMessageChunk;
38
- } | AIMessageChunk;
141
+ export type SystemRunnable =
142
+ | Runnable<
143
+ BaseMessage[],
144
+ (BaseMessage | SystemMessage)[],
145
+ RunnableConfig<Record<string, unknown>>
146
+ >
147
+ | undefined;
148
+
149
+ /**
150
+ * Optional compile options passed to workflow.compile().
151
+ * These are intentionally untyped to avoid coupling to library internals.
152
+ */
153
+ export type CompileOptions = {
154
+ // A checkpointer instance (e.g., MemorySaver, SQL saver)
155
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
156
+ checkpointer?: any;
157
+ interruptBefore?: string[];
158
+ interruptAfter?: string[];
159
+ };
160
+
161
+ export type EventStreamCallbackHandlerInput =
162
+ Parameters<CompiledWorkflow['streamEvents']>[2] extends Omit<
163
+ infer T,
164
+ 'autoClose'
165
+ >
166
+ ? T
167
+ : never;
168
+
169
+ export type StreamChunk =
170
+ | (ChatGenerationChunk & {
171
+ message: AIMessageChunk;
172
+ })
173
+ | AIMessageChunk;
39
174
 
40
175
  /**
41
176
  * Data associated with a StreamEvent.
42
177
  */
43
178
  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;
179
+ /**
180
+ * The input passed to the runnable that generated the event.
181
+ * Inputs will sometimes be available at the *START* of the runnable, and
182
+ * sometimes at the *END* of the runnable.
183
+ * If a runnable is able to stream its inputs, then its input by definition
184
+ * won't be known until the *END* of the runnable when it has finished streaming
185
+ * its inputs.
186
+ */
187
+ input?: unknown;
188
+ /**
189
+ * The output of the runnable that generated the event.
190
+ * Outputs will only be available at the *END* of the runnable.
191
+ * For most runnables, this field can be inferred from the `chunk` field,
192
+ * though there might be some exceptions for special cased runnables (e.g., like
193
+ * chat models), which may return more information.
194
+ */
195
+ output?: unknown;
196
+ /**
197
+ * A streaming chunk from the output that generated the event.
198
+ * chunks support addition in general, and adding them up should result
199
+ * in the output of the runnable that generated the event.
200
+ */
201
+ chunk?: StreamChunk;
202
+ /**
203
+ * Runnable config for invoking other runnables within handlers.
204
+ */
205
+ config?: RunnableConfig;
206
+ /**
207
+ * Custom result from the runnable that generated the event.
208
+ */
209
+ result?: unknown;
210
+ /**
211
+ * Custom field to indicate the event was manually emitted, and may have been handled already
212
+ */
213
+ emitted?: boolean;
75
214
  };
76
215
 
77
216
  /**
@@ -80,54 +219,54 @@ export type StreamEventData = {
80
219
  * Schema of a streaming event which is produced from the streamEvents method.
81
220
  */
82
221
  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;
222
+ /**
223
+ * Event names are of the format: on_[runnable_type]_(start|stream|end).
224
+ *
225
+ * Runnable types are one of:
226
+ * - llm - used by non chat models
227
+ * - chat_model - used by chat models
228
+ * - prompt -- e.g., ChatPromptTemplate
229
+ * - tool -- LangChain tools
230
+ * - chain - most Runnables are of this type
231
+ *
232
+ * Further, the events are categorized as one of:
233
+ * - start - when the runnable starts
234
+ * - stream - when the runnable is streaming
235
+ * - end - when the runnable ends
236
+ *
237
+ * start, stream and end are associated with slightly different `data` payload.
238
+ *
239
+ * Please see the documentation for `EventData` for more details.
240
+ */
241
+ event: string;
242
+ /** The name of the runnable that generated the event. */
243
+ name: string;
244
+ /**
245
+ * An randomly generated ID to keep track of the execution of the given runnable.
246
+ *
247
+ * Each child runnable that gets invoked as part of the execution of a parent runnable
248
+ * is assigned its own unique ID.
249
+ */
250
+ run_id: string;
251
+ /**
252
+ * Tags associated with the runnable that generated this event.
253
+ * Tags are always inherited from parent runnables.
254
+ */
255
+ tags?: string[];
256
+ /** Metadata associated with the runnable that generated this event. */
257
+ metadata: Record<string, unknown>;
258
+ /**
259
+ * Event data.
260
+ *
261
+ * The contents of the event data depend on the event type.
262
+ */
263
+ data: StreamEventData;
125
264
  };
126
265
 
127
266
  export type GraphConfig = {
128
- provider: string;
129
- thread_id?: string;
130
- run_id?: string;
267
+ provider: string;
268
+ thread_id?: string;
269
+ run_id?: string;
131
270
  };
132
271
 
133
272
  export type PartMetadata = {
@@ -138,18 +277,48 @@ export type PartMetadata = {
138
277
  output?: string;
139
278
  };
140
279
 
141
- export type ModelEndData = StreamEventData & { output: AIMessageChunk | undefined } | undefined;
142
-
280
+ export type ModelEndData =
281
+ | (StreamEventData & { output: AIMessageChunk | undefined })
282
+ | undefined;
283
+ export type GraphTools = GenericTool[] | BindToolsInput[] | GoogleAIToolType[];
143
284
  export type StandardGraphInput = {
144
285
  runId?: string;
286
+ signal?: AbortSignal;
287
+ agents: AgentInputs[];
288
+ tokenCounter?: TokenCounter;
289
+ indexTokenCountMap?: Record<string, number>;
290
+ };
291
+
292
+ export type GraphEdge = {
293
+ /** Use a list for multiple sources */
294
+ from: string | string[];
295
+ /** Use a list for multiple destinations */
296
+ to: string | string[];
297
+ description?: string;
298
+ /** Can return boolean or specific destination(s) */
299
+ condition?: (state: BaseGraphState) => boolean | string | string[];
300
+ /** 'handoff' creates tools for dynamic routing, 'direct' creates direct edges, which also allow parallel execution */
301
+ edgeType?: 'handoff' | 'direct';
302
+ /** Optional prompt to add when transitioning through this edge */
303
+ promptInstructions?:
304
+ | string
305
+ | ((messages: BaseMessage[]) => string | undefined);
306
+ };
307
+
308
+ export type MultiAgentGraphInput = StandardGraphInput & {
309
+ edges: GraphEdge[];
310
+ };
311
+
312
+ export interface AgentInputs {
313
+ agentId: string;
145
314
  toolEnd?: boolean;
146
315
  toolMap?: ToolMap;
316
+ tools?: GraphTools;
147
317
  provider: Providers;
148
- signal?: AbortSignal;
149
318
  instructions?: string;
150
319
  streamBuffer?: number;
151
- tools?: GenericTool[];
152
- clientOptions: ClientOptions;
320
+ maxContextTokens?: number;
321
+ clientOptions?: ClientOptions;
153
322
  additional_instructions?: string;
154
323
  reasoningKey?: 'reasoning_content' | 'reasoning';
155
- };
324
+ }
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
  };
@@ -8,6 +8,8 @@ import type {
8
8
  } from '@langchain/core/messages';
9
9
  import type { ToolCall, ToolCallChunk } from '@langchain/core/messages/tool';
10
10
  import type { LLMResult, Generation } from '@langchain/core/outputs';
11
+ import type { AnthropicContentBlock } from '@/llm/anthropic/types';
12
+ import type { Command } from '@langchain/langgraph';
11
13
  import type { ToolEndEvent } from '@/types/tools';
12
14
  import { StepTypes, ContentTypes, GraphEvents } from '@/common/enum';
13
15
 
@@ -103,7 +105,7 @@ export type MessageCreationDetails = {
103
105
 
104
106
  export type ToolEndData = {
105
107
  input: string | Record<string, unknown>;
106
- output?: ToolMessage;
108
+ output?: ToolMessage | Command;
107
109
  };
108
110
  export type ToolErrorData = {
109
111
  id: string;
@@ -251,6 +253,12 @@ export type ReasoningContentText = {
251
253
  think: string;
252
254
  };
253
255
 
256
+ /** Vertex AI / Google Common - Reasoning Content Block Format */
257
+ export type GoogleReasoningContentText = {
258
+ type: ContentTypes.REASONING;
259
+ reasoning: string;
260
+ };
261
+
254
262
  /** Anthropic's Reasoning Content Block Format */
255
263
  export type ThinkingContentText = {
256
264
  type: ContentTypes.THINKING;
@@ -293,7 +301,20 @@ export type ToolCallContent = {
293
301
  tool_call?: ToolCallPart;
294
302
  };
295
303
 
304
+ export type ToolResultContent = {
305
+ content:
306
+ | string
307
+ | Record<string, unknown>
308
+ | Array<string | Record<string, unknown>>
309
+ | AnthropicContentBlock[];
310
+ type: 'tool_result' | 'web_search_result' | 'web_search_tool_result';
311
+ tool_use_id?: string;
312
+ input?: string | Record<string, unknown>;
313
+ index?: number;
314
+ };
315
+
296
316
  export type MessageContentComplex = (
317
+ | ToolResultContent
297
318
  | ThinkingContentText
298
319
  | AgentUpdate
299
320
  | ToolCallContent