@librechat/agents 3.6.14 → 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/contextPressureMeter.cjs +8 -6
- package/dist/cjs/llm/contextPressureMeter.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/cjs/utils/toolContent.cjs +2 -2
- package/dist/cjs/utils/toolContent.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/contextPressureMeter.mjs +8 -6
- package/dist/esm/llm/contextPressureMeter.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/esm/utils/toolContent.mjs +3 -3
- package/dist/esm/utils/toolContent.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/contextPressureMeter.ts +23 -13
- 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
- package/src/utils/toolContent.ts +9 -3
package/src/messages/format.ts
CHANGED
|
@@ -27,6 +27,7 @@ import type {
|
|
|
27
27
|
ToolCallPart,
|
|
28
28
|
TPayload,
|
|
29
29
|
TMessage,
|
|
30
|
+
ProviderName,
|
|
30
31
|
} from '@/types';
|
|
31
32
|
import type {
|
|
32
33
|
ProviderMessageAttribution,
|
|
@@ -366,7 +367,7 @@ export const formatFromLangChain = (
|
|
|
366
367
|
interface FormatAssistantMessageOptions {
|
|
367
368
|
preserveUnpairedServerToolUses?: boolean;
|
|
368
369
|
preserveReasoningContent?: boolean;
|
|
369
|
-
provider?:
|
|
370
|
+
provider?: ProviderName;
|
|
370
371
|
sourceMessageId?: string;
|
|
371
372
|
sourceContentPartOffset?: number;
|
|
372
373
|
sourceContentPartIndices?: readonly SourceContentPartIndices[];
|
|
@@ -376,7 +377,7 @@ interface FormatAssistantMessageOptions {
|
|
|
376
377
|
type SourceContentPartIndices = number | readonly number[];
|
|
377
378
|
|
|
378
379
|
interface FormatAgentMessagesOptions {
|
|
379
|
-
provider?:
|
|
380
|
+
provider?: ProviderName;
|
|
380
381
|
/** Reconstruct hidden `reasoning_content` from `THINK` parts onto prior
|
|
381
382
|
* tool-call messages. Explicit opt-in for OpenAI-compatible endpoints that
|
|
382
383
|
* replay reasoning across turns; defaults to on for DeepSeek thinking-mode. */
|
|
@@ -478,10 +479,7 @@ function collectTrustedToolResultSourceContentPartIndices(
|
|
|
478
479
|
let trusted: Set<number> | undefined;
|
|
479
480
|
let previousPart: MessageContentComplex | null | undefined;
|
|
480
481
|
for (let index = 0; index < content.length; index++) {
|
|
481
|
-
const part = content[index] as
|
|
482
|
-
| MessageContentComplex
|
|
483
|
-
| null
|
|
484
|
-
| undefined;
|
|
482
|
+
const part = content[index] as MessageContentComplex | null | undefined;
|
|
485
483
|
if (part == null) {
|
|
486
484
|
previousPart = part;
|
|
487
485
|
continue;
|
|
@@ -509,13 +507,18 @@ function sourceContentPartIndicesAreTrustedToolResult(
|
|
|
509
507
|
trustedToolSourceContentPartIndices: ReadonlySet<number> | undefined
|
|
510
508
|
): boolean {
|
|
511
509
|
if (typeof sourceContentPartIndices === 'number') {
|
|
512
|
-
return
|
|
510
|
+
return (
|
|
511
|
+
trustedToolSourceContentPartIndices?.has(sourceContentPartIndices) ===
|
|
512
|
+
true
|
|
513
|
+
);
|
|
513
514
|
}
|
|
514
515
|
if (sourceContentPartIndices.length === 0) {
|
|
515
516
|
return false;
|
|
516
517
|
}
|
|
517
518
|
for (const sourceContentPartIndex of sourceContentPartIndices) {
|
|
518
|
-
if (
|
|
519
|
+
if (
|
|
520
|
+
trustedToolSourceContentPartIndices?.has(sourceContentPartIndex) !== true
|
|
521
|
+
) {
|
|
519
522
|
return false;
|
|
520
523
|
}
|
|
521
524
|
}
|
|
@@ -1377,10 +1380,7 @@ function stampSourceMessageIdentity(
|
|
|
1377
1380
|
},
|
|
1378
1381
|
];
|
|
1379
1382
|
}
|
|
1380
|
-
setProviderMessageProvenance(
|
|
1381
|
-
message,
|
|
1382
|
-
partsToStamp
|
|
1383
|
-
);
|
|
1383
|
+
setProviderMessageProvenance(message, partsToStamp);
|
|
1384
1384
|
if (sourceMessageId == null || derivedIndex !== 0) {
|
|
1385
1385
|
return;
|
|
1386
1386
|
}
|
|
@@ -2759,9 +2759,7 @@ function getSyntheticProviderContextProvenanceParts(
|
|
|
2759
2759
|
): ProviderMessageProvenancePart[] | null {
|
|
2760
2760
|
/** Fold labels are generated context, while retained source bytes keep their
|
|
2761
2761
|
* original attribution so downstream policy can still route them exactly. */
|
|
2762
|
-
const parts: ProviderMessageProvenancePart[] = [
|
|
2763
|
-
{ attribution: 'synthetic' },
|
|
2764
|
-
];
|
|
2762
|
+
const parts: ProviderMessageProvenancePart[] = [{ attribution: 'synthetic' }];
|
|
2765
2763
|
for (const source of sourceMessages) {
|
|
2766
2764
|
const {
|
|
2767
2765
|
message: sourceMessage,
|
|
@@ -3311,7 +3309,7 @@ function appendToolCalls(
|
|
|
3311
3309
|
*/
|
|
3312
3310
|
export function ensureThinkingBlockInMessages(
|
|
3313
3311
|
messages: BaseMessage[],
|
|
3314
|
-
_provider:
|
|
3312
|
+
_provider: ProviderName,
|
|
3315
3313
|
config?: RunnableConfig,
|
|
3316
3314
|
runStartIndex?: number
|
|
3317
3315
|
): BaseMessage[] {
|
package/src/messages/prune.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type {
|
|
|
13
13
|
} from '@/types/stream';
|
|
14
14
|
import type { ContextPruningConfig } from '@/types/graph';
|
|
15
15
|
import type { TokenCounter } from '@/types/run';
|
|
16
|
+
import type { ProviderName } from '@/types';
|
|
16
17
|
import {
|
|
17
18
|
cloneToolMessageWithContent,
|
|
18
19
|
compactToolContent,
|
|
@@ -29,6 +30,7 @@ import {
|
|
|
29
30
|
import { resolveContextPruningSettings } from './contextPruningSettings';
|
|
30
31
|
import { hasUnsafeStructuredSerialization } from '@/utils/tokens';
|
|
31
32
|
import { ContentTypes, Providers, Constants } from '@/common';
|
|
33
|
+
import { getProviderFamily } from '@/llm/providerRegistry';
|
|
32
34
|
import { applyContextPruning } from './contextPruning';
|
|
33
35
|
import { toLangChainContent } from './langchain';
|
|
34
36
|
|
|
@@ -130,7 +132,7 @@ export function clampCalibrationRatio(ratio: number): number {
|
|
|
130
132
|
}
|
|
131
133
|
|
|
132
134
|
export type PruneMessagesFactoryParams = {
|
|
133
|
-
provider?:
|
|
135
|
+
provider?: ProviderName;
|
|
134
136
|
maxTokens: number;
|
|
135
137
|
/** Per-tool-result character cap applied while reconciling cached counts. */
|
|
136
138
|
maxToolResultChars?: number;
|
|
@@ -2065,6 +2067,15 @@ type ThinkingBlocks = {
|
|
|
2065
2067
|
};
|
|
2066
2068
|
|
|
2067
2069
|
export function createPruneMessages(factoryParams: PruneMessagesFactoryParams) {
|
|
2070
|
+
const providerFamily =
|
|
2071
|
+
factoryParams.provider == null
|
|
2072
|
+
? undefined
|
|
2073
|
+
: getProviderFamily(factoryParams.provider);
|
|
2074
|
+
const usesBedrockThinking =
|
|
2075
|
+
factoryParams.provider === Providers.BEDROCK ||
|
|
2076
|
+
providerFamily === 'bedrock';
|
|
2077
|
+
const usesOpenAIThinking =
|
|
2078
|
+
factoryParams.provider === Providers.OPENAI || providerFamily === 'openai';
|
|
2068
2079
|
const indexTokenCountMap = { ...factoryParams.indexTokenCountMap };
|
|
2069
2080
|
let lastTurnStartIndex = factoryParams.startIndex;
|
|
2070
2081
|
let lastCutOffIndex = 0;
|
|
@@ -2152,10 +2163,7 @@ export function createPruneMessages(factoryParams: PruneMessagesFactoryParams) {
|
|
|
2152
2163
|
};
|
|
2153
2164
|
}
|
|
2154
2165
|
|
|
2155
|
-
if (
|
|
2156
|
-
factoryParams.provider === Providers.OPENAI &&
|
|
2157
|
-
factoryParams.thinkingEnabled === true
|
|
2158
|
-
) {
|
|
2166
|
+
if (usesOpenAIThinking && factoryParams.thinkingEnabled === true) {
|
|
2159
2167
|
for (let i = lastTurnStartIndex; i < params.messages.length; i++) {
|
|
2160
2168
|
const m = params.messages[i];
|
|
2161
2169
|
if (
|
|
@@ -2729,10 +2737,9 @@ export function createPruneMessages(factoryParams: PruneMessagesFactoryParams) {
|
|
|
2729
2737
|
thinkingEnabled: factoryParams.thinkingEnabled,
|
|
2730
2738
|
tokenCounter: factoryParams.tokenCounter,
|
|
2731
2739
|
instructionTokens: rawSpaceInstructionTokens,
|
|
2732
|
-
reasoningType:
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
: ContentTypes.THINKING,
|
|
2740
|
+
reasoningType: usesBedrockThinking
|
|
2741
|
+
? ContentTypes.REASONING_CONTENT
|
|
2742
|
+
: ContentTypes.THINKING,
|
|
2736
2743
|
thinkingStartIndex:
|
|
2737
2744
|
factoryParams.thinkingEnabled === true
|
|
2738
2745
|
? runThinkingStartIndex
|
|
@@ -2826,10 +2833,9 @@ export function createPruneMessages(factoryParams: PruneMessagesFactoryParams) {
|
|
|
2826
2833
|
thinkingEnabled: factoryParams.thinkingEnabled,
|
|
2827
2834
|
tokenCounter: factoryParams.tokenCounter,
|
|
2828
2835
|
instructionTokens: currentInstructionTokens,
|
|
2829
|
-
reasoningType:
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
: ContentTypes.THINKING,
|
|
2836
|
+
reasoningType: usesBedrockThinking
|
|
2837
|
+
? ContentTypes.REASONING_CONTENT
|
|
2838
|
+
: ContentTypes.THINKING,
|
|
2833
2839
|
thinkingStartIndex:
|
|
2834
2840
|
factoryParams.thinkingEnabled === true
|
|
2835
2841
|
? runThinkingStartIndex
|
|
@@ -2963,10 +2969,9 @@ export function createPruneMessages(factoryParams: PruneMessagesFactoryParams) {
|
|
|
2963
2969
|
thinkingEnabled: factoryParams.thinkingEnabled,
|
|
2964
2970
|
tokenCounter: factoryParams.tokenCounter,
|
|
2965
2971
|
instructionTokens: currentInstructionTokens,
|
|
2966
|
-
reasoningType:
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
: ContentTypes.THINKING,
|
|
2972
|
+
reasoningType: usesBedrockThinking
|
|
2973
|
+
? ContentTypes.REASONING_CONTENT
|
|
2974
|
+
: ContentTypes.THINKING,
|
|
2970
2975
|
thinkingStartIndex:
|
|
2971
2976
|
factoryParams.thinkingEnabled === true
|
|
2972
2977
|
? runThinkingStartIndex
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
2
|
+
|
|
3
|
+
declare const CUSTOM_PROVIDER_OPTIONS_TYPE: unique symbol;
|
|
4
|
+
|
|
5
|
+
/** Declaration-merge this map to type host-registered provider options. */
|
|
6
|
+
export interface CustomProviderOptionsMap {
|
|
7
|
+
readonly [CUSTOM_PROVIDER_OPTIONS_TYPE]?: never;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type ProviderFamily =
|
|
11
|
+
| 'openai'
|
|
12
|
+
| 'anthropic'
|
|
13
|
+
| 'bedrock'
|
|
14
|
+
| 'google'
|
|
15
|
+
| 'mistral'
|
|
16
|
+
| 'generic';
|
|
17
|
+
|
|
18
|
+
export interface ProviderRegistrationOptions<
|
|
19
|
+
TOptions extends object,
|
|
20
|
+
TModel extends BaseChatModel,
|
|
21
|
+
> {
|
|
22
|
+
provider: string;
|
|
23
|
+
model: new (config: TOptions) => TModel;
|
|
24
|
+
family?: ProviderFamily;
|
|
25
|
+
manualToolStream?: boolean;
|
|
26
|
+
strictAlternation?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { registerProvider } from './llm/providers';
|
package/src/run.ts
CHANGED
package/src/stream.ts
CHANGED
|
@@ -820,12 +820,11 @@ function startEagerToolExecutions(args: {
|
|
|
820
820
|
toolCalls: entries.map((entry) => entry.request),
|
|
821
821
|
userId: graph.config?.configurable?.user_id as string | undefined,
|
|
822
822
|
agentId: agentContext?.agentId,
|
|
823
|
-
callerCapabilityProjection:
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
)?.getCallerCapabilityProjectionSnapshot?.(),
|
|
823
|
+
callerCapabilityProjection: (
|
|
824
|
+
agentContext as
|
|
825
|
+
| Partial<Pick<AgentContext, 'getCallerCapabilityProjectionSnapshot'>>
|
|
826
|
+
| undefined
|
|
827
|
+
)?.getCallerCapabilityProjectionSnapshot?.(),
|
|
829
828
|
configurable: graph.config?.configurable as
|
|
830
829
|
| Record<string, unknown>
|
|
831
830
|
| undefined,
|
|
@@ -1327,7 +1326,7 @@ export function getChunkContent({
|
|
|
1327
1326
|
reasoningKey,
|
|
1328
1327
|
}: {
|
|
1329
1328
|
chunk?: Partial<AIMessageChunk>;
|
|
1330
|
-
provider?:
|
|
1329
|
+
provider?: t.ProviderName;
|
|
1331
1330
|
reasoningKey: 'reasoning_content' | 'reasoning';
|
|
1332
1331
|
}): string | t.MessageContentComplex[] | undefined {
|
|
1333
1332
|
if (
|
|
@@ -1851,7 +1850,7 @@ export class ChatModelStreamHandler implements t.EventHandler {
|
|
|
1851
1850
|
|
|
1852
1851
|
if (Array.isArray(content) && content.every(isTextContentPart)) {
|
|
1853
1852
|
const contentGroups = splitAssistantTextContentByPhase(content);
|
|
1854
|
-
const currentStepId = graph.stepKeyIds
|
|
1853
|
+
const currentStepId = graph.stepKeyIds.get(stepKey)?.at(-1);
|
|
1855
1854
|
const currentStep =
|
|
1856
1855
|
currentStepId == null ? undefined : graph.getRunStep(currentStepId);
|
|
1857
1856
|
const currentPhase =
|
|
@@ -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. */
|