illuma-agents 1.0.2 → 1.0.4

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 (225) hide show
  1. package/LICENSE +25 -21
  2. package/dist/cjs/agents/AgentContext.cjs +222 -0
  3. package/dist/cjs/agents/AgentContext.cjs.map +1 -0
  4. package/dist/cjs/common/enum.cjs +5 -4
  5. package/dist/cjs/common/enum.cjs.map +1 -1
  6. package/dist/cjs/events.cjs +7 -5
  7. package/dist/cjs/events.cjs.map +1 -1
  8. package/dist/cjs/graphs/Graph.cjs +328 -207
  9. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  10. package/dist/cjs/graphs/MultiAgentGraph.cjs +507 -0
  11. package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -0
  12. package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
  13. package/dist/cjs/llm/google/index.cjs.map +1 -1
  14. package/dist/cjs/llm/ollama/index.cjs.map +1 -1
  15. package/dist/cjs/llm/openai/index.cjs +35 -0
  16. package/dist/cjs/llm/openai/index.cjs.map +1 -1
  17. package/dist/cjs/llm/openai/utils/index.cjs +3 -1
  18. package/dist/cjs/llm/openai/utils/index.cjs.map +1 -1
  19. package/dist/cjs/llm/openrouter/index.cjs.map +1 -1
  20. package/dist/cjs/llm/providers.cjs +0 -2
  21. package/dist/cjs/llm/providers.cjs.map +1 -1
  22. package/dist/cjs/llm/vertexai/index.cjs.map +1 -1
  23. package/dist/cjs/main.cjs +12 -1
  24. package/dist/cjs/main.cjs.map +1 -1
  25. package/dist/cjs/messages/cache.cjs +123 -0
  26. package/dist/cjs/messages/cache.cjs.map +1 -0
  27. package/dist/cjs/messages/content.cjs +53 -0
  28. package/dist/cjs/messages/content.cjs.map +1 -0
  29. package/dist/cjs/messages/format.cjs +17 -29
  30. package/dist/cjs/messages/format.cjs.map +1 -1
  31. package/dist/cjs/run.cjs +119 -74
  32. package/dist/cjs/run.cjs.map +1 -1
  33. package/dist/cjs/stream.cjs +77 -73
  34. package/dist/cjs/stream.cjs.map +1 -1
  35. package/dist/cjs/tools/Calculator.cjs +45 -0
  36. package/dist/cjs/tools/Calculator.cjs.map +1 -0
  37. package/dist/cjs/tools/CodeExecutor.cjs +22 -22
  38. package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
  39. package/dist/cjs/tools/ToolNode.cjs +5 -3
  40. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  41. package/dist/cjs/tools/handlers.cjs +20 -20
  42. package/dist/cjs/tools/handlers.cjs.map +1 -1
  43. package/dist/cjs/utils/events.cjs +31 -0
  44. package/dist/cjs/utils/events.cjs.map +1 -0
  45. package/dist/cjs/utils/handlers.cjs +70 -0
  46. package/dist/cjs/utils/handlers.cjs.map +1 -0
  47. package/dist/cjs/utils/tokens.cjs +54 -7
  48. package/dist/cjs/utils/tokens.cjs.map +1 -1
  49. package/dist/esm/agents/AgentContext.mjs +220 -0
  50. package/dist/esm/agents/AgentContext.mjs.map +1 -0
  51. package/dist/esm/common/enum.mjs +5 -4
  52. package/dist/esm/common/enum.mjs.map +1 -1
  53. package/dist/esm/events.mjs +7 -5
  54. package/dist/esm/events.mjs.map +1 -1
  55. package/dist/esm/graphs/Graph.mjs +330 -209
  56. package/dist/esm/graphs/Graph.mjs.map +1 -1
  57. package/dist/esm/graphs/MultiAgentGraph.mjs +505 -0
  58. package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -0
  59. package/dist/esm/llm/anthropic/index.mjs.map +1 -1
  60. package/dist/esm/llm/google/index.mjs.map +1 -1
  61. package/dist/esm/llm/ollama/index.mjs.map +1 -1
  62. package/dist/esm/llm/openai/index.mjs +35 -0
  63. package/dist/esm/llm/openai/index.mjs.map +1 -1
  64. package/dist/esm/llm/openai/utils/index.mjs +3 -1
  65. package/dist/esm/llm/openai/utils/index.mjs.map +1 -1
  66. package/dist/esm/llm/openrouter/index.mjs.map +1 -1
  67. package/dist/esm/llm/providers.mjs +0 -2
  68. package/dist/esm/llm/providers.mjs.map +1 -1
  69. package/dist/esm/llm/vertexai/index.mjs.map +1 -1
  70. package/dist/esm/main.mjs +7 -2
  71. package/dist/esm/main.mjs.map +1 -1
  72. package/dist/esm/messages/cache.mjs +120 -0
  73. package/dist/esm/messages/cache.mjs.map +1 -0
  74. package/dist/esm/messages/content.mjs +51 -0
  75. package/dist/esm/messages/content.mjs.map +1 -0
  76. package/dist/esm/messages/format.mjs +18 -29
  77. package/dist/esm/messages/format.mjs.map +1 -1
  78. package/dist/esm/run.mjs +119 -74
  79. package/dist/esm/run.mjs.map +1 -1
  80. package/dist/esm/stream.mjs +77 -73
  81. package/dist/esm/stream.mjs.map +1 -1
  82. package/dist/esm/tools/Calculator.mjs +24 -0
  83. package/dist/esm/tools/Calculator.mjs.map +1 -0
  84. package/dist/esm/tools/CodeExecutor.mjs +22 -22
  85. package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
  86. package/dist/esm/tools/ToolNode.mjs +5 -3
  87. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  88. package/dist/esm/tools/handlers.mjs +20 -20
  89. package/dist/esm/tools/handlers.mjs.map +1 -1
  90. package/dist/esm/utils/events.mjs +29 -0
  91. package/dist/esm/utils/events.mjs.map +1 -0
  92. package/dist/esm/utils/handlers.mjs +68 -0
  93. package/dist/esm/utils/handlers.mjs.map +1 -0
  94. package/dist/esm/utils/tokens.mjs +54 -8
  95. package/dist/esm/utils/tokens.mjs.map +1 -1
  96. package/dist/types/agents/AgentContext.d.ts +94 -0
  97. package/dist/types/common/enum.d.ts +7 -5
  98. package/dist/types/events.d.ts +3 -3
  99. package/dist/types/graphs/Graph.d.ts +60 -66
  100. package/dist/types/graphs/MultiAgentGraph.d.ts +47 -0
  101. package/dist/types/graphs/index.d.ts +1 -0
  102. package/dist/types/index.d.ts +1 -0
  103. package/dist/types/llm/openai/index.d.ts +10 -0
  104. package/dist/types/messages/cache.d.ts +20 -0
  105. package/dist/types/messages/content.d.ts +7 -0
  106. package/dist/types/messages/format.d.ts +1 -7
  107. package/dist/types/messages/index.d.ts +2 -0
  108. package/dist/types/messages/reducer.d.ts +9 -0
  109. package/dist/types/run.d.ts +16 -10
  110. package/dist/types/stream.d.ts +4 -3
  111. package/dist/types/tools/Calculator.d.ts +8 -0
  112. package/dist/types/tools/ToolNode.d.ts +1 -1
  113. package/dist/types/tools/handlers.d.ts +9 -7
  114. package/dist/types/tools/search/tool.d.ts +4 -4
  115. package/dist/types/types/graph.d.ts +124 -11
  116. package/dist/types/types/llm.d.ts +13 -9
  117. package/dist/types/types/messages.d.ts +4 -0
  118. package/dist/types/types/run.d.ts +46 -8
  119. package/dist/types/types/stream.d.ts +3 -2
  120. package/dist/types/utils/events.d.ts +6 -0
  121. package/dist/types/utils/handlers.d.ts +34 -0
  122. package/dist/types/utils/index.d.ts +1 -0
  123. package/dist/types/utils/tokens.d.ts +24 -0
  124. package/package.json +162 -145
  125. package/src/agents/AgentContext.ts +323 -0
  126. package/src/common/enum.ts +177 -176
  127. package/src/events.ts +197 -191
  128. package/src/graphs/Graph.ts +1058 -846
  129. package/src/graphs/MultiAgentGraph.ts +598 -0
  130. package/src/graphs/index.ts +2 -1
  131. package/src/index.ts +25 -24
  132. package/src/llm/anthropic/index.ts +413 -413
  133. package/src/llm/google/index.ts +222 -222
  134. package/src/llm/google/utils/zod_to_genai_parameters.ts +86 -88
  135. package/src/llm/ollama/index.ts +92 -92
  136. package/src/llm/openai/index.ts +894 -853
  137. package/src/llm/openai/utils/index.ts +920 -918
  138. package/src/llm/openrouter/index.ts +60 -60
  139. package/src/llm/providers.ts +55 -57
  140. package/src/llm/vertexai/index.ts +360 -360
  141. package/src/messages/cache.test.ts +461 -0
  142. package/src/messages/cache.ts +151 -0
  143. package/src/messages/content.test.ts +362 -0
  144. package/src/messages/content.ts +63 -0
  145. package/src/messages/format.ts +611 -625
  146. package/src/messages/formatAgentMessages.test.ts +1144 -917
  147. package/src/messages/index.ts +6 -4
  148. package/src/messages/reducer.ts +80 -0
  149. package/src/run.ts +447 -381
  150. package/src/scripts/abort.ts +157 -138
  151. package/src/scripts/ant_web_search.ts +158 -158
  152. package/src/scripts/cli.ts +172 -167
  153. package/src/scripts/cli2.ts +133 -125
  154. package/src/scripts/cli3.ts +184 -178
  155. package/src/scripts/cli4.ts +191 -184
  156. package/src/scripts/cli5.ts +191 -184
  157. package/src/scripts/code_exec.ts +213 -214
  158. package/src/scripts/code_exec_simple.ts +147 -129
  159. package/src/scripts/content.ts +138 -120
  160. package/src/scripts/handoff-test.ts +135 -0
  161. package/src/scripts/multi-agent-chain.ts +278 -0
  162. package/src/scripts/multi-agent-conditional.ts +220 -0
  163. package/src/scripts/multi-agent-document-review-chain.ts +197 -0
  164. package/src/scripts/multi-agent-hybrid-flow.ts +310 -0
  165. package/src/scripts/multi-agent-parallel.ts +343 -0
  166. package/src/scripts/multi-agent-sequence.ts +212 -0
  167. package/src/scripts/multi-agent-supervisor.ts +364 -0
  168. package/src/scripts/multi-agent-test.ts +186 -0
  169. package/src/scripts/search.ts +146 -150
  170. package/src/scripts/simple.ts +225 -225
  171. package/src/scripts/stream.ts +140 -122
  172. package/src/scripts/test-custom-prompt-key.ts +145 -0
  173. package/src/scripts/test-handoff-input.ts +170 -0
  174. package/src/scripts/test-multi-agent-list-handoff.ts +261 -0
  175. package/src/scripts/test-tools-before-handoff.ts +222 -0
  176. package/src/scripts/tools.ts +153 -155
  177. package/src/specs/agent-handoffs.test.ts +889 -0
  178. package/src/specs/anthropic.simple.test.ts +320 -317
  179. package/src/specs/azure.simple.test.ts +325 -316
  180. package/src/specs/openai.simple.test.ts +311 -316
  181. package/src/specs/openrouter.simple.test.ts +107 -0
  182. package/src/specs/prune.test.ts +758 -763
  183. package/src/specs/reasoning.test.ts +201 -165
  184. package/src/specs/thinking-prune.test.ts +769 -703
  185. package/src/specs/token-memoization.test.ts +39 -0
  186. package/src/stream.ts +664 -651
  187. package/src/tools/Calculator.test.ts +278 -0
  188. package/src/tools/Calculator.ts +25 -0
  189. package/src/tools/CodeExecutor.ts +220 -220
  190. package/src/tools/ToolNode.ts +170 -170
  191. package/src/tools/handlers.ts +341 -336
  192. package/src/types/graph.ts +372 -185
  193. package/src/types/llm.ts +141 -140
  194. package/src/types/messages.ts +4 -0
  195. package/src/types/run.ts +128 -89
  196. package/src/types/stream.ts +401 -400
  197. package/src/utils/events.ts +32 -0
  198. package/src/utils/handlers.ts +107 -0
  199. package/src/utils/index.ts +6 -5
  200. package/src/utils/llmConfig.ts +183 -183
  201. package/src/utils/tokens.ts +129 -70
  202. package/dist/types/scripts/abort.d.ts +0 -1
  203. package/dist/types/scripts/ant_web_search.d.ts +0 -1
  204. package/dist/types/scripts/args.d.ts +0 -7
  205. package/dist/types/scripts/caching.d.ts +0 -1
  206. package/dist/types/scripts/cli.d.ts +0 -1
  207. package/dist/types/scripts/cli2.d.ts +0 -1
  208. package/dist/types/scripts/cli3.d.ts +0 -1
  209. package/dist/types/scripts/cli4.d.ts +0 -1
  210. package/dist/types/scripts/cli5.d.ts +0 -1
  211. package/dist/types/scripts/code_exec.d.ts +0 -1
  212. package/dist/types/scripts/code_exec_files.d.ts +0 -1
  213. package/dist/types/scripts/code_exec_simple.d.ts +0 -1
  214. package/dist/types/scripts/content.d.ts +0 -1
  215. package/dist/types/scripts/empty_input.d.ts +0 -1
  216. package/dist/types/scripts/image.d.ts +0 -1
  217. package/dist/types/scripts/memory.d.ts +0 -1
  218. package/dist/types/scripts/search.d.ts +0 -1
  219. package/dist/types/scripts/simple.d.ts +0 -1
  220. package/dist/types/scripts/stream.d.ts +0 -1
  221. package/dist/types/scripts/thinking.d.ts +0 -1
  222. package/dist/types/scripts/tools.d.ts +0 -1
  223. package/dist/types/specs/spec.utils.d.ts +0 -1
  224. package/dist/types/tools/example.d.ts +0 -78
  225. package/src/tools/example.ts +0 -129
