@librechat/agents 2.4.321 → 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.
- package/dist/cjs/agents/AgentContext.cjs +218 -0
- package/dist/cjs/agents/AgentContext.cjs.map +1 -0
- package/dist/cjs/common/enum.cjs +14 -5
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/events.cjs +10 -6
- package/dist/cjs/events.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +309 -212
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +322 -0
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -0
- package/dist/cjs/llm/anthropic/index.cjs +54 -9
- package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/types.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +52 -6
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +22 -2
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/tools.cjs +29 -0
- package/dist/cjs/llm/anthropic/utils/tools.cjs.map +1 -0
- package/dist/cjs/llm/google/index.cjs +144 -0
- package/dist/cjs/llm/google/index.cjs.map +1 -0
- package/dist/cjs/llm/google/utils/common.cjs +477 -0
- package/dist/cjs/llm/google/utils/common.cjs.map +1 -0
- package/dist/cjs/llm/ollama/index.cjs +67 -0
- package/dist/cjs/llm/ollama/index.cjs.map +1 -0
- package/dist/cjs/llm/ollama/utils.cjs +158 -0
- package/dist/cjs/llm/ollama/utils.cjs.map +1 -0
- package/dist/cjs/llm/openai/index.cjs +389 -3
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/utils/index.cjs +672 -0
- package/dist/cjs/llm/openai/utils/index.cjs.map +1 -0
- package/dist/cjs/llm/providers.cjs +15 -15
- package/dist/cjs/llm/providers.cjs.map +1 -1
- package/dist/cjs/llm/text.cjs +14 -3
- package/dist/cjs/llm/text.cjs.map +1 -1
- package/dist/cjs/llm/vertexai/index.cjs +330 -0
- package/dist/cjs/llm/vertexai/index.cjs.map +1 -0
- package/dist/cjs/main.cjs +11 -0
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/run.cjs +120 -81
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/stream.cjs +85 -51
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +10 -4
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/handlers.cjs +119 -13
- package/dist/cjs/tools/handlers.cjs.map +1 -1
- package/dist/cjs/tools/search/anthropic.cjs +40 -0
- package/dist/cjs/tools/search/anthropic.cjs.map +1 -0
- package/dist/cjs/tools/search/firecrawl.cjs +61 -13
- package/dist/cjs/tools/search/firecrawl.cjs.map +1 -1
- package/dist/cjs/tools/search/format.cjs +9 -3
- package/dist/cjs/tools/search/format.cjs.map +1 -1
- package/dist/cjs/tools/search/rerankers.cjs +35 -50
- package/dist/cjs/tools/search/rerankers.cjs.map +1 -1
- package/dist/cjs/tools/search/schema.cjs +70 -0
- package/dist/cjs/tools/search/schema.cjs.map +1 -0
- package/dist/cjs/tools/search/search.cjs +145 -38
- package/dist/cjs/tools/search/search.cjs.map +1 -1
- package/dist/cjs/tools/search/tool.cjs +165 -48
- package/dist/cjs/tools/search/tool.cjs.map +1 -1
- package/dist/cjs/tools/search/utils.cjs +34 -5
- package/dist/cjs/tools/search/utils.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/title.cjs +57 -21
- package/dist/cjs/utils/title.cjs.map +1 -1
- package/dist/cjs/utils/tokens.cjs +54 -7
- package/dist/cjs/utils/tokens.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +216 -0
- package/dist/esm/agents/AgentContext.mjs.map +1 -0
- package/dist/esm/common/enum.mjs +15 -6
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/events.mjs +10 -6
- package/dist/esm/events.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +311 -214
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +320 -0
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -0
- package/dist/esm/llm/anthropic/index.mjs +54 -9
- package/dist/esm/llm/anthropic/index.mjs.map +1 -1
- package/dist/esm/llm/anthropic/types.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs +52 -6
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs +22 -2
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/tools.mjs +27 -0
- package/dist/esm/llm/anthropic/utils/tools.mjs.map +1 -0
- package/dist/esm/llm/google/index.mjs +142 -0
- package/dist/esm/llm/google/index.mjs.map +1 -0
- package/dist/esm/llm/google/utils/common.mjs +471 -0
- package/dist/esm/llm/google/utils/common.mjs.map +1 -0
- package/dist/esm/llm/ollama/index.mjs +65 -0
- package/dist/esm/llm/ollama/index.mjs.map +1 -0
- package/dist/esm/llm/ollama/utils.mjs +155 -0
- package/dist/esm/llm/ollama/utils.mjs.map +1 -0
- package/dist/esm/llm/openai/index.mjs +388 -4
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/llm/openai/utils/index.mjs +666 -0
- package/dist/esm/llm/openai/utils/index.mjs.map +1 -0
- package/dist/esm/llm/providers.mjs +5 -5
- package/dist/esm/llm/providers.mjs.map +1 -1
- package/dist/esm/llm/text.mjs +14 -3
- package/dist/esm/llm/text.mjs.map +1 -1
- package/dist/esm/llm/vertexai/index.mjs +328 -0
- package/dist/esm/llm/vertexai/index.mjs.map +1 -0
- package/dist/esm/main.mjs +6 -5
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/run.mjs +121 -83
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/stream.mjs +87 -54
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +10 -4
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/handlers.mjs +119 -15
- package/dist/esm/tools/handlers.mjs.map +1 -1
- package/dist/esm/tools/search/anthropic.mjs +37 -0
- package/dist/esm/tools/search/anthropic.mjs.map +1 -0
- package/dist/esm/tools/search/firecrawl.mjs +61 -13
- package/dist/esm/tools/search/firecrawl.mjs.map +1 -1
- package/dist/esm/tools/search/format.mjs +10 -4
- package/dist/esm/tools/search/format.mjs.map +1 -1
- package/dist/esm/tools/search/rerankers.mjs +35 -50
- package/dist/esm/tools/search/rerankers.mjs.map +1 -1
- package/dist/esm/tools/search/schema.mjs +61 -0
- package/dist/esm/tools/search/schema.mjs.map +1 -0
- package/dist/esm/tools/search/search.mjs +146 -39
- package/dist/esm/tools/search/search.mjs.map +1 -1
- package/dist/esm/tools/search/tool.mjs +164 -47
- package/dist/esm/tools/search/tool.mjs.map +1 -1
- package/dist/esm/tools/search/utils.mjs +33 -6
- package/dist/esm/tools/search/utils.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/title.mjs +57 -22
- package/dist/esm/utils/title.mjs.map +1 -1
- package/dist/esm/utils/tokens.mjs +54 -8
- package/dist/esm/utils/tokens.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +91 -0
- package/dist/types/common/enum.d.ts +15 -6
- package/dist/types/events.d.ts +5 -4
- package/dist/types/graphs/Graph.d.ts +64 -67
- package/dist/types/graphs/MultiAgentGraph.d.ts +37 -0
- package/dist/types/graphs/index.d.ts +1 -0
- package/dist/types/llm/anthropic/index.d.ts +11 -0
- package/dist/types/llm/anthropic/types.d.ts +9 -3
- package/dist/types/llm/anthropic/utils/message_inputs.d.ts +1 -1
- package/dist/types/llm/anthropic/utils/output_parsers.d.ts +4 -4
- package/dist/types/llm/anthropic/utils/tools.d.ts +3 -0
- package/dist/types/llm/google/index.d.ts +13 -0
- package/dist/types/llm/google/types.d.ts +32 -0
- package/dist/types/llm/google/utils/common.d.ts +19 -0
- package/dist/types/llm/google/utils/tools.d.ts +10 -0
- package/dist/types/llm/google/utils/zod_to_genai_parameters.d.ts +14 -0
- package/dist/types/llm/ollama/index.d.ts +7 -0
- package/dist/types/llm/ollama/utils.d.ts +7 -0
- package/dist/types/llm/openai/index.d.ts +72 -3
- package/dist/types/llm/openai/types.d.ts +10 -0
- package/dist/types/llm/openai/utils/index.d.ts +20 -0
- package/dist/types/llm/text.d.ts +1 -1
- package/dist/types/llm/vertexai/index.d.ts +293 -0
- package/dist/types/messages/reducer.d.ts +9 -0
- package/dist/types/run.d.ts +19 -12
- package/dist/types/scripts/ant_web_search.d.ts +1 -0
- package/dist/types/scripts/args.d.ts +2 -1
- package/dist/types/scripts/handoff-test.d.ts +1 -0
- package/dist/types/scripts/multi-agent-conditional.d.ts +1 -0
- package/dist/types/scripts/multi-agent-parallel.d.ts +1 -0
- package/dist/types/scripts/multi-agent-sequence.d.ts +1 -0
- package/dist/types/scripts/multi-agent-test.d.ts +1 -0
- package/dist/types/stream.d.ts +10 -3
- package/dist/types/tools/CodeExecutor.d.ts +2 -2
- package/dist/types/tools/ToolNode.d.ts +1 -1
- package/dist/types/tools/handlers.d.ts +17 -4
- package/dist/types/tools/search/anthropic.d.ts +16 -0
- package/dist/types/tools/search/firecrawl.d.ts +16 -0
- package/dist/types/tools/search/rerankers.d.ts +8 -5
- package/dist/types/tools/search/schema.d.ts +16 -0
- package/dist/types/tools/search/tool.d.ts +13 -0
- package/dist/types/tools/search/types.d.ts +64 -9
- package/dist/types/tools/search/utils.d.ts +9 -2
- package/dist/types/types/graph.d.ts +95 -15
- package/dist/types/types/llm.d.ts +24 -10
- package/dist/types/types/run.d.ts +46 -8
- package/dist/types/types/stream.d.ts +16 -2
- package/dist/types/types/tools.d.ts +1 -1
- package/dist/types/utils/events.d.ts +6 -0
- package/dist/types/utils/title.d.ts +2 -1
- package/dist/types/utils/tokens.d.ts +24 -0
- package/package.json +35 -18
- package/src/agents/AgentContext.ts +315 -0
- package/src/common/enum.ts +14 -5
- package/src/events.ts +24 -13
- package/src/graphs/Graph.ts +495 -312
- package/src/graphs/MultiAgentGraph.ts +381 -0
- package/src/graphs/index.ts +2 -1
- package/src/llm/anthropic/Jacob_Lee_Resume_2023.pdf +0 -0
- package/src/llm/anthropic/index.ts +78 -13
- package/src/llm/anthropic/llm.spec.ts +491 -115
- package/src/llm/anthropic/types.ts +39 -3
- package/src/llm/anthropic/utils/message_inputs.ts +67 -11
- package/src/llm/anthropic/utils/message_outputs.ts +21 -2
- package/src/llm/anthropic/utils/output_parsers.ts +25 -6
- package/src/llm/anthropic/utils/tools.ts +29 -0
- package/src/llm/google/index.ts +218 -0
- package/src/llm/google/types.ts +43 -0
- package/src/llm/google/utils/common.ts +646 -0
- package/src/llm/google/utils/tools.ts +160 -0
- package/src/llm/google/utils/zod_to_genai_parameters.ts +86 -0
- package/src/llm/ollama/index.ts +89 -0
- package/src/llm/ollama/utils.ts +193 -0
- package/src/llm/openai/index.ts +600 -14
- package/src/llm/openai/types.ts +24 -0
- package/src/llm/openai/utils/index.ts +912 -0
- package/src/llm/openai/utils/isReasoningModel.test.ts +90 -0
- package/src/llm/providers.ts +10 -9
- package/src/llm/text.ts +26 -7
- package/src/llm/vertexai/index.ts +360 -0
- package/src/messages/reducer.ts +80 -0
- package/src/run.ts +181 -112
- package/src/scripts/ant_web_search.ts +158 -0
- package/src/scripts/args.ts +12 -8
- package/src/scripts/cli4.ts +29 -21
- package/src/scripts/cli5.ts +29 -21
- package/src/scripts/code_exec.ts +54 -23
- package/src/scripts/code_exec_files.ts +48 -17
- package/src/scripts/code_exec_simple.ts +46 -27
- package/src/scripts/handoff-test.ts +135 -0
- package/src/scripts/image.ts +52 -20
- package/src/scripts/multi-agent-conditional.ts +220 -0
- package/src/scripts/multi-agent-example-output.md +110 -0
- package/src/scripts/multi-agent-parallel.ts +337 -0
- package/src/scripts/multi-agent-sequence.ts +212 -0
- package/src/scripts/multi-agent-test.ts +186 -0
- package/src/scripts/search.ts +4 -12
- package/src/scripts/simple.ts +25 -10
- package/src/scripts/tools.ts +48 -18
- package/src/specs/anthropic.simple.test.ts +150 -34
- package/src/specs/azure.simple.test.ts +325 -0
- package/src/specs/openai.simple.test.ts +140 -33
- package/src/specs/openrouter.simple.test.ts +107 -0
- package/src/specs/prune.test.ts +4 -9
- package/src/specs/reasoning.test.ts +80 -44
- package/src/specs/token-memoization.test.ts +39 -0
- package/src/stream.test.ts +94 -0
- package/src/stream.ts +139 -60
- package/src/tools/ToolNode.ts +21 -7
- package/src/tools/handlers.ts +192 -18
- package/src/tools/search/anthropic.ts +51 -0
- package/src/tools/search/firecrawl.ts +78 -24
- package/src/tools/search/format.ts +10 -5
- package/src/tools/search/rerankers.ts +50 -62
- package/src/tools/search/schema.ts +63 -0
- package/src/tools/search/search.ts +167 -34
- package/src/tools/search/tool.ts +222 -46
- package/src/tools/search/types.ts +65 -10
- package/src/tools/search/utils.ts +37 -5
- package/src/types/graph.ts +272 -103
- package/src/types/llm.ts +25 -12
- package/src/types/run.ts +51 -13
- package/src/types/stream.ts +22 -1
- package/src/types/tools.ts +16 -10
- package/src/utils/events.ts +32 -0
- package/src/utils/llmConfig.ts +20 -8
- package/src/utils/title.ts +104 -30
- package/src/utils/tokens.ts +69 -10
package/src/types/graph.ts
CHANGED
|
@@ -1,77 +1,216 @@
|
|
|
1
1
|
// src/types/graph.ts
|
|
2
|
-
import type {
|
|
3
|
-
|
|
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 {
|
|
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 {
|
|
9
|
-
|
|
10
|
-
|
|
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(
|
|
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> =
|
|
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
|
|
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
|
|
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
|
|
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
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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 =
|
|
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
|
-
|
|
152
|
-
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
|
|
94
|
+
export type SharedLLMConfig = {
|
|
88
95
|
provider: Providers;
|
|
89
|
-
}
|
|
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]:
|
|
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]:
|
|
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
|
|
25
|
-
|
|
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?:
|
|
121
|
+
callbacks?: g.ClientCallbacks;
|
|
80
122
|
keepContent?: boolean;
|
|
81
|
-
/* Context Management */
|
|
82
|
-
maxContextTokens?: number;
|
|
83
|
-
tokenCounter?: TokenCounter;
|
|
84
|
-
indexTokenCountMap?: Record<string, number>;
|
|
85
123
|
};
|
package/src/types/stream.ts
CHANGED
|
@@ -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
|