@librechat/agents 3.0.0-rc1 → 3.0.0-rc10
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/common/enum.cjs +1 -0
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +0 -1
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +229 -44
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs +33 -0
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/run.cjs +28 -15
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/stream.cjs +1 -1
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/esm/common/enum.mjs +1 -0
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +0 -1
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +230 -45
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +33 -0
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/run.mjs +28 -15
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/stream.mjs +1 -1
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/types/common/enum.d.ts +2 -1
- package/dist/types/graphs/MultiAgentGraph.d.ts +12 -2
- package/dist/types/llm/openai/index.d.ts +10 -0
- package/dist/types/run.d.ts +1 -1
- package/dist/types/types/graph.d.ts +38 -4
- package/dist/types/types/llm.d.ts +1 -0
- package/dist/types/types/run.d.ts +5 -1
- package/package.json +10 -2
- package/src/common/enum.ts +1 -0
- package/src/graphs/Graph.ts +0 -1
- package/src/graphs/MultiAgentGraph.ts +267 -50
- package/src/llm/openai/index.ts +41 -0
- package/src/run.ts +38 -27
- package/src/scripts/multi-agent-chain.ts +278 -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 +27 -23
- package/src/scripts/multi-agent-supervisor.ts +362 -0
- 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 +233 -0
- package/src/stream.ts +4 -1
- package/src/types/graph.ts +51 -5
- package/src/types/llm.ts +1 -0
- package/src/types/run.ts +6 -1
- 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/handoff-test.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/multi-agent-conditional.d.ts +0 -1
- package/dist/types/scripts/multi-agent-parallel.d.ts +0 -1
- package/dist/types/scripts/multi-agent-sequence.d.ts +0 -1
- package/dist/types/scripts/multi-agent-test.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/src/scripts/multi-agent-example-output.md +0 -110
|
@@ -2,7 +2,17 @@ import type * as t from '@/types';
|
|
|
2
2
|
import { StandardGraph } from './Graph';
|
|
3
3
|
/**
|
|
4
4
|
* MultiAgentGraph extends StandardGraph to support dynamic multi-agent workflows
|
|
5
|
-
* with handoffs, fan-in/fan-out, and other composable patterns
|
|
5
|
+
* with handoffs, fan-in/fan-out, and other composable patterns.
|
|
6
|
+
*
|
|
7
|
+
* Key behavior:
|
|
8
|
+
* - Agents with ONLY handoff edges: Can dynamically route to any handoff destination
|
|
9
|
+
* - Agents with ONLY direct edges: Always follow their direct edges
|
|
10
|
+
* - Agents with BOTH: Use Command for exclusive routing (handoff OR direct, not both)
|
|
11
|
+
* - If handoff occurs: Only the handoff destination executes
|
|
12
|
+
* - If no handoff: Direct edges execute (potentially in parallel)
|
|
13
|
+
*
|
|
14
|
+
* This enables the common pattern where an agent either delegates (handoff)
|
|
15
|
+
* OR continues its workflow (direct edges), but not both simultaneously.
|
|
6
16
|
*/
|
|
7
17
|
export declare class MultiAgentGraph extends StandardGraph {
|
|
8
18
|
private edges;
|
|
@@ -33,5 +43,5 @@ export declare class MultiAgentGraph extends StandardGraph {
|
|
|
33
43
|
/**
|
|
34
44
|
* Create the multi-agent workflow with dynamic handoffs
|
|
35
45
|
*/
|
|
36
|
-
createWorkflow(): t.
|
|
46
|
+
createWorkflow(): t.CompiledMultiAgentWorkflow;
|
|
37
47
|
}
|
|
@@ -40,6 +40,10 @@ export declare class CustomAzureOpenAIClient extends AzureOpenAIClient {
|
|
|
40
40
|
}
|
|
41
41
|
/** @ts-expect-error We are intentionally overriding `getReasoningParams` */
|
|
42
42
|
export declare class ChatOpenAI extends OriginalChatOpenAI<t.ChatOpenAICallOptions> {
|
|
43
|
+
_lc_stream_delay?: number;
|
|
44
|
+
constructor(fields?: t.ChatOpenAICallOptions & {
|
|
45
|
+
_lc_stream_delay?: number;
|
|
46
|
+
} & t.OpenAIChatInput['modelKwargs']);
|
|
43
47
|
get exposedClient(): CustomOpenAIClient;
|
|
44
48
|
protected _getClientOptions(options?: OpenAICoreRequestOptions): OpenAICoreRequestOptions;
|
|
45
49
|
/**
|
|
@@ -53,6 +57,10 @@ export declare class ChatOpenAI extends OriginalChatOpenAI<t.ChatOpenAICallOptio
|
|
|
53
57
|
}
|
|
54
58
|
/** @ts-expect-error We are intentionally overriding `getReasoningParams` */
|
|
55
59
|
export declare class AzureChatOpenAI extends OriginalAzureChatOpenAI {
|
|
60
|
+
_lc_stream_delay?: number;
|
|
61
|
+
constructor(fields?: t.AzureOpenAIInput & {
|
|
62
|
+
_lc_stream_delay?: number;
|
|
63
|
+
});
|
|
56
64
|
get exposedClient(): CustomOpenAIClient;
|
|
57
65
|
/**
|
|
58
66
|
* Returns backwards compatible reasoning parameters from constructor params and call options
|
|
@@ -84,6 +92,7 @@ export interface XAIUsageMetadata extends OpenAIClient.Completions.CompletionUsa
|
|
|
84
92
|
num_sources_used?: number;
|
|
85
93
|
}
|
|
86
94
|
export declare class ChatXAI extends OriginalChatXAI {
|
|
95
|
+
_lc_stream_delay?: number;
|
|
87
96
|
constructor(fields?: Partial<ChatXAIInput> & {
|
|
88
97
|
configuration?: {
|
|
89
98
|
baseURL?: string;
|
|
@@ -91,6 +100,7 @@ export declare class ChatXAI extends OriginalChatXAI {
|
|
|
91
100
|
clientConfig?: {
|
|
92
101
|
baseURL?: string;
|
|
93
102
|
};
|
|
103
|
+
_lc_stream_delay?: number;
|
|
94
104
|
});
|
|
95
105
|
get exposedClient(): CustomOpenAIClient;
|
|
96
106
|
protected _getClientOptions(options?: OpenAICoreRequestOptions): OpenAICoreRequestOptions;
|
package/dist/types/run.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare const defaultOmitOptions: Set<string>;
|
|
|
7
7
|
export declare class Run<_T extends t.BaseGraphState> {
|
|
8
8
|
id: string;
|
|
9
9
|
private tokenCounter?;
|
|
10
|
-
private handlerRegistry
|
|
10
|
+
private handlerRegistry?;
|
|
11
11
|
private indexTokenCountMap?;
|
|
12
12
|
graphRunnable?: t.CompiledStateWorkflow;
|
|
13
13
|
Graph: StandardGraph | MultiAgentGraph | undefined;
|
|
@@ -28,6 +28,9 @@ export type SystemCallbacks = {
|
|
|
28
28
|
export type BaseGraphState = {
|
|
29
29
|
messages: BaseMessage[];
|
|
30
30
|
};
|
|
31
|
+
export type MultiAgentGraphState = BaseGraphState & {
|
|
32
|
+
agentMessages?: BaseMessage[];
|
|
33
|
+
};
|
|
31
34
|
export type IState = BaseGraphState;
|
|
32
35
|
export interface EventHandler {
|
|
33
36
|
handle(event: string, data: StreamEventData | ModelEndData | RunStep | RunStepDeltaEvent | MessageDeltaEvent | ReasoningDeltaEvent | {
|
|
@@ -46,6 +49,19 @@ export type CompiledStateWorkflow = CompiledStateGraph<StateType<{
|
|
|
46
49
|
}, {
|
|
47
50
|
messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
48
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>;
|
|
49
65
|
export type CompiledAgentWorfklow = CompiledStateGraph<{
|
|
50
66
|
messages: BaseMessage[];
|
|
51
67
|
}, {
|
|
@@ -185,17 +201,35 @@ export type StandardGraphInput = {
|
|
|
185
201
|
indexTokenCountMap?: Record<string, number>;
|
|
186
202
|
};
|
|
187
203
|
export type GraphEdge = {
|
|
188
|
-
/**
|
|
204
|
+
/** Agent ID, use a list for multiple sources */
|
|
189
205
|
from: string | string[];
|
|
190
|
-
/**
|
|
206
|
+
/** Agent ID, use a list for multiple destinations */
|
|
191
207
|
to: string | string[];
|
|
192
208
|
description?: string;
|
|
193
209
|
/** Can return boolean or specific destination(s) */
|
|
194
210
|
condition?: (state: BaseGraphState) => boolean | string | string[];
|
|
195
211
|
/** 'handoff' creates tools for dynamic routing, 'direct' creates direct edges, which also allow parallel execution */
|
|
196
212
|
edgeType?: 'handoff' | 'direct';
|
|
197
|
-
/**
|
|
198
|
-
|
|
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;
|
|
199
233
|
};
|
|
200
234
|
export type MultiAgentGraphInput = StandardGraphInput & {
|
|
201
235
|
edges: GraphEdge[];
|
|
@@ -61,6 +61,7 @@ export type XAIClientOptions = ChatXAIInput;
|
|
|
61
61
|
export type ClientOptions = OpenAIClientOptions | AzureClientOptions | OllamaClientOptions | AnthropicClientOptions | MistralAIClientOptions | VertexAIClientOptions | BedrockClientOptions | BedrockConverseClientOptions | GoogleClientOptions | DeepSeekClientOptions | XAIClientOptions;
|
|
62
62
|
export type SharedLLMConfig = {
|
|
63
63
|
provider: Providers;
|
|
64
|
+
_lc_stream_delay?: number;
|
|
64
65
|
};
|
|
65
66
|
export type LLMConfig = SharedLLMConfig & ClientOptions & {
|
|
66
67
|
/** Optional provider fallbacks in order of attempt */
|
|
@@ -92,9 +92,13 @@ export type MultiAgentGraphConfig = {
|
|
|
92
92
|
agents: g.AgentInputs[];
|
|
93
93
|
edges: g.GraphEdge[];
|
|
94
94
|
};
|
|
95
|
+
export type StandardGraphConfig = Omit<MultiAgentGraphConfig, 'edges' | 'type'> & {
|
|
96
|
+
type?: 'standard';
|
|
97
|
+
signal?: AbortSignal;
|
|
98
|
+
};
|
|
95
99
|
export type RunConfig = {
|
|
96
100
|
runId: string;
|
|
97
|
-
graphConfig: LegacyGraphConfig | MultiAgentGraphConfig;
|
|
101
|
+
graphConfig: LegacyGraphConfig | StandardGraphConfig | MultiAgentGraphConfig;
|
|
98
102
|
customHandlers?: Record<string, g.EventHandler>;
|
|
99
103
|
returnContent?: boolean;
|
|
100
104
|
tokenCounter?: TokenCounter;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@librechat/agents",
|
|
3
|
-
"version": "3.0.00-
|
|
3
|
+
"version": "3.0.00-rc10",
|
|
4
4
|
"main": "./dist/cjs/main.cjs",
|
|
5
5
|
"module": "./dist/esm/main.mjs",
|
|
6
6
|
"types": "./dist/types/index.d.ts",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"image": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/image.ts --provider 'google' --name 'Jo' --location 'New York, NY'",
|
|
48
48
|
"code_exec_files": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/code_exec_files.ts --provider 'openAI' --name 'Jo' --location 'New York, NY'",
|
|
49
49
|
"code_exec_simple": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/code_exec_simple.ts --provider 'google' --name 'Jo' --location 'New York, NY'",
|
|
50
|
-
"simple": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/simple.ts --provider '
|
|
50
|
+
"simple": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/simple.ts --provider 'openAI' --name 'Jo' --location 'New York, NY'",
|
|
51
51
|
"caching": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/caching.ts --name 'Jo' --location 'New York, NY'",
|
|
52
52
|
"thinking": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/thinking.ts --name 'Jo' --location 'New York, NY'",
|
|
53
53
|
"memory": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/memory.ts --provider 'openAI' --name 'Jo' --location 'New York, NY'",
|
|
@@ -57,9 +57,16 @@
|
|
|
57
57
|
"abort": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/abort.ts --provider 'openAI' --name 'Jo' --location 'New York, NY'",
|
|
58
58
|
"start:cli2": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/cli2.ts --provider 'anthropic' --name 'Jo' --location 'New York, NY'",
|
|
59
59
|
"multi-agent-test": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/multi-agent-test.ts",
|
|
60
|
+
"test-tools-before-handoff": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/test-tools-before-handoff.ts",
|
|
60
61
|
"multi-agent-parallel": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/multi-agent-parallel.ts",
|
|
62
|
+
"multi-agent-chain": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/multi-agent-chain.ts",
|
|
61
63
|
"multi-agent-sequence": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/multi-agent-sequence.ts",
|
|
62
64
|
"multi-agent-conditional": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/multi-agent-conditional.ts",
|
|
65
|
+
"multi-agent-supervisor": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/multi-agent-supervisor.ts",
|
|
66
|
+
"multi-agent-list-handoff": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/test-multi-agent-list-handoff.ts",
|
|
67
|
+
"multi-agent-hybrid-flow": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/multi-agent-hybrid-flow.ts",
|
|
68
|
+
"test-handoff-input": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/test-handoff-input.ts",
|
|
69
|
+
"test-custom-prompt-key": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/test-custom-prompt-key.ts",
|
|
63
70
|
"script2": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/proto/example_test.ts",
|
|
64
71
|
"script3": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/proto/example_test_anthropic.ts",
|
|
65
72
|
"script4": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/cli4.ts --name 'Jo' --location 'New York, NY'",
|
|
@@ -111,6 +118,7 @@
|
|
|
111
118
|
"devDependencies": {
|
|
112
119
|
"@anthropic-ai/vertex-sdk": "^0.12.0",
|
|
113
120
|
"@eslint/compat": "^1.2.7",
|
|
121
|
+
"@langchain/tavily": "^0.1.5",
|
|
114
122
|
"@rollup/plugin-alias": "^5.1.0",
|
|
115
123
|
"@rollup/plugin-commonjs": "^28.0.3",
|
|
116
124
|
"@rollup/plugin-json": "^6.1.0",
|
package/src/common/enum.ts
CHANGED
package/src/graphs/Graph.ts
CHANGED
|
@@ -380,7 +380,6 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
|
|
|
380
380
|
currentTools?: t.GraphTools;
|
|
381
381
|
currentToolMap?: t.ToolMap;
|
|
382
382
|
}): CustomToolNode<t.BaseGraphState> | ToolNode<t.BaseGraphState> {
|
|
383
|
-
// return new ToolNode<t.BaseGraphState>(this.tools);
|
|
384
383
|
return new CustomToolNode<t.BaseGraphState>({
|
|
385
384
|
tools: (currentTools as t.GenericTool[] | undefined) ?? [],
|
|
386
385
|
toolMap: currentToolMap,
|