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.
- package/LICENSE +25 -21
- package/dist/cjs/agents/AgentContext.cjs +222 -0
- package/dist/cjs/agents/AgentContext.cjs.map +1 -0
- package/dist/cjs/common/enum.cjs +5 -4
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/events.cjs +7 -5
- package/dist/cjs/events.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +328 -207
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +507 -0
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -0
- package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
- package/dist/cjs/llm/google/index.cjs.map +1 -1
- package/dist/cjs/llm/ollama/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs +35 -0
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/utils/index.cjs +3 -1
- package/dist/cjs/llm/openai/utils/index.cjs.map +1 -1
- package/dist/cjs/llm/openrouter/index.cjs.map +1 -1
- package/dist/cjs/llm/providers.cjs +0 -2
- package/dist/cjs/llm/providers.cjs.map +1 -1
- package/dist/cjs/llm/vertexai/index.cjs.map +1 -1
- package/dist/cjs/main.cjs +12 -1
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/messages/cache.cjs +123 -0
- package/dist/cjs/messages/cache.cjs.map +1 -0
- package/dist/cjs/messages/content.cjs +53 -0
- package/dist/cjs/messages/content.cjs.map +1 -0
- package/dist/cjs/messages/format.cjs +17 -29
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/cjs/run.cjs +119 -74
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/stream.cjs +77 -73
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/tools/Calculator.cjs +45 -0
- package/dist/cjs/tools/Calculator.cjs.map +1 -0
- package/dist/cjs/tools/CodeExecutor.cjs +22 -22
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +5 -3
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/handlers.cjs +20 -20
- package/dist/cjs/tools/handlers.cjs.map +1 -1
- package/dist/cjs/utils/events.cjs +31 -0
- package/dist/cjs/utils/events.cjs.map +1 -0
- package/dist/cjs/utils/handlers.cjs +70 -0
- package/dist/cjs/utils/handlers.cjs.map +1 -0
- package/dist/cjs/utils/tokens.cjs +54 -7
- package/dist/cjs/utils/tokens.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +220 -0
- package/dist/esm/agents/AgentContext.mjs.map +1 -0
- package/dist/esm/common/enum.mjs +5 -4
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/events.mjs +7 -5
- package/dist/esm/events.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +330 -209
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +505 -0
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -0
- package/dist/esm/llm/anthropic/index.mjs.map +1 -1
- package/dist/esm/llm/google/index.mjs.map +1 -1
- package/dist/esm/llm/ollama/index.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +35 -0
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/llm/openai/utils/index.mjs +3 -1
- package/dist/esm/llm/openai/utils/index.mjs.map +1 -1
- package/dist/esm/llm/openrouter/index.mjs.map +1 -1
- package/dist/esm/llm/providers.mjs +0 -2
- package/dist/esm/llm/providers.mjs.map +1 -1
- package/dist/esm/llm/vertexai/index.mjs.map +1 -1
- package/dist/esm/main.mjs +7 -2
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/messages/cache.mjs +120 -0
- package/dist/esm/messages/cache.mjs.map +1 -0
- package/dist/esm/messages/content.mjs +51 -0
- package/dist/esm/messages/content.mjs.map +1 -0
- package/dist/esm/messages/format.mjs +18 -29
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/esm/run.mjs +119 -74
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/stream.mjs +77 -73
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/tools/Calculator.mjs +24 -0
- package/dist/esm/tools/Calculator.mjs.map +1 -0
- package/dist/esm/tools/CodeExecutor.mjs +22 -22
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +5 -3
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/handlers.mjs +20 -20
- package/dist/esm/tools/handlers.mjs.map +1 -1
- package/dist/esm/utils/events.mjs +29 -0
- package/dist/esm/utils/events.mjs.map +1 -0
- package/dist/esm/utils/handlers.mjs +68 -0
- package/dist/esm/utils/handlers.mjs.map +1 -0
- package/dist/esm/utils/tokens.mjs +54 -8
- package/dist/esm/utils/tokens.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +94 -0
- package/dist/types/common/enum.d.ts +7 -5
- package/dist/types/events.d.ts +3 -3
- package/dist/types/graphs/Graph.d.ts +60 -66
- package/dist/types/graphs/MultiAgentGraph.d.ts +47 -0
- package/dist/types/graphs/index.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/llm/openai/index.d.ts +10 -0
- package/dist/types/messages/cache.d.ts +20 -0
- package/dist/types/messages/content.d.ts +7 -0
- package/dist/types/messages/format.d.ts +1 -7
- package/dist/types/messages/index.d.ts +2 -0
- package/dist/types/messages/reducer.d.ts +9 -0
- package/dist/types/run.d.ts +16 -10
- package/dist/types/stream.d.ts +4 -3
- package/dist/types/tools/Calculator.d.ts +8 -0
- package/dist/types/tools/ToolNode.d.ts +1 -1
- package/dist/types/tools/handlers.d.ts +9 -7
- package/dist/types/tools/search/tool.d.ts +4 -4
- package/dist/types/types/graph.d.ts +124 -11
- package/dist/types/types/llm.d.ts +13 -9
- package/dist/types/types/messages.d.ts +4 -0
- package/dist/types/types/run.d.ts +46 -8
- package/dist/types/types/stream.d.ts +3 -2
- package/dist/types/utils/events.d.ts +6 -0
- package/dist/types/utils/handlers.d.ts +34 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/tokens.d.ts +24 -0
- package/package.json +162 -145
- package/src/agents/AgentContext.ts +323 -0
- package/src/common/enum.ts +177 -176
- package/src/events.ts +197 -191
- package/src/graphs/Graph.ts +1058 -846
- package/src/graphs/MultiAgentGraph.ts +598 -0
- package/src/graphs/index.ts +2 -1
- package/src/index.ts +25 -24
- package/src/llm/anthropic/index.ts +413 -413
- package/src/llm/google/index.ts +222 -222
- package/src/llm/google/utils/zod_to_genai_parameters.ts +86 -88
- package/src/llm/ollama/index.ts +92 -92
- package/src/llm/openai/index.ts +894 -853
- package/src/llm/openai/utils/index.ts +920 -918
- package/src/llm/openrouter/index.ts +60 -60
- package/src/llm/providers.ts +55 -57
- package/src/llm/vertexai/index.ts +360 -360
- package/src/messages/cache.test.ts +461 -0
- package/src/messages/cache.ts +151 -0
- package/src/messages/content.test.ts +362 -0
- package/src/messages/content.ts +63 -0
- package/src/messages/format.ts +611 -625
- package/src/messages/formatAgentMessages.test.ts +1144 -917
- package/src/messages/index.ts +6 -4
- package/src/messages/reducer.ts +80 -0
- package/src/run.ts +447 -381
- package/src/scripts/abort.ts +157 -138
- package/src/scripts/ant_web_search.ts +158 -158
- package/src/scripts/cli.ts +172 -167
- package/src/scripts/cli2.ts +133 -125
- package/src/scripts/cli3.ts +184 -178
- package/src/scripts/cli4.ts +191 -184
- package/src/scripts/cli5.ts +191 -184
- package/src/scripts/code_exec.ts +213 -214
- package/src/scripts/code_exec_simple.ts +147 -129
- package/src/scripts/content.ts +138 -120
- package/src/scripts/handoff-test.ts +135 -0
- package/src/scripts/multi-agent-chain.ts +278 -0
- package/src/scripts/multi-agent-conditional.ts +220 -0
- package/src/scripts/multi-agent-document-review-chain.ts +197 -0
- package/src/scripts/multi-agent-hybrid-flow.ts +310 -0
- package/src/scripts/multi-agent-parallel.ts +343 -0
- package/src/scripts/multi-agent-sequence.ts +212 -0
- package/src/scripts/multi-agent-supervisor.ts +364 -0
- package/src/scripts/multi-agent-test.ts +186 -0
- package/src/scripts/search.ts +146 -150
- package/src/scripts/simple.ts +225 -225
- package/src/scripts/stream.ts +140 -122
- package/src/scripts/test-custom-prompt-key.ts +145 -0
- package/src/scripts/test-handoff-input.ts +170 -0
- package/src/scripts/test-multi-agent-list-handoff.ts +261 -0
- package/src/scripts/test-tools-before-handoff.ts +222 -0
- package/src/scripts/tools.ts +153 -155
- package/src/specs/agent-handoffs.test.ts +889 -0
- package/src/specs/anthropic.simple.test.ts +320 -317
- package/src/specs/azure.simple.test.ts +325 -316
- package/src/specs/openai.simple.test.ts +311 -316
- package/src/specs/openrouter.simple.test.ts +107 -0
- package/src/specs/prune.test.ts +758 -763
- package/src/specs/reasoning.test.ts +201 -165
- package/src/specs/thinking-prune.test.ts +769 -703
- package/src/specs/token-memoization.test.ts +39 -0
- package/src/stream.ts +664 -651
- package/src/tools/Calculator.test.ts +278 -0
- package/src/tools/Calculator.ts +25 -0
- package/src/tools/CodeExecutor.ts +220 -220
- package/src/tools/ToolNode.ts +170 -170
- package/src/tools/handlers.ts +341 -336
- package/src/types/graph.ts +372 -185
- package/src/types/llm.ts +141 -140
- package/src/types/messages.ts +4 -0
- package/src/types/run.ts +128 -89
- package/src/types/stream.ts +401 -400
- package/src/utils/events.ts +32 -0
- package/src/utils/handlers.ts +107 -0
- package/src/utils/index.ts +6 -5
- package/src/utils/llmConfig.ts +183 -183
- package/src/utils/tokens.ts +129 -70
- package/dist/types/scripts/abort.d.ts +0 -1
- package/dist/types/scripts/ant_web_search.d.ts +0 -1
- package/dist/types/scripts/args.d.ts +0 -7
- package/dist/types/scripts/caching.d.ts +0 -1
- package/dist/types/scripts/cli.d.ts +0 -1
- package/dist/types/scripts/cli2.d.ts +0 -1
- package/dist/types/scripts/cli3.d.ts +0 -1
- package/dist/types/scripts/cli4.d.ts +0 -1
- package/dist/types/scripts/cli5.d.ts +0 -1
- package/dist/types/scripts/code_exec.d.ts +0 -1
- package/dist/types/scripts/code_exec_files.d.ts +0 -1
- package/dist/types/scripts/code_exec_simple.d.ts +0 -1
- package/dist/types/scripts/content.d.ts +0 -1
- package/dist/types/scripts/empty_input.d.ts +0 -1
- package/dist/types/scripts/image.d.ts +0 -1
- package/dist/types/scripts/memory.d.ts +0 -1
- package/dist/types/scripts/search.d.ts +0 -1
- package/dist/types/scripts/simple.d.ts +0 -1
- package/dist/types/scripts/stream.d.ts +0 -1
- package/dist/types/scripts/thinking.d.ts +0 -1
- package/dist/types/scripts/tools.d.ts +0 -1
- package/dist/types/specs/spec.utils.d.ts +0 -1
- package/dist/types/tools/example.d.ts +0 -78
- package/src/tools/example.ts +0 -129
|
@@ -1,23 +1,89 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { START, StateType, UpdateType, StateGraph, StateGraphArgs, StateDefinition, CompiledStateGraph, BinaryOperatorAggregate } from '@langchain/langgraph';
|
|
2
2
|
import type { BindToolsInput } from '@langchain/core/language_models/chat_models';
|
|
3
|
-
import type { BaseMessage, AIMessageChunk } from '@langchain/core/messages';
|
|
3
|
+
import type { BaseMessage, AIMessageChunk, SystemMessage } from '@langchain/core/messages';
|
|
4
|
+
import type { RunnableConfig, Runnable } from '@langchain/core/runnables';
|
|
4
5
|
import type { ChatGenerationChunk } from '@langchain/core/outputs';
|
|
5
6
|
import type { GoogleAIToolType } from '@langchain/google-common';
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
7
|
+
import type { ToolMap, ToolEndEvent, GenericTool } from '@/types/tools';
|
|
8
|
+
import type { Providers, Callback, GraphNodeKeys } from '@/common';
|
|
9
|
+
import type { StandardGraph, MultiAgentGraph } from '@/graphs';
|
|
8
10
|
import type { ClientOptions } from '@/types/llm';
|
|
9
|
-
import type {
|
|
10
|
-
import type {
|
|
11
|
+
import type { RunStep, RunStepDeltaEvent, MessageDeltaEvent, ReasoningDeltaEvent } from '@/types/stream';
|
|
12
|
+
import type { TokenCounter } from '@/types/run';
|
|
13
|
+
/** Interface for bound model with stream and invoke methods */
|
|
14
|
+
export interface ChatModel {
|
|
15
|
+
stream?: (messages: BaseMessage[], config?: RunnableConfig) => Promise<AsyncIterable<AIMessageChunk>>;
|
|
16
|
+
invoke: (messages: BaseMessage[], config?: RunnableConfig) => Promise<AIMessageChunk>;
|
|
17
|
+
}
|
|
18
|
+
export type GraphNode = GraphNodeKeys | typeof START;
|
|
19
|
+
export type ClientCallback<T extends unknown[]> = (graph: StandardGraph, ...args: T) => void;
|
|
20
|
+
export type ClientCallbacks = {
|
|
21
|
+
[Callback.TOOL_ERROR]?: ClientCallback<[Error, string]>;
|
|
22
|
+
[Callback.TOOL_START]?: ClientCallback<unknown[]>;
|
|
23
|
+
[Callback.TOOL_END]?: ClientCallback<unknown[]>;
|
|
24
|
+
};
|
|
25
|
+
export type SystemCallbacks = {
|
|
26
|
+
[K in keyof ClientCallbacks]: ClientCallbacks[K] extends ClientCallback<infer Args> ? (...args: Args) => void : never;
|
|
27
|
+
};
|
|
11
28
|
export type BaseGraphState = {
|
|
12
29
|
messages: BaseMessage[];
|
|
13
30
|
};
|
|
31
|
+
export type MultiAgentGraphState = BaseGraphState & {
|
|
32
|
+
agentMessages?: BaseMessage[];
|
|
33
|
+
};
|
|
14
34
|
export type IState = BaseGraphState;
|
|
15
35
|
export interface EventHandler {
|
|
16
|
-
handle(event: string, data: StreamEventData | ModelEndData
|
|
36
|
+
handle(event: string, data: StreamEventData | ModelEndData | RunStep | RunStepDeltaEvent | MessageDeltaEvent | ReasoningDeltaEvent | {
|
|
37
|
+
result: ToolEndEvent;
|
|
38
|
+
}, metadata?: Record<string, unknown>, graph?: StandardGraph | MultiAgentGraph): void | Promise<void>;
|
|
17
39
|
}
|
|
18
40
|
export type GraphStateChannels<T extends BaseGraphState> = StateGraphArgs<T>['channels'];
|
|
19
41
|
export type Workflow<T extends BaseGraphState = BaseGraphState, U extends Partial<T> = Partial<T>, N extends string = string> = StateGraph<T, U, N>;
|
|
20
42
|
export type CompiledWorkflow<T extends BaseGraphState = BaseGraphState, U extends Partial<T> = Partial<T>, N extends string = string> = CompiledStateGraph<T, U, N>;
|
|
43
|
+
export type CompiledStateWorkflow = CompiledStateGraph<StateType<{
|
|
44
|
+
messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
45
|
+
}>, UpdateType<{
|
|
46
|
+
messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
47
|
+
}>, string, {
|
|
48
|
+
messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
49
|
+
}, {
|
|
50
|
+
messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
51
|
+
}, StateDefinition>;
|
|
52
|
+
export type CompiledMultiAgentWorkflow = CompiledStateGraph<StateType<{
|
|
53
|
+
messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
54
|
+
agentMessages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
55
|
+
}>, UpdateType<{
|
|
56
|
+
messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
57
|
+
agentMessages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
58
|
+
}>, string, {
|
|
59
|
+
messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
60
|
+
agentMessages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
61
|
+
}, {
|
|
62
|
+
messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
63
|
+
agentMessages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
64
|
+
}, StateDefinition>;
|
|
65
|
+
export type CompiledAgentWorfklow = CompiledStateGraph<{
|
|
66
|
+
messages: BaseMessage[];
|
|
67
|
+
}, {
|
|
68
|
+
messages?: BaseMessage[] | undefined;
|
|
69
|
+
}, '__start__' | `agent=${string}` | `tools=${string}`, {
|
|
70
|
+
messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
71
|
+
}, {
|
|
72
|
+
messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
73
|
+
}, StateDefinition, {
|
|
74
|
+
[x: `agent=${string}`]: Partial<BaseGraphState>;
|
|
75
|
+
[x: `tools=${string}`]: any;
|
|
76
|
+
}>;
|
|
77
|
+
export type SystemRunnable = Runnable<BaseMessage[], (BaseMessage | SystemMessage)[], RunnableConfig<Record<string, unknown>>> | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* Optional compile options passed to workflow.compile().
|
|
80
|
+
* These are intentionally untyped to avoid coupling to library internals.
|
|
81
|
+
*/
|
|
82
|
+
export type CompileOptions = {
|
|
83
|
+
checkpointer?: any;
|
|
84
|
+
interruptBefore?: string[];
|
|
85
|
+
interruptAfter?: string[];
|
|
86
|
+
};
|
|
21
87
|
export type EventStreamCallbackHandlerInput = Parameters<CompiledWorkflow['streamEvents']>[2] extends Omit<infer T, 'autoClose'> ? T : never;
|
|
22
88
|
export type StreamChunk = (ChatGenerationChunk & {
|
|
23
89
|
message: AIMessageChunk;
|
|
@@ -57,6 +123,10 @@ export type StreamEventData = {
|
|
|
57
123
|
* Custom result from the runnable that generated the event.
|
|
58
124
|
*/
|
|
59
125
|
result?: unknown;
|
|
126
|
+
/**
|
|
127
|
+
* Custom field to indicate the event was manually emitted, and may have been handled already
|
|
128
|
+
*/
|
|
129
|
+
emitted?: boolean;
|
|
60
130
|
};
|
|
61
131
|
/**
|
|
62
132
|
* A streaming event.
|
|
@@ -125,14 +195,57 @@ export type ModelEndData = (StreamEventData & {
|
|
|
125
195
|
export type GraphTools = GenericTool[] | BindToolsInput[] | GoogleAIToolType[];
|
|
126
196
|
export type StandardGraphInput = {
|
|
127
197
|
runId?: string;
|
|
198
|
+
signal?: AbortSignal;
|
|
199
|
+
agents: AgentInputs[];
|
|
200
|
+
tokenCounter?: TokenCounter;
|
|
201
|
+
indexTokenCountMap?: Record<string, number>;
|
|
202
|
+
};
|
|
203
|
+
export type GraphEdge = {
|
|
204
|
+
/** Agent ID, use a list for multiple sources */
|
|
205
|
+
from: string | string[];
|
|
206
|
+
/** Agent ID, use a list for multiple destinations */
|
|
207
|
+
to: string | string[];
|
|
208
|
+
description?: string;
|
|
209
|
+
/** Can return boolean or specific destination(s) */
|
|
210
|
+
condition?: (state: BaseGraphState) => boolean | string | string[];
|
|
211
|
+
/** 'handoff' creates tools for dynamic routing, 'direct' creates direct edges, which also allow parallel execution */
|
|
212
|
+
edgeType?: 'handoff' | 'direct';
|
|
213
|
+
/**
|
|
214
|
+
* For direct edges: Optional prompt to add when transitioning through this edge.
|
|
215
|
+
* String prompts can include variables like {results} which will be replaced with
|
|
216
|
+
* messages from startIndex onwards. When {results} is used, excludeResults defaults to true.
|
|
217
|
+
*
|
|
218
|
+
* For handoff edges: Description for the input parameter that the handoff tool accepts,
|
|
219
|
+
* allowing the supervisor to pass specific instructions/context to the transferred agent.
|
|
220
|
+
*/
|
|
221
|
+
prompt?: string | ((messages: BaseMessage[], runStartIndex: number) => string | Promise<string> | undefined);
|
|
222
|
+
/**
|
|
223
|
+
* When true, excludes messages from startIndex when adding prompt.
|
|
224
|
+
* Automatically set to true when {results} variable is used in prompt.
|
|
225
|
+
*/
|
|
226
|
+
excludeResults?: boolean;
|
|
227
|
+
/**
|
|
228
|
+
* For handoff edges: Customizes the parameter name for the handoff input.
|
|
229
|
+
* Defaults to "instructions" if not specified.
|
|
230
|
+
* Only applies when prompt is provided for handoff edges.
|
|
231
|
+
*/
|
|
232
|
+
promptKey?: string;
|
|
233
|
+
};
|
|
234
|
+
export type MultiAgentGraphInput = StandardGraphInput & {
|
|
235
|
+
edges: GraphEdge[];
|
|
236
|
+
};
|
|
237
|
+
export interface AgentInputs {
|
|
238
|
+
agentId: string;
|
|
128
239
|
toolEnd?: boolean;
|
|
129
240
|
toolMap?: ToolMap;
|
|
241
|
+
tools?: GraphTools;
|
|
130
242
|
provider: Providers;
|
|
131
|
-
signal?: AbortSignal;
|
|
132
243
|
instructions?: string;
|
|
133
244
|
streamBuffer?: number;
|
|
134
|
-
|
|
245
|
+
maxContextTokens?: number;
|
|
246
|
+
clientOptions?: ClientOptions;
|
|
135
247
|
additional_instructions?: string;
|
|
136
248
|
reasoningKey?: 'reasoning_content' | 'reasoning';
|
|
137
|
-
|
|
138
|
-
|
|
249
|
+
/** Format content blocks as strings (for legacy compatibility i.e. Ollama/Azure Serverless) */
|
|
250
|
+
useLegacyContent?: boolean;
|
|
251
|
+
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { ChatOllama } from '@langchain/ollama';
|
|
2
|
-
import { ChatAnthropic } from '@langchain/anthropic';
|
|
3
2
|
import { ChatMistralAI } from '@langchain/mistralai';
|
|
4
3
|
import { ChatBedrockConverse } from '@langchain/aws';
|
|
5
|
-
import { BedrockChat } from '@langchain/community/chat_models/bedrock/web';
|
|
6
4
|
import type { BindToolsInput, BaseChatModelParams } from '@langchain/core/language_models/chat_models';
|
|
7
5
|
import type { OpenAIChatInput, ChatOpenAIFields, AzureOpenAIInput, ClientOptions as OAIClientOptions } from '@langchain/openai';
|
|
8
|
-
import type { BedrockChatFields } from '@langchain/community/chat_models/bedrock/web';
|
|
9
6
|
import type { GoogleGenerativeAIChatInput } from '@langchain/google-genai';
|
|
10
7
|
import type { GeminiGenerationConfig } from '@langchain/google-common';
|
|
11
8
|
import type { ChatVertexAIInput } from '@langchain/google-vertexai';
|
|
@@ -22,6 +19,7 @@ import type { OpenAI as OpenAIClient } from 'openai';
|
|
|
22
19
|
import type { ChatXAIInput } from '@langchain/xai';
|
|
23
20
|
import { AzureChatOpenAI, ChatDeepSeek, ChatOpenAI, ChatXAI } from '@/llm/openai';
|
|
24
21
|
import { CustomChatGoogleGenerativeAI } from '@/llm/google';
|
|
22
|
+
import { CustomAnthropic } from '@/llm/anthropic';
|
|
25
23
|
import { ChatOpenRouter } from '@/llm/openrouter';
|
|
26
24
|
import { ChatVertexAI } from '@/llm/vertexai';
|
|
27
25
|
import { Providers } from '@/common';
|
|
@@ -47,22 +45,30 @@ export type MistralAIClientOptions = ChatMistralAIInput;
|
|
|
47
45
|
export type VertexAIClientOptions = ChatVertexAIInput & {
|
|
48
46
|
includeThoughts?: boolean;
|
|
49
47
|
};
|
|
50
|
-
export type BedrockClientOptions = BedrockChatFields;
|
|
51
48
|
export type BedrockAnthropicInput = ChatBedrockConverseInput & {
|
|
52
49
|
additionalModelRequestFields?: ChatBedrockConverseInput['additionalModelRequestFields'] & AnthropicReasoning;
|
|
50
|
+
promptCache?: boolean;
|
|
53
51
|
};
|
|
54
52
|
export type BedrockConverseClientOptions = ChatBedrockConverseInput;
|
|
53
|
+
export type BedrockAnthropicClientOptions = BedrockAnthropicInput;
|
|
55
54
|
export type GoogleClientOptions = GoogleGenerativeAIChatInput & {
|
|
56
55
|
customHeaders?: RequestOptions['customHeaders'];
|
|
57
56
|
thinkingConfig?: GeminiGenerationConfig['thinkingConfig'];
|
|
58
57
|
};
|
|
59
58
|
export type DeepSeekClientOptions = ChatDeepSeekCallOptions;
|
|
60
59
|
export type XAIClientOptions = ChatXAIInput;
|
|
61
|
-
export type ClientOptions = OpenAIClientOptions | AzureClientOptions | OllamaClientOptions | AnthropicClientOptions | MistralAIClientOptions | VertexAIClientOptions |
|
|
60
|
+
export type ClientOptions = OpenAIClientOptions | AzureClientOptions | OllamaClientOptions | AnthropicClientOptions | MistralAIClientOptions | VertexAIClientOptions | BedrockConverseClientOptions | GoogleClientOptions | DeepSeekClientOptions | XAIClientOptions;
|
|
62
61
|
export type SharedLLMConfig = {
|
|
63
62
|
provider: Providers;
|
|
63
|
+
_lc_stream_delay?: number;
|
|
64
|
+
};
|
|
65
|
+
export type LLMConfig = SharedLLMConfig & ClientOptions & {
|
|
66
|
+
/** Optional provider fallbacks in order of attempt */
|
|
67
|
+
fallbacks?: Array<{
|
|
68
|
+
provider: Providers;
|
|
69
|
+
clientOptions?: ClientOptions;
|
|
70
|
+
}>;
|
|
64
71
|
};
|
|
65
|
-
export type LLMConfig = SharedLLMConfig & ClientOptions;
|
|
66
72
|
export type ProviderOptionsMap = {
|
|
67
73
|
[Providers.AZURE]: AzureClientOptions;
|
|
68
74
|
[Providers.OPENAI]: OpenAIClientOptions;
|
|
@@ -74,7 +80,6 @@ export type ProviderOptionsMap = {
|
|
|
74
80
|
[Providers.MISTRALAI]: MistralAIClientOptions;
|
|
75
81
|
[Providers.MISTRAL]: MistralAIClientOptions;
|
|
76
82
|
[Providers.OPENROUTER]: ChatOpenRouterCallOptions;
|
|
77
|
-
[Providers.BEDROCK_LEGACY]: BedrockClientOptions;
|
|
78
83
|
[Providers.BEDROCK]: BedrockConverseClientOptions;
|
|
79
84
|
[Providers.XAI]: XAIClientOptions;
|
|
80
85
|
};
|
|
@@ -85,11 +90,10 @@ export type ChatModelMap = {
|
|
|
85
90
|
[Providers.AZURE]: AzureChatOpenAI;
|
|
86
91
|
[Providers.DEEPSEEK]: ChatDeepSeek;
|
|
87
92
|
[Providers.VERTEXAI]: ChatVertexAI;
|
|
88
|
-
[Providers.ANTHROPIC]:
|
|
93
|
+
[Providers.ANTHROPIC]: CustomAnthropic;
|
|
89
94
|
[Providers.MISTRALAI]: ChatMistralAI;
|
|
90
95
|
[Providers.MISTRAL]: ChatMistralAI;
|
|
91
96
|
[Providers.OPENROUTER]: ChatOpenRouter;
|
|
92
|
-
[Providers.BEDROCK_LEGACY]: BedrockChat;
|
|
93
97
|
[Providers.BEDROCK]: ChatBedrockConverse;
|
|
94
98
|
[Providers.GOOGLE]: CustomChatGoogleGenerativeAI;
|
|
95
99
|
};
|
|
@@ -3,19 +3,48 @@ import type { BaseMessage } from '@langchain/core/messages';
|
|
|
3
3
|
import type { StructuredTool } from '@langchain/core/tools';
|
|
4
4
|
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
5
5
|
import type { BaseCallbackHandler, CallbackHandlerMethods } from '@langchain/core/callbacks/base';
|
|
6
|
-
import type * as graph from '@/graphs/Graph';
|
|
7
6
|
import type * as s from '@/types/stream';
|
|
8
7
|
import type * as e from '@/common/enum';
|
|
9
8
|
import type * as g from '@/types/graph';
|
|
10
9
|
import type * as l from '@/types/llm';
|
|
11
10
|
export type ZodObjectAny = z.ZodObject<any, any, any, any>;
|
|
12
11
|
export type BaseGraphConfig = {
|
|
13
|
-
type?: 'standard';
|
|
14
12
|
llmConfig: l.LLMConfig;
|
|
15
13
|
provider?: e.Providers;
|
|
16
14
|
clientOptions?: l.ClientOptions;
|
|
15
|
+
/** Optional compile options for workflow.compile() */
|
|
16
|
+
compileOptions?: g.CompileOptions;
|
|
17
17
|
};
|
|
18
|
-
export type
|
|
18
|
+
export type LegacyGraphConfig = BaseGraphConfig & {
|
|
19
|
+
type?: 'standard';
|
|
20
|
+
} & Omit<g.StandardGraphInput, 'provider' | 'clientOptions' | 'agents'> & Omit<g.AgentInputs, 'provider' | 'clientOptions' | 'agentId'>;
|
|
21
|
+
export type SupervisedGraphConfig = BaseGraphConfig & {
|
|
22
|
+
type: 'supervised';
|
|
23
|
+
/** Enable supervised router; when false, fall back to standard loop */
|
|
24
|
+
routerEnabled?: boolean;
|
|
25
|
+
/** Table-driven routing policy per stage */
|
|
26
|
+
routingPolicies?: Array<{
|
|
27
|
+
stage: string;
|
|
28
|
+
agents?: string[];
|
|
29
|
+
model?: e.Providers;
|
|
30
|
+
parallel?: boolean;
|
|
31
|
+
/** Optional simple condition on content/tools */
|
|
32
|
+
when?: 'always' | 'has_tools' | 'no_tools' | {
|
|
33
|
+
includes?: string[];
|
|
34
|
+
excludes?: string[];
|
|
35
|
+
};
|
|
36
|
+
}>;
|
|
37
|
+
/** Opt-in feature flags */
|
|
38
|
+
featureFlags?: {
|
|
39
|
+
multi_model_routing?: boolean;
|
|
40
|
+
fan_out?: boolean;
|
|
41
|
+
fan_out_retries?: number;
|
|
42
|
+
fan_out_backoff_ms?: number;
|
|
43
|
+
fan_out_concurrency?: number;
|
|
44
|
+
};
|
|
45
|
+
/** Optional per-stage model configs */
|
|
46
|
+
models?: Record<string, l.LLMConfig>;
|
|
47
|
+
} & Omit<g.StandardGraphInput, 'provider' | 'clientOptions'>;
|
|
19
48
|
export type RunTitleOptions = {
|
|
20
49
|
inputText: string;
|
|
21
50
|
provider: e.Providers;
|
|
@@ -57,18 +86,27 @@ export type TaskManagerGraphConfig = {
|
|
|
57
86
|
llmConfig: l.LLMConfig;
|
|
58
87
|
};
|
|
59
88
|
};
|
|
89
|
+
export type MultiAgentGraphConfig = {
|
|
90
|
+
type: 'multi-agent';
|
|
91
|
+
compileOptions?: g.CompileOptions;
|
|
92
|
+
agents: g.AgentInputs[];
|
|
93
|
+
edges: g.GraphEdge[];
|
|
94
|
+
};
|
|
95
|
+
export type StandardGraphConfig = Omit<MultiAgentGraphConfig, 'edges' | 'type'> & {
|
|
96
|
+
type?: 'standard';
|
|
97
|
+
signal?: AbortSignal;
|
|
98
|
+
};
|
|
60
99
|
export type RunConfig = {
|
|
61
100
|
runId: string;
|
|
62
|
-
graphConfig:
|
|
101
|
+
graphConfig: LegacyGraphConfig | StandardGraphConfig | MultiAgentGraphConfig;
|
|
63
102
|
customHandlers?: Record<string, g.EventHandler>;
|
|
64
103
|
returnContent?: boolean;
|
|
104
|
+
tokenCounter?: TokenCounter;
|
|
105
|
+
indexTokenCountMap?: Record<string, number>;
|
|
65
106
|
};
|
|
66
107
|
export type ProvidedCallbacks = (BaseCallbackHandler | CallbackHandlerMethods)[] | undefined;
|
|
67
108
|
export type TokenCounter = (message: BaseMessage) => number;
|
|
68
109
|
export type EventStreamOptions = {
|
|
69
|
-
callbacks?:
|
|
110
|
+
callbacks?: g.ClientCallbacks;
|
|
70
111
|
keepContent?: boolean;
|
|
71
|
-
maxContextTokens?: number;
|
|
72
|
-
tokenCounter?: TokenCounter;
|
|
73
|
-
indexTokenCountMap?: Record<string, number>;
|
|
74
112
|
};
|
|
@@ -3,6 +3,7 @@ import type { MessageContentImageUrl, MessageContentText, ToolMessage, BaseMessa
|
|
|
3
3
|
import type { ToolCall, ToolCallChunk } from '@langchain/core/messages/tool';
|
|
4
4
|
import type { LLMResult, Generation } from '@langchain/core/outputs';
|
|
5
5
|
import type { AnthropicContentBlock } from '@/llm/anthropic/types';
|
|
6
|
+
import type { Command } from '@langchain/langgraph';
|
|
6
7
|
import type { ToolEndEvent } from '@/types/tools';
|
|
7
8
|
import { StepTypes, ContentTypes, GraphEvents } from '@/common/enum';
|
|
8
9
|
export type HandleLLMEnd = (output: LLMResult, runId: string, parentRunId?: string, tags?: string[]) => void;
|
|
@@ -65,7 +66,7 @@ export type MessageCreationDetails = {
|
|
|
65
66
|
};
|
|
66
67
|
export type ToolEndData = {
|
|
67
68
|
input: string | Record<string, unknown>;
|
|
68
|
-
output?: ToolMessage;
|
|
69
|
+
output?: ToolMessage | Command;
|
|
69
70
|
};
|
|
70
71
|
export type ToolErrorData = {
|
|
71
72
|
id: string;
|
|
@@ -220,7 +221,7 @@ export type ToolCallPart = {
|
|
|
220
221
|
/** Type ("tool_call") according to Assistants Tool Call Structure */
|
|
221
222
|
type: ContentTypes.TOOL_CALL;
|
|
222
223
|
/** The name of the tool to be called */
|
|
223
|
-
name
|
|
224
|
+
name?: string;
|
|
224
225
|
/** The arguments to the tool call */
|
|
225
226
|
args?: string | Record<string, any>;
|
|
226
227
|
/** If provided, an identifier associated with the tool call */
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
2
|
+
/**
|
|
3
|
+
* Safely dispatches a custom event and properly awaits it to avoid
|
|
4
|
+
* race conditions where events are dispatched after run cleanup.
|
|
5
|
+
*/
|
|
6
|
+
export declare function safeDispatchCustomEvent(event: string, payload: unknown, config?: RunnableConfig): Promise<void>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-Agent Handler Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides a simple helper to create handlers with content aggregation for multi-agent scripts.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const { contentParts, aggregateContent, handlers } = createHandlers();
|
|
9
|
+
*
|
|
10
|
+
* // With callbacks
|
|
11
|
+
* const { contentParts, aggregateContent, handlers } = createHandlers({
|
|
12
|
+
* onRunStep: (event, data) => console.log('Step:', data),
|
|
13
|
+
* onRunStepCompleted: (event, data) => console.log('Completed:', data)
|
|
14
|
+
* });
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
import { GraphEvents } from '@/common';
|
|
18
|
+
import { createContentAggregator } from '@/stream';
|
|
19
|
+
import type * as t from '@/types';
|
|
20
|
+
interface HandlerCallbacks {
|
|
21
|
+
onRunStep?: (event: GraphEvents.ON_RUN_STEP, data: t.StreamEventData) => void;
|
|
22
|
+
onRunStepCompleted?: (event: GraphEvents.ON_RUN_STEP_COMPLETED, data: t.StreamEventData) => void;
|
|
23
|
+
onRunStepDelta?: (event: GraphEvents.ON_RUN_STEP_DELTA, data: t.StreamEventData) => void;
|
|
24
|
+
onMessageDelta?: (event: GraphEvents.ON_MESSAGE_DELTA, data: t.StreamEventData) => void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates handlers with content aggregation for multi-agent scripts
|
|
28
|
+
*/
|
|
29
|
+
export declare function createHandlers(callbacks?: HandlerCallbacks): {
|
|
30
|
+
contentParts: Array<t.MessageContentComplex | undefined>;
|
|
31
|
+
aggregateContent: ReturnType<typeof createContentAggregator>['aggregateContent'];
|
|
32
|
+
handlers: Record<string, t.EventHandler>;
|
|
33
|
+
};
|
|
34
|
+
export {};
|
|
@@ -1,3 +1,27 @@
|
|
|
1
1
|
import type { BaseMessage } from '@langchain/core/messages';
|
|
2
2
|
export declare function getTokenCountForMessage(message: BaseMessage, getTokenCount: (text: string) => number): number;
|
|
3
|
+
/**
|
|
4
|
+
* Creates a singleton token counter function that reuses the same encoder instance.
|
|
5
|
+
* This avoids creating multiple function closures and prevents potential memory issues.
|
|
6
|
+
*/
|
|
3
7
|
export declare const createTokenCounter: () => Promise<(message: BaseMessage) => number>;
|
|
8
|
+
/**
|
|
9
|
+
* Utility to manage the token encoder lifecycle explicitly.
|
|
10
|
+
* Useful for applications that need fine-grained control over resource management.
|
|
11
|
+
*/
|
|
12
|
+
export declare const TokenEncoderManager: {
|
|
13
|
+
/**
|
|
14
|
+
* Pre-initializes the encoder. This can be called during app startup
|
|
15
|
+
* to avoid lazy loading delays later.
|
|
16
|
+
*/
|
|
17
|
+
initialize(): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Clears the cached encoder and token counter.
|
|
20
|
+
* Useful for testing or when you need to force a fresh reload.
|
|
21
|
+
*/
|
|
22
|
+
reset(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Checks if the encoder has been initialized.
|
|
25
|
+
*/
|
|
26
|
+
isInitialized(): boolean;
|
|
27
|
+
};
|