@@ -1,185 +1,372 @@
1
- // src/types/graph.ts
2
- import type {
3
- StateGraphArgs,
4
- StateGraph,
5
- CompiledStateGraph,
6
- } from '@langchain/langgraph';
7
- import type { BindToolsInput } from '@langchain/core/language_models/chat_models';
8
- import type { BaseMessage, AIMessageChunk } from '@langchain/core/messages';
9
- import type { ChatGenerationChunk } from '@langchain/core/outputs';
10
- import type { GoogleAIToolType } from '@langchain/google-common';
11
- import type { RunnableConfig } from '@langchain/core/runnables';
12
- import type { ToolMap, GenericTool } from '@/types/tools';
13
- import type { ClientOptions } from '@/types/llm';
14
- import type { Providers } from '@/common';
15
- import type { Graph } from '@/graphs';
16
- // import type { RunnableConfig } from '@langchain/core/runnables';
17
-
18
- export type BaseGraphState = {
19
- messages: BaseMessage[];
20
- // [key: string]: unknown;
21
- };
22
-
23
- export type IState = BaseGraphState;
24
-
25
- // export interface IState extends BaseGraphState {
26
- // instructions?: string;
27
- // additional_instructions?: string;
28
- // }
29
-
30
- export interface EventHandler {
31
- handle(
32
- event: string,
33
- data: StreamEventData | ModelEndData,
34
- metadata?: Record<string, unknown>,
35
- graph?: Graph
36
- ): void;
37
- }
38
-
39
- export type GraphStateChannels<T extends BaseGraphState> =
40
- StateGraphArgs<T>['channels'];
41
-
42
- export type Workflow<
43
- T extends BaseGraphState = BaseGraphState,
44
- U extends Partial<T> = Partial<T>,
45
- N extends string = string,
46
- > = StateGraph<T, U, N>;
47
-
48
- export type CompiledWorkflow<
49
- T extends BaseGraphState = BaseGraphState,
50
- U extends Partial<T> = Partial<T>,
51
- N extends string = string,
52
- > = CompiledStateGraph<T, U, N>;
53
-
54
- export type EventStreamCallbackHandlerInput =
55
- Parameters<CompiledWorkflow['streamEvents']>[2] extends Omit<
56
- infer T,
57
- 'autoClose'
58
- >
59
- ? T
60
- : never;
61
-
62
- export type StreamChunk =
63
- | (ChatGenerationChunk & {
64
- message: AIMessageChunk;
65
- })
66
- | AIMessageChunk;
67
-
68
- /**
69
- * Data associated with a StreamEvent.
70
- */
71
- export type StreamEventData = {
72
- /**
73
- * The input passed to the runnable that generated the event.
74
- * Inputs will sometimes be available at the *START* of the runnable, and
75
- * sometimes at the *END* of the runnable.
76
- * If a runnable is able to stream its inputs, then its input by definition
77
- * won't be known until the *END* of the runnable when it has finished streaming
78
- * its inputs.
79
- */
80
- input?: unknown;
81
- /**
82
- * The output of the runnable that generated the event.
83
- * Outputs will only be available at the *END* of the runnable.
84
- * For most runnables, this field can be inferred from the `chunk` field,
85
- * though there might be some exceptions for special cased runnables (e.g., like
86
- * chat models), which may return more information.
87
- */
88
- output?: unknown;
89
- /**
90
- * A streaming chunk from the output that generated the event.
91
- * chunks support addition in general, and adding them up should result
92
- * in the output of the runnable that generated the event.
93
- */
94
- chunk?: StreamChunk;
95
- /**
96
- * Runnable config for invoking other runnables within handlers.
97
- */
98
- config?: RunnableConfig;
99
- /**
100
- * Custom result from the runnable that generated the event.
101
- */
102
- result?: unknown;
103
- };
104
-
105
- /**
106
- * A streaming event.
107
- *
108
- * Schema of a streaming event which is produced from the streamEvents method.
109
- */
110
- export type StreamEvent = {
111
- /**
112
- * Event names are of the format: on_[runnable_type]_(start|stream|end).
113
- *
114
- * Runnable types are one of:
115
- * - llm - used by non chat models
116
- * - chat_model - used by chat models
117
- * - prompt -- e.g., ChatPromptTemplate
118
- * - tool -- LangChain tools
119
- * - chain - most Runnables are of this type
120
- *
121
- * Further, the events are categorized as one of:
122
- * - start - when the runnable starts
123
- * - stream - when the runnable is streaming
124
- * - end - when the runnable ends
125
- *
126
- * start, stream and end are associated with slightly different `data` payload.
127
- *
128
- * Please see the documentation for `EventData` for more details.
129
- */
130
- event: string;
131
- /** The name of the runnable that generated the event. */
132
- name: string;
133
- /**
134
- * An randomly generated ID to keep track of the execution of the given runnable.
135
- *
136
- * Each child runnable that gets invoked as part of the execution of a parent runnable
137
- * is assigned its own unique ID.
138
- */
139
- run_id: string;
140
- /**
141
- * Tags associated with the runnable that generated this event.
142
- * Tags are always inherited from parent runnables.
143
- */
144
- tags?: string[];
145
- /** Metadata associated with the runnable that generated this event. */
146
- metadata: Record<string, unknown>;
147
- /**
148
- * Event data.
149
- *
150
- * The contents of the event data depend on the event type.
151
- */
152
- data: StreamEventData;
153
- };
154
-
155
- export type GraphConfig = {
156
- provider: string;
157
- thread_id?: string;
158
- run_id?: string;
159
- };
160
-
161
- export type PartMetadata = {
162
- progress?: number;
163
- asset_pointer?: string;
164
- status?: string;
165
- action?: boolean;
166
- output?: string;
167
- };
168
-
169
- export type ModelEndData =
170
- | (StreamEventData & { output: AIMessageChunk | undefined })
171
- | undefined;
172
- export type GraphTools = GenericTool[] | BindToolsInput[] | GoogleAIToolType[];
173
- export type StandardGraphInput = {
174
- runId?: string;
175
- toolEnd?: boolean;
176
- toolMap?: ToolMap;
177
- provider: Providers;
178
- signal?: AbortSignal;
179
- instructions?: string;
180
- streamBuffer?: number;
181
- clientOptions: ClientOptions;
182
- additional_instructions?: string;
183
- reasoningKey?: 'reasoning_content' | 'reasoning';
184
- tools?: GraphTools;
185
- };
1
+ // src/types/graph.ts
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';
19
+ import type { ChatGenerationChunk } from '@langchain/core/outputs';
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';
24
+ import type { ClientOptions } from '@/types/llm';
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
+ };
64
+
65
+ export type BaseGraphState = {
66
+ messages: BaseMessage[];
67
+ };
68
+
69
+ export type MultiAgentGraphState = BaseGraphState & {
70
+ agentMessages?: BaseMessage[];
71
+ };
72
+
73
+ export type IState = BaseGraphState;
74
+
75
+ export interface EventHandler {
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>;
89
+ }
90
+
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
+ >;
143
+
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
+ >;
165
+
166
+ export type SystemRunnable =
167
+ | Runnable<
168
+ BaseMessage[],
169
+ (BaseMessage | SystemMessage)[],
170
+ RunnableConfig<Record<string, unknown>>
171
+ >
172
+ | undefined;
173
+
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;
193
+
194
+ export type StreamChunk =
195
+ | (ChatGenerationChunk & {
196
+ message: AIMessageChunk;
197
+ })
198
+ | AIMessageChunk;
199
+
200
+ /**
201
+ * Data associated with a StreamEvent.
202
+ */
203
+ export type StreamEventData = {
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;
239
+ };
240
+
241
+ /**
242
+ * A streaming event.
243
+ *
244
+ * Schema of a streaming event which is produced from the streamEvents method.
245
+ */
246
+ export type StreamEvent = {
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;
289
+ };
290
+
291
+ export type GraphConfig = {
292
+ provider: string;
293
+ thread_id?: string;
294
+ run_id?: string;
295
+ };
296
+
297
+ export type PartMetadata = {
298
+ progress?: number;
299
+ asset_pointer?: string;
300
+ status?: string;
301
+ action?: boolean;
302
+ output?: string;
303
+ };
304
+
305
+ export type ModelEndData =
306
+ | (StreamEventData & { output: AIMessageChunk | undefined })
307
+ | undefined;
308
+ export type GraphTools = GenericTool[] | BindToolsInput[] | GoogleAIToolType[];
309
+ export type StandardGraphInput = {
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
+ | ((
338
+ messages: BaseMessage[],
339
+ runStartIndex: number
340
+ ) => string | Promise<string> | undefined);
341
+ /**
342
+ * When true, excludes messages from startIndex when adding prompt.
343
+ * Automatically set to true when {results} variable is used in prompt.
344
+ */
345
+ excludeResults?: boolean;
346
+ /**
347
+ * For handoff edges: Customizes the parameter name for the handoff input.
348
+ * Defaults to "instructions" if not specified.
349
+ * Only applies when prompt is provided for handoff edges.
350
+ */
351
+ promptKey?: string;
352
+ };
353
+
354
+ export type MultiAgentGraphInput = StandardGraphInput & {
355
+ edges: GraphEdge[];
356
+ };
357
+
358
+ export interface AgentInputs {
359
+ agentId: string;
360
+ toolEnd?: boolean;
361
+ toolMap?: ToolMap;
362
+ tools?: GraphTools;
363
+ provider: Providers;
364
+ instructions?: string;
365
+ streamBuffer?: number;
366
+ maxContextTokens?: number;
367
+ clientOptions?: ClientOptions;
368
+ additional_instructions?: string;
369
+ reasoningKey?: 'reasoning_content' | 'reasoning';
370
+ /** Format content blocks as strings (for legacy compatibility i.e. Ollama/Azure Serverless) */
371
+ useLegacyContent?: boolean;
372
+ }