@librechat/agents 2.3.6 → 2.3.8
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/graphs/Graph.cjs +5 -4
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/messages/core.cjs +2 -2
- package/dist/cjs/messages/core.cjs.map +1 -1
- package/dist/cjs/messages/prune.cjs +3 -4
- package/dist/cjs/messages/prune.cjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +5 -4
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/messages/core.mjs +2 -2
- package/dist/esm/messages/core.mjs.map +1 -1
- package/dist/esm/messages/prune.mjs +4 -5
- package/dist/esm/messages/prune.mjs.map +1 -1
- package/dist/types/messages/prune.d.ts +4 -3
- package/dist/types/types/llm.d.ts +8 -0
- package/package.json +1 -1
- package/src/graphs/Graph.ts +13 -4
- package/src/messages/core.ts +3 -3
- package/src/messages/prune.ts +10 -6
- package/src/types/llm.ts +9 -2
package/src/messages/prune.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { AIMessage, BaseMessage, UsageMetadata } from '@langchain/core/messages';
|
|
2
|
-
import type { ThinkingContentText, MessageContentComplex } from '@/types/stream';
|
|
2
|
+
import type { ThinkingContentText, MessageContentComplex, ReasoningContentText } from '@/types/stream';
|
|
3
3
|
import type { TokenCounter } from '@/types/run';
|
|
4
|
-
import { ContentTypes } from '@/common';
|
|
4
|
+
import { ContentTypes, Providers } from '@/common';
|
|
5
|
+
|
|
5
6
|
export type PruneMessagesFactoryParams = {
|
|
7
|
+
provider?: Providers;
|
|
6
8
|
maxTokens: number;
|
|
7
9
|
startIndex: number;
|
|
8
10
|
tokenCounter: TokenCounter;
|
|
@@ -20,7 +22,7 @@ function isIndexInContext(arrayA: unknown[], arrayB: unknown[], targetIndex: num
|
|
|
20
22
|
return targetIndex >= startingIndexInA;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
function addThinkingBlock(message: AIMessage, thinkingBlock: ThinkingContentText): MessageContentComplex[] {
|
|
25
|
+
function addThinkingBlock(message: AIMessage, thinkingBlock: ThinkingContentText | ReasoningContentText): MessageContentComplex[] {
|
|
24
26
|
const content: MessageContentComplex[] = Array.isArray(message.content)
|
|
25
27
|
? message.content as MessageContentComplex[]
|
|
26
28
|
: [{
|
|
@@ -65,8 +67,8 @@ export function getMessagesWithinTokenLimit({
|
|
|
65
67
|
indexTokenCountMap,
|
|
66
68
|
startType: _startType,
|
|
67
69
|
thinkingEnabled,
|
|
68
|
-
/** We may need to use this when recalculating */
|
|
69
70
|
tokenCounter,
|
|
71
|
+
reasoningType = ContentTypes.THINKING,
|
|
70
72
|
}: {
|
|
71
73
|
messages: BaseMessage[];
|
|
72
74
|
maxContextTokens: number;
|
|
@@ -74,6 +76,7 @@ export function getMessagesWithinTokenLimit({
|
|
|
74
76
|
tokenCounter: TokenCounter;
|
|
75
77
|
startType?: string;
|
|
76
78
|
thinkingEnabled?: boolean;
|
|
79
|
+
reasoningType?: ContentTypes.THINKING | ContentTypes.REASONING_CONTENT;
|
|
77
80
|
}): {
|
|
78
81
|
context: BaseMessage[];
|
|
79
82
|
remainingContextTokens: number;
|
|
@@ -98,7 +101,7 @@ export function getMessagesWithinTokenLimit({
|
|
|
98
101
|
|
|
99
102
|
let thinkingStartIndex = -1;
|
|
100
103
|
let thinkingEndIndex = -1;
|
|
101
|
-
let thinkingBlock: ThinkingContentText | undefined;
|
|
104
|
+
let thinkingBlock: ThinkingContentText | ReasoningContentText | undefined;
|
|
102
105
|
const endIndex = instructions != null ? 1 : 0;
|
|
103
106
|
const prunedMemory: BaseMessage[] = [];
|
|
104
107
|
|
|
@@ -116,7 +119,7 @@ export function getMessagesWithinTokenLimit({
|
|
|
116
119
|
thinkingEndIndex = currentIndex;
|
|
117
120
|
}
|
|
118
121
|
if (thinkingEndIndex > -1 && !thinkingBlock && thinkingStartIndex < 0 && messageType === 'ai' && Array.isArray(poppedMessage.content)) {
|
|
119
|
-
thinkingBlock = (poppedMessage.content.find((content) => content.type ===
|
|
122
|
+
thinkingBlock = (poppedMessage.content.find((content) => content.type === reasoningType)) as ThinkingContentText | undefined;
|
|
120
123
|
thinkingStartIndex = thinkingBlock != null ? currentIndex : -1;
|
|
121
124
|
}
|
|
122
125
|
/** False start, the latest message was not part of a multi-assistant/tool sequence of messages */
|
|
@@ -346,6 +349,7 @@ export function createPruneMessages(factoryParams: PruneMessagesFactoryParams) {
|
|
|
346
349
|
startType: params.startType,
|
|
347
350
|
thinkingEnabled: factoryParams.thinkingEnabled,
|
|
348
351
|
tokenCounter: factoryParams.tokenCounter,
|
|
352
|
+
reasoningType: factoryParams.provider === Providers.BEDROCK ? ContentTypes.REASONING_CONTENT : ContentTypes.THINKING,
|
|
349
353
|
});
|
|
350
354
|
lastCutOffIndex = Math.max(params.messages.length - context.length, 0);
|
|
351
355
|
|
package/src/types/llm.ts
CHANGED
|
@@ -35,16 +35,23 @@ export type AzureClientOptions = (Partial<OpenAIChatInput> & Partial<AzureOpenAI
|
|
|
35
35
|
} & BaseChatModelParams & {
|
|
36
36
|
configuration?: OAIClientOptions;
|
|
37
37
|
});
|
|
38
|
-
|
|
38
|
+
export type ThinkingConfig = AnthropicInput['thinking'];
|
|
39
39
|
export type ChatOpenAIToolType = BindToolsInput | OpenAIClient.ChatCompletionTool;
|
|
40
40
|
export type CommonToolType = StructuredTool | ChatOpenAIToolType;
|
|
41
|
-
|
|
41
|
+
export type AnthropicReasoning = {
|
|
42
|
+
thinking?: ThinkingConfig | boolean;
|
|
43
|
+
thinkingBudget?: number;
|
|
44
|
+
};
|
|
42
45
|
export type OpenAIClientOptions = ChatOpenAIFields;
|
|
43
46
|
export type OllamaClientOptions = ChatOllamaInput;
|
|
44
47
|
export type AnthropicClientOptions = AnthropicInput;
|
|
45
48
|
export type MistralAIClientOptions = ChatMistralAIInput;
|
|
46
49
|
export type VertexAIClientOptions = ChatVertexAIInput;
|
|
47
50
|
export type BedrockClientOptions = BedrockChatFields;
|
|
51
|
+
export type BedrockAnthropicInput = ChatBedrockConverseInput & {
|
|
52
|
+
additionalModelRequestFields?: ChatBedrockConverseInput['additionalModelRequestFields'] &
|
|
53
|
+
AnthropicReasoning;
|
|
54
|
+
};
|
|
48
55
|
export type BedrockConverseClientOptions = ChatBedrockConverseInput;
|
|
49
56
|
export type GoogleClientOptions = GoogleGenerativeAIChatInput;
|
|
50
57
|
export type DeepSeekClientOptions = ChatDeepSeekCallOptions;
|