@librechat/agents 3.6.15 → 3.6.16
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/README.md +41 -0
- package/dist/cjs/agents/AgentContext.cjs +1 -1
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +9 -7
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/llm/init.cjs +1 -0
- package/dist/cjs/llm/init.cjs.map +1 -1
- package/dist/cjs/llm/invoke.cjs +9 -2
- package/dist/cjs/llm/invoke.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs +1 -1
- package/dist/cjs/llm/prepareProviderRequest.cjs +6 -3
- package/dist/cjs/llm/prepareProviderRequest.cjs.map +1 -1
- package/dist/cjs/llm/providerRegistry.cjs +69 -0
- package/dist/cjs/llm/providerRegistry.cjs.map +1 -0
- package/dist/cjs/llm/providers.cjs +38 -25
- package/dist/cjs/llm/providers.cjs.map +1 -1
- package/dist/cjs/llm/request.cjs +6 -4
- package/dist/cjs/llm/request.cjs.map +1 -1
- package/dist/cjs/llm/truncation.cjs +2 -1
- package/dist/cjs/llm/truncation.cjs.map +1 -1
- package/dist/cjs/main.cjs +18 -15
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/cjs/messages/prune.cjs +8 -4
- package/dist/cjs/messages/prune.cjs.map +1 -1
- package/dist/cjs/provider-registration.cjs +4 -0
- package/dist/cjs/run.cjs +2 -2
- package/dist/cjs/stream.cjs +1 -1
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/summarization/node.cjs +2 -2
- package/dist/cjs/summarization/node.cjs.map +1 -1
- package/dist/cjs/utils/llm.cjs +6 -4
- package/dist/cjs/utils/llm.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +1 -1
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +10 -8
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/llm/init.mjs +1 -0
- package/dist/esm/llm/init.mjs.map +1 -1
- package/dist/esm/llm/invoke.mjs +9 -2
- package/dist/esm/llm/invoke.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +1 -1
- package/dist/esm/llm/prepareProviderRequest.mjs +7 -4
- package/dist/esm/llm/prepareProviderRequest.mjs.map +1 -1
- package/dist/esm/llm/providerRegistry.mjs +64 -0
- package/dist/esm/llm/providerRegistry.mjs.map +1 -0
- package/dist/esm/llm/providers.mjs +36 -22
- package/dist/esm/llm/providers.mjs.map +1 -1
- package/dist/esm/llm/request.mjs +6 -4
- package/dist/esm/llm/request.mjs.map +1 -1
- package/dist/esm/llm/truncation.mjs +2 -1
- package/dist/esm/llm/truncation.mjs.map +1 -1
- package/dist/esm/main.mjs +12 -10
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/esm/messages/prune.mjs +8 -4
- package/dist/esm/messages/prune.mjs.map +1 -1
- package/dist/esm/provider-registration.mjs +3 -0
- package/dist/esm/run.mjs +2 -2
- package/dist/esm/stream.mjs +1 -1
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/summarization/node.mjs +2 -2
- package/dist/esm/summarization/node.mjs.map +1 -1
- package/dist/esm/utils/llm.mjs +6 -4
- package/dist/esm/utils/llm.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +5 -5
- package/dist/types/index.d.ts +2 -0
- package/dist/types/llm/contextOverflowRecovery.d.ts +2 -2
- package/dist/types/llm/init.d.ts +21 -14
- package/dist/types/llm/invoke.d.ts +5 -6
- package/dist/types/llm/prepareProviderRequest.d.ts +5 -6
- package/dist/types/llm/providerRegistry.d.ts +11 -0
- package/dist/types/llm/providers.d.ts +4 -5
- package/dist/types/llm/request.d.ts +2 -3
- package/dist/types/llm/truncation.d.ts +2 -2
- package/dist/types/messages/core.d.ts +1 -2
- package/dist/types/messages/format.d.ts +3 -3
- package/dist/types/messages/prune.d.ts +3 -2
- package/dist/types/provider-registration.d.ts +15 -0
- package/dist/types/stream.d.ts +1 -2
- package/dist/types/summarization/node.d.ts +1 -2
- package/dist/types/types/activityLabel.d.ts +3 -4
- package/dist/types/types/graph.d.ts +4 -5
- package/dist/types/types/llm.d.ts +54 -13
- package/dist/types/types/reasoningLabel.d.ts +2 -3
- package/dist/types/types/run.d.ts +3 -3
- package/dist/types/types/summarize.d.ts +2 -2
- package/dist/types/utils/errors.d.ts +3 -3
- package/dist/types/utils/llm.d.ts +4 -4
- package/dist/types/utils/llmConfig.d.ts +2 -2
- package/package.json +9 -1
- package/src/agents/AgentContext.ts +27 -26
- package/src/graphs/Graph.ts +14 -14
- package/src/index.ts +5 -0
- package/src/llm/contextOverflowRecovery.ts +2 -2
- package/src/llm/init.ts +40 -17
- package/src/llm/invoke.ts +36 -21
- package/src/llm/prepareProviderRequest.ts +19 -18
- package/src/llm/providerRegistry.ts +134 -0
- package/src/llm/providers.ts +73 -30
- package/src/llm/request.ts +10 -6
- package/src/llm/truncation.ts +9 -3
- package/src/messages/core.ts +2 -2
- package/src/messages/format.ts +14 -16
- package/src/messages/prune.ts +22 -17
- package/src/provider-registration.ts +29 -0
- package/src/run.ts +1 -1
- package/src/session/AgentSession.ts +1 -1
- package/src/stream.ts +7 -8
- package/src/summarization/node.ts +7 -7
- package/src/types/activityLabel.ts +3 -4
- package/src/types/graph.ts +5 -5
- package/src/types/llm.ts +95 -13
- package/src/types/reasoningLabel.ts +2 -3
- package/src/types/run.ts +3 -3
- package/src/types/summarize.ts +2 -2
- package/src/utils/errors.ts +3 -3
- package/src/utils/llm.ts +22 -15
- package/src/utils/llmConfig.ts +4 -4
|
@@ -657,7 +657,7 @@ async function executeSummarizationWithFallback(params: {
|
|
|
657
657
|
* `log('error', ...)` path below rather than bubbling up silently.
|
|
658
658
|
*/
|
|
659
659
|
const summarizationModel = initializeModel({
|
|
660
|
-
provider: clientConfig.provider
|
|
660
|
+
provider: clientConfig.provider,
|
|
661
661
|
clientOptions: clientConfig.clientOptions as t.ClientOptions,
|
|
662
662
|
tools: agentContext.getToolsForBinding(),
|
|
663
663
|
}) as t.ChatModel;
|
|
@@ -670,13 +670,13 @@ async function executeSummarizationWithFallback(params: {
|
|
|
670
670
|
priorSummaryText,
|
|
671
671
|
config: summarizeConfig,
|
|
672
672
|
stepId,
|
|
673
|
-
provider: clientConfig.provider
|
|
673
|
+
provider: clientConfig.provider,
|
|
674
674
|
reasoningKey: agentContext.reasoningKey,
|
|
675
675
|
graph,
|
|
676
676
|
usePromptCache,
|
|
677
677
|
promptCacheTtl:
|
|
678
|
-
|
|
679
|
-
|
|
678
|
+
clientConfig.provider === Providers.ANTHROPIC ||
|
|
679
|
+
clientConfig.provider === Providers.OPENROUTER
|
|
680
680
|
? resolvePromptCacheTtl(
|
|
681
681
|
(
|
|
682
682
|
clientConfig.clientOptions as {
|
|
@@ -737,7 +737,7 @@ async function executeSummarizationWithFallback(params: {
|
|
|
737
737
|
const onChunk = createSummarizationChunkHandler({
|
|
738
738
|
stepId,
|
|
739
739
|
config: traceConfig(summarizeConfig, 'cache_hit_compaction'),
|
|
740
|
-
provider: clientConfig.provider
|
|
740
|
+
provider: clientConfig.provider,
|
|
741
741
|
reasoningKey: agentContext.reasoningKey,
|
|
742
742
|
graph,
|
|
743
743
|
});
|
|
@@ -1509,7 +1509,7 @@ export function createSummarizationChunkHandler({
|
|
|
1509
1509
|
}: {
|
|
1510
1510
|
stepId?: string;
|
|
1511
1511
|
config?: RunnableConfig;
|
|
1512
|
-
provider?:
|
|
1512
|
+
provider?: t.ProviderName;
|
|
1513
1513
|
reasoningKey?: 'reasoning_content' | 'reasoning';
|
|
1514
1514
|
graph?: StreamLimitState & { getBreakerController?: () => AbortController };
|
|
1515
1515
|
}): OnChunk | undefined {
|
|
@@ -1622,7 +1622,7 @@ async function summarizeWithCacheHit({
|
|
|
1622
1622
|
priorSummaryText: string;
|
|
1623
1623
|
config?: RunnableConfig;
|
|
1624
1624
|
stepId?: string;
|
|
1625
|
-
provider:
|
|
1625
|
+
provider: t.ProviderName;
|
|
1626
1626
|
reasoningKey?: 'reasoning_content' | 'reasoning';
|
|
1627
1627
|
graph?: StreamLimitState & { getBreakerSignal?: () => AbortSignal };
|
|
1628
1628
|
usePromptCache?: boolean;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
2
2
|
import type { AssistantTextPhase } from '@/types/assistantPhase';
|
|
3
|
-
import type { ClientOptions } from '@/types/llm';
|
|
4
|
-
import type { Providers } from '@/common';
|
|
3
|
+
import type { ClientOptions, ProviderName } from '@/types/llm';
|
|
5
4
|
|
|
6
5
|
/** One tool call's contribution to the label payload (host-assembled). */
|
|
7
6
|
export type ActivityLabelToolEntry = {
|
|
@@ -25,7 +24,7 @@ export type ActivityLabelToolEntry = {
|
|
|
25
24
|
* `activity_label` content type's formatter exclusions.
|
|
26
25
|
*/
|
|
27
26
|
export type RunActivityLabelOptions = {
|
|
28
|
-
provider:
|
|
27
|
+
provider: ProviderName;
|
|
29
28
|
clientOptions?: ClientOptions;
|
|
30
29
|
/**
|
|
31
30
|
* Agent that executed the labeled batch. Selects that agent's Langfuse
|
|
@@ -85,7 +84,7 @@ export type ActivityPhaseEntry = {
|
|
|
85
84
|
|
|
86
85
|
/** Options for `Run.generateActivityPhaseLabel`. */
|
|
87
86
|
export type RunActivityPhaseLabelOptions = {
|
|
88
|
-
provider:
|
|
87
|
+
provider: ProviderName;
|
|
89
88
|
clientOptions?: ClientOptions;
|
|
90
89
|
/**
|
|
91
90
|
* Logical activities in run order. The SDK requires at least two so hosts
|
package/src/types/graph.ts
CHANGED
|
@@ -40,10 +40,10 @@ import type {
|
|
|
40
40
|
StreamPreemption,
|
|
41
41
|
TokenBudgetBreakdown,
|
|
42
42
|
} from '@/types/run';
|
|
43
|
-
import type { Providers, Callback, GraphNodeKeys } from '@/common';
|
|
44
43
|
import type { SubagentTaskConfig } from '@/types/subagentTasks';
|
|
45
44
|
import type { StandardGraph, MultiAgentGraph } from '@/graphs';
|
|
46
|
-
import type {
|
|
45
|
+
import type { ProviderClientOptionsConfig } from '@/types/llm';
|
|
46
|
+
import type { Callback, GraphNodeKeys } from '@/common';
|
|
47
47
|
|
|
48
48
|
/** Interface for bound model with stream and invoke methods */
|
|
49
49
|
export interface ChatModel {
|
|
@@ -824,7 +824,7 @@ export interface LangfuseConfig {
|
|
|
824
824
|
deterministicTraceId?: boolean;
|
|
825
825
|
}
|
|
826
826
|
|
|
827
|
-
|
|
827
|
+
interface AgentInputFields {
|
|
828
828
|
agentId: string;
|
|
829
829
|
/**
|
|
830
830
|
* Partition key for transient code-session ids and file refs. Agents with
|
|
@@ -839,12 +839,10 @@ export interface AgentInputs {
|
|
|
839
839
|
toolEnd?: boolean;
|
|
840
840
|
toolMap?: ToolMap;
|
|
841
841
|
tools?: GraphTools;
|
|
842
|
-
provider: Providers;
|
|
843
842
|
/** Stable/cacheable system instructions. */
|
|
844
843
|
instructions?: string;
|
|
845
844
|
streamBuffer?: number;
|
|
846
845
|
maxContextTokens?: number;
|
|
847
|
-
clientOptions?: ClientOptions;
|
|
848
846
|
/** Per-agent Langfuse tracing configuration. */
|
|
849
847
|
langfuse?: LangfuseConfig;
|
|
850
848
|
/** Dynamic system tail appended after stable instructions without provider cache markers. */
|
|
@@ -914,6 +912,8 @@ export interface AgentInputs {
|
|
|
914
912
|
graphTools?: GenericTool[];
|
|
915
913
|
}
|
|
916
914
|
|
|
915
|
+
export type AgentInputs = AgentInputFields & ProviderClientOptionsConfig;
|
|
916
|
+
|
|
917
917
|
export interface ContextPruningConfig {
|
|
918
918
|
enabled?: boolean;
|
|
919
919
|
keepLastAssistants?: number;
|
package/src/types/llm.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type {
|
|
|
8
8
|
} from '@langchain/openai';
|
|
9
9
|
import type {
|
|
10
10
|
BindToolsInput,
|
|
11
|
+
BaseChatModel,
|
|
11
12
|
BaseChatModelParams,
|
|
12
13
|
} from '@langchain/core/language_models/chat_models';
|
|
13
14
|
import type { GoogleGenerativeAIChatInput } from '@langchain/google-genai';
|
|
@@ -21,6 +22,7 @@ import type { AnthropicInput } from '@langchain/anthropic';
|
|
|
21
22
|
import type { Runnable } from '@langchain/core/runnables';
|
|
22
23
|
import type { OpenAI as OpenAIClient } from 'openai';
|
|
23
24
|
import type { ChatXAIInput } from '@langchain/xai';
|
|
25
|
+
import type { CustomProviderOptionsMap } from '../provider-registration';
|
|
24
26
|
import type { ChatOpenRouterCallOptions } from '@/llm/openrouter';
|
|
25
27
|
import type { PromptCacheTtl } from '@/messages/cache';
|
|
26
28
|
import {
|
|
@@ -138,7 +140,7 @@ export type DeepSeekClientOptions = Partial<ChatDeepSeekInput> &
|
|
|
138
140
|
StreamSmoothingOptions;
|
|
139
141
|
export type XAIClientOptions = ChatXAIInput & StreamSmoothingOptions;
|
|
140
142
|
|
|
141
|
-
export type
|
|
143
|
+
export type BuiltInClientOptions =
|
|
142
144
|
| OpenAIClientOptions
|
|
143
145
|
| AzureClientOptions
|
|
144
146
|
| AnthropicClientOptions
|
|
@@ -149,24 +151,86 @@ export type ClientOptions =
|
|
|
149
151
|
| DeepSeekClientOptions
|
|
150
152
|
| XAIClientOptions;
|
|
151
153
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
+
type CustomProviderName = Extract<keyof CustomProviderOptionsMap, string>;
|
|
155
|
+
|
|
156
|
+
type LooseRuntimeProviderName = string & {
|
|
157
|
+
readonly __runtimeProviderName?: never;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export type ProviderName =
|
|
161
|
+
| keyof ProviderOptionsMap
|
|
162
|
+
| CustomProviderName
|
|
163
|
+
| LooseRuntimeProviderName;
|
|
164
|
+
|
|
165
|
+
declare const RUNTIME_PROVIDER_NAME: unique symbol;
|
|
166
|
+
|
|
167
|
+
/** A runtime provider without declaration-merged option types. */
|
|
168
|
+
export type RuntimeProviderName = string & {
|
|
169
|
+
readonly [RUNTIME_PROVIDER_NAME]: true;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
export type ClientOptions =
|
|
173
|
+
| BuiltInClientOptions
|
|
174
|
+
| CustomProviderOptionsMap[CustomProviderName];
|
|
175
|
+
|
|
176
|
+
export type SharedLLMConfig<
|
|
177
|
+
P extends
|
|
178
|
+
| keyof ProviderOptionsMap
|
|
179
|
+
| CustomProviderName
|
|
180
|
+
| RuntimeProviderName = keyof ProviderOptionsMap,
|
|
181
|
+
> = {
|
|
182
|
+
provider: P;
|
|
183
|
+
model?: string;
|
|
154
184
|
_lc_stream_delay?: number;
|
|
155
185
|
};
|
|
156
186
|
|
|
157
|
-
|
|
158
|
-
provider:
|
|
159
|
-
|
|
187
|
+
type CustomProviderClientOptionsConfig<P extends CustomProviderName> = {
|
|
188
|
+
provider: P;
|
|
189
|
+
} & (object extends CustomProviderOptionsMap[P]
|
|
190
|
+
? { clientOptions?: CustomProviderOptionsMap[P] }
|
|
191
|
+
: { clientOptions: CustomProviderOptionsMap[P] });
|
|
192
|
+
|
|
193
|
+
export type ProviderClientOptionsConfig =
|
|
194
|
+
| {
|
|
195
|
+
provider: keyof ProviderOptionsMap;
|
|
196
|
+
clientOptions?: BuiltInClientOptions;
|
|
197
|
+
}
|
|
198
|
+
| {
|
|
199
|
+
[P in CustomProviderName]: CustomProviderClientOptionsConfig<P>;
|
|
200
|
+
}[CustomProviderName]
|
|
201
|
+
| {
|
|
202
|
+
provider: RuntimeProviderName;
|
|
203
|
+
clientOptions: ClientOptions;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
export type FallbackConfig = ProviderClientOptionsConfig & {
|
|
160
207
|
/** Context window used to corroborate ambiguous fallback overflow errors. */
|
|
161
208
|
maxContextTokens?: number;
|
|
162
|
-
}
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
type LLMConfigFor<P extends CustomProviderName> = SharedLLMConfig<P> &
|
|
212
|
+
CustomProviderOptionsMap[P] & {
|
|
213
|
+
/** Optional provider fallbacks in order of attempt */
|
|
214
|
+
fallbacks?: FallbackConfig[];
|
|
215
|
+
};
|
|
163
216
|
|
|
164
|
-
export type
|
|
165
|
-
|
|
217
|
+
export type BuiltInLLMConfig = SharedLLMConfig &
|
|
218
|
+
BuiltInClientOptions & {
|
|
166
219
|
/** Optional provider fallbacks in order of attempt */
|
|
167
220
|
fallbacks?: FallbackConfig[];
|
|
168
221
|
};
|
|
169
222
|
|
|
223
|
+
export type LLMConfig =
|
|
224
|
+
| BuiltInLLMConfig
|
|
225
|
+
| {
|
|
226
|
+
[P in CustomProviderName]: LLMConfigFor<P>;
|
|
227
|
+
}[CustomProviderName]
|
|
228
|
+
| (SharedLLMConfig<RuntimeProviderName> &
|
|
229
|
+
ClientOptions & {
|
|
230
|
+
/** Optional provider fallbacks in order of attempt */
|
|
231
|
+
fallbacks?: FallbackConfig[];
|
|
232
|
+
});
|
|
233
|
+
|
|
170
234
|
export type ProviderOptionsMap = {
|
|
171
235
|
[Providers.AZURE]: AzureClientOptions;
|
|
172
236
|
[Providers.OPENAI]: OpenAIClientOptions;
|
|
@@ -182,7 +246,7 @@ export type ProviderOptionsMap = {
|
|
|
182
246
|
[Providers.MOONSHOT]: OpenAIClientOptions;
|
|
183
247
|
};
|
|
184
248
|
|
|
185
|
-
export
|
|
249
|
+
export interface ChatModelMap {
|
|
186
250
|
[Providers.XAI]: ChatXAI;
|
|
187
251
|
[Providers.OPENAI]: ChatOpenAI;
|
|
188
252
|
[Providers.AZURE]: AzureChatOpenAI;
|
|
@@ -195,14 +259,32 @@ export type ChatModelMap = {
|
|
|
195
259
|
[Providers.BEDROCK]: CustomChatBedrockConverse;
|
|
196
260
|
[Providers.GOOGLE]: CustomChatGoogleGenerativeAI;
|
|
197
261
|
[Providers.MOONSHOT]: ChatMoonshot;
|
|
198
|
-
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export type ProviderOptionsFor<P extends ProviderName> =
|
|
265
|
+
P extends keyof ProviderOptionsMap
|
|
266
|
+
? ProviderOptionsMap[P]
|
|
267
|
+
: P extends CustomProviderName
|
|
268
|
+
? CustomProviderOptionsMap[P]
|
|
269
|
+
: BuiltInClientOptions;
|
|
270
|
+
|
|
271
|
+
export type ProviderModelFor<P extends ProviderName> =
|
|
272
|
+
P extends keyof ChatModelMap
|
|
273
|
+
? ChatModelMap[P] & BaseChatModel
|
|
274
|
+
: BaseChatModel;
|
|
275
|
+
|
|
276
|
+
export type ProviderModelConstructor<P extends ProviderName> = new (
|
|
277
|
+
config: ProviderOptionsFor<P>
|
|
278
|
+
) => ProviderModelFor<P>;
|
|
199
279
|
|
|
200
280
|
export type ChatModelConstructorMap = {
|
|
201
281
|
[P in Providers]: new (config: ProviderOptionsMap[P]) => ChatModelMap[P];
|
|
202
282
|
};
|
|
203
283
|
|
|
204
|
-
export type ChatModelInstance =
|
|
284
|
+
export type ChatModelInstance = BaseChatModel;
|
|
205
285
|
|
|
206
|
-
export type ModelWithTools =
|
|
286
|
+
export type ModelWithTools = BaseChatModel & {
|
|
207
287
|
bindTools(tools: CommonToolType[]): Runnable;
|
|
208
288
|
};
|
|
289
|
+
|
|
290
|
+
export type { CustomProviderOptionsMap } from '../provider-registration';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
2
2
|
import type { UsageMetadata } from '@langchain/core/messages';
|
|
3
|
-
import type { ClientOptions } from '@/types/llm';
|
|
4
|
-
import type { Providers } from '@/common';
|
|
3
|
+
import type { ClientOptions, ProviderName } from '@/types/llm';
|
|
5
4
|
|
|
6
5
|
/** Lifecycle state of the visible reasoning snapshot being labeled. */
|
|
7
6
|
export type ReasoningLabelStatus = 'streaming' | 'complete';
|
|
@@ -15,7 +14,7 @@ export type ReasoningLabelResult = {
|
|
|
15
14
|
|
|
16
15
|
/** Options for `Run.generateReasoningLabel`. */
|
|
17
16
|
export type RunReasoningLabelOptions = {
|
|
18
|
-
provider:
|
|
17
|
+
provider: ProviderName;
|
|
19
18
|
clientOptions?: ClientOptions;
|
|
20
19
|
/**
|
|
21
20
|
* Complete user-visible reasoning accumulated for this step so far. Hidden
|
package/src/types/run.ts
CHANGED
|
@@ -22,7 +22,7 @@ import type * as l from '@/types/llm';
|
|
|
22
22
|
export type ZodObjectAny = z.ZodObject<any, any, any, any>;
|
|
23
23
|
export type BaseGraphConfig = {
|
|
24
24
|
llmConfig: l.LLMConfig;
|
|
25
|
-
provider?:
|
|
25
|
+
provider?: l.ProviderName;
|
|
26
26
|
clientOptions?: l.ClientOptions;
|
|
27
27
|
/** Optional compile options for workflow.compile() */
|
|
28
28
|
compileOptions?: g.CompileOptions;
|
|
@@ -47,7 +47,7 @@ export type SupervisedGraphConfig = BaseGraphConfig & {
|
|
|
47
47
|
routingPolicies?: Array<{
|
|
48
48
|
stage: string;
|
|
49
49
|
agents?: string[];
|
|
50
|
-
model?:
|
|
50
|
+
model?: l.ProviderName;
|
|
51
51
|
parallel?: boolean;
|
|
52
52
|
/** Optional simple condition on content/tools */
|
|
53
53
|
when?:
|
|
@@ -70,7 +70,7 @@ export type SupervisedGraphConfig = BaseGraphConfig & {
|
|
|
70
70
|
|
|
71
71
|
export type RunTitleOptions = {
|
|
72
72
|
inputText: string;
|
|
73
|
-
provider:
|
|
73
|
+
provider: l.ProviderName;
|
|
74
74
|
contentParts: (s.MessageContentComplex | undefined)[];
|
|
75
75
|
titlePrompt?: string;
|
|
76
76
|
skipLanguage?: boolean;
|
package/src/types/summarize.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SummaryContentBlock } from '@/types/stream';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ProviderName } from '@/types/llm';
|
|
3
3
|
|
|
4
4
|
export type SummarizationTrigger = {
|
|
5
5
|
type:
|
|
@@ -35,7 +35,7 @@ export type RetainRecentConfig = {
|
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
export type SummarizationConfig = {
|
|
38
|
-
provider?:
|
|
38
|
+
provider?: ProviderName;
|
|
39
39
|
model?: string;
|
|
40
40
|
parameters?: Record<string, unknown>;
|
|
41
41
|
prompt?: string;
|
package/src/utils/errors.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* into a forced summarization pass instead of surfacing the error.
|
|
13
13
|
*/
|
|
14
14
|
import { ContextOverflowError } from '@langchain/core/errors';
|
|
15
|
-
import type {
|
|
15
|
+
import type { ProviderName } from '@/types';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Why the request was rejected. Both kinds are fixed by shrinking the
|
|
@@ -49,7 +49,7 @@ export interface ContextOverflowInfo {
|
|
|
49
49
|
promptTokens?: number;
|
|
50
50
|
/** Which layer produced the verdict. Surfaced in logs and asserted in tests. */
|
|
51
51
|
source: 'langchain' | 'pattern';
|
|
52
|
-
provider?:
|
|
52
|
+
provider?: ProviderName;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
interface OverflowPattern {
|
|
@@ -80,7 +80,7 @@ interface OverflowPattern {
|
|
|
80
80
|
const CONTEXT_PRESSURE_RATIO = 0.8;
|
|
81
81
|
|
|
82
82
|
export interface ContextOverflowContext {
|
|
83
|
-
provider?:
|
|
83
|
+
provider?: ProviderName;
|
|
84
84
|
/** Our own estimate of the prompt size for the call that failed. */
|
|
85
85
|
estimatedPromptTokens?: number;
|
|
86
86
|
/** The budget we believed applied when we built that prompt. */
|
package/src/utils/llm.ts
CHANGED
|
@@ -1,37 +1,44 @@
|
|
|
1
1
|
// src/utils/llm.ts
|
|
2
|
+
import type { ProviderName } from '@/types';
|
|
3
|
+
import { getProviderFamily } from '@/llm/providerRegistry';
|
|
2
4
|
import { Providers } from '@/common';
|
|
3
5
|
|
|
4
|
-
export function isOpenAILike(provider?:
|
|
6
|
+
export function isOpenAILike(provider?: ProviderName): boolean {
|
|
5
7
|
if (provider == null) {
|
|
6
8
|
return false;
|
|
7
9
|
}
|
|
8
10
|
return (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
getProviderFamily(provider) === 'openai' ||
|
|
12
|
+
(
|
|
13
|
+
[
|
|
14
|
+
Providers.OPENAI,
|
|
15
|
+
Providers.AZURE,
|
|
16
|
+
Providers.OPENROUTER,
|
|
17
|
+
Providers.XAI,
|
|
18
|
+
Providers.DEEPSEEK,
|
|
19
|
+
] as string[]
|
|
20
|
+
).includes(provider)
|
|
21
|
+
);
|
|
17
22
|
}
|
|
18
23
|
|
|
19
|
-
export function isGoogleLike(provider?:
|
|
24
|
+
export function isGoogleLike(provider?: ProviderName): boolean {
|
|
20
25
|
if (provider == null) {
|
|
21
26
|
return false;
|
|
22
27
|
}
|
|
23
|
-
return (
|
|
24
|
-
provider
|
|
28
|
+
return (
|
|
29
|
+
getProviderFamily(provider) === 'google' ||
|
|
30
|
+
([Providers.GOOGLE, Providers.VERTEXAI] as string[]).includes(provider)
|
|
25
31
|
);
|
|
26
32
|
}
|
|
27
33
|
|
|
28
34
|
/** Returns true for native Anthropic or Bedrock running a Claude model. */
|
|
29
35
|
export function isAnthropicLike(
|
|
30
|
-
provider?:
|
|
36
|
+
provider?: ProviderName,
|
|
31
37
|
clientOptions?: { model?: string }
|
|
32
38
|
): boolean {
|
|
33
|
-
|
|
34
|
-
if (provider === Providers.
|
|
39
|
+
const family = provider == null ? undefined : getProviderFamily(provider);
|
|
40
|
+
if (provider === Providers.ANTHROPIC || family === 'anthropic') return true;
|
|
41
|
+
if (provider === Providers.BEDROCK || family === 'bedrock') {
|
|
35
42
|
return (
|
|
36
43
|
clientOptions?.model == null ||
|
|
37
44
|
/claude/i.test(String(clientOptions.model))
|
package/src/utils/llmConfig.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type * as or from '@/llm/openrouter';
|
|
|
3
3
|
import type * as t from '@/types';
|
|
4
4
|
import { Providers } from '@/common';
|
|
5
5
|
|
|
6
|
-
export const llmConfigs: Record<string, t.
|
|
6
|
+
export const llmConfigs: Record<string, t.BuiltInLLMConfig | undefined> = {
|
|
7
7
|
[Providers.OPENAI]: {
|
|
8
8
|
provider: Providers.OPENAI,
|
|
9
9
|
model: 'gpt-4.1',
|
|
@@ -68,7 +68,7 @@ export const llmConfigs: Record<string, t.LLMConfig | undefined> = {
|
|
|
68
68
|
modelKwargs: {
|
|
69
69
|
max_tokens: 10000,
|
|
70
70
|
},
|
|
71
|
-
} as or.ChatOpenRouterCallOptions & t.
|
|
71
|
+
} as or.ChatOpenRouterCallOptions & t.BuiltInLLMConfig,
|
|
72
72
|
[Providers.AZURE]: {
|
|
73
73
|
provider: Providers.AZURE,
|
|
74
74
|
temperature: 0.7,
|
|
@@ -159,7 +159,7 @@ export const llmConfigs: Record<string, t.LLMConfig | undefined> = {
|
|
|
159
159
|
// location: 'global',
|
|
160
160
|
// thinkingBudget: -1,
|
|
161
161
|
// includeThoughts: true,
|
|
162
|
-
} as t.VertexAIClientOptions & t.
|
|
162
|
+
} as t.VertexAIClientOptions & t.BuiltInLLMConfig,
|
|
163
163
|
[Providers.GOOGLE]: {
|
|
164
164
|
provider: Providers.GOOGLE,
|
|
165
165
|
model: 'gemini-2.5-flash',
|
|
@@ -194,7 +194,7 @@ export const llmConfigs: Record<string, t.LLMConfig | undefined> = {
|
|
|
194
194
|
},
|
|
195
195
|
};
|
|
196
196
|
|
|
197
|
-
export function getLLMConfig(provider: string): t.
|
|
197
|
+
export function getLLMConfig(provider: string): t.BuiltInLLMConfig {
|
|
198
198
|
const config = llmConfigs[provider];
|
|
199
199
|
if (config === undefined) {
|
|
200
200
|
throw new Error(`Unsupported provider: ${provider}`);
|