@librechat/agents 3.1.74 → 3.1.75-dev.0
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 +66 -0
- package/dist/cjs/agents/AgentContext.cjs +84 -37
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +13 -3
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/index.cjs +145 -52
- 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 +25 -15
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +84 -70
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/index.cjs +1 -1
- package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs +213 -3
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/utils/message_outputs.cjs +2 -1
- package/dist/cjs/llm/bedrock/utils/message_outputs.cjs.map +1 -1
- package/dist/cjs/llm/google/utils/common.cjs +5 -4
- package/dist/cjs/llm/google/utils/common.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs +468 -647
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/utils/index.cjs +1 -448
- package/dist/cjs/llm/openai/utils/index.cjs.map +1 -1
- package/dist/cjs/llm/openrouter/index.cjs +57 -175
- package/dist/cjs/llm/openrouter/index.cjs.map +1 -1
- package/dist/cjs/llm/vertexai/index.cjs +5 -3
- package/dist/cjs/llm/vertexai/index.cjs.map +1 -1
- package/dist/cjs/messages/cache.cjs +39 -4
- package/dist/cjs/messages/cache.cjs.map +1 -1
- package/dist/cjs/messages/core.cjs +7 -6
- package/dist/cjs/messages/core.cjs.map +1 -1
- package/dist/cjs/messages/format.cjs +7 -6
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/cjs/messages/langchain.cjs +26 -0
- package/dist/cjs/messages/langchain.cjs.map +1 -0
- package/dist/cjs/messages/prune.cjs +7 -6
- package/dist/cjs/messages/prune.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +5 -1
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +85 -38
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +13 -3
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/llm/anthropic/index.mjs +146 -54
- 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 +25 -15
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs +84 -71
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -1
- package/dist/esm/llm/bedrock/index.mjs +1 -1
- package/dist/esm/llm/bedrock/index.mjs.map +1 -1
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs +214 -4
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/bedrock/utils/message_outputs.mjs +2 -1
- package/dist/esm/llm/bedrock/utils/message_outputs.mjs.map +1 -1
- package/dist/esm/llm/google/utils/common.mjs +5 -4
- package/dist/esm/llm/google/utils/common.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +469 -648
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/llm/openai/utils/index.mjs +4 -449
- package/dist/esm/llm/openai/utils/index.mjs.map +1 -1
- package/dist/esm/llm/openrouter/index.mjs +57 -175
- package/dist/esm/llm/openrouter/index.mjs.map +1 -1
- package/dist/esm/llm/vertexai/index.mjs +5 -3
- package/dist/esm/llm/vertexai/index.mjs.map +1 -1
- package/dist/esm/messages/cache.mjs +39 -4
- package/dist/esm/messages/cache.mjs.map +1 -1
- package/dist/esm/messages/core.mjs +7 -6
- package/dist/esm/messages/core.mjs.map +1 -1
- package/dist/esm/messages/format.mjs +7 -6
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/esm/messages/langchain.mjs +23 -0
- package/dist/esm/messages/langchain.mjs.map +1 -0
- package/dist/esm/messages/prune.mjs +7 -6
- package/dist/esm/messages/prune.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +5 -1
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +14 -4
- package/dist/types/agents/__tests__/promptCacheLiveHelpers.d.ts +46 -0
- package/dist/types/llm/anthropic/index.d.ts +22 -9
- package/dist/types/llm/anthropic/types.d.ts +5 -1
- package/dist/types/llm/anthropic/utils/message_outputs.d.ts +13 -6
- package/dist/types/llm/anthropic/utils/output_parsers.d.ts +1 -1
- package/dist/types/llm/openai/index.d.ts +21 -24
- package/dist/types/llm/openrouter/index.d.ts +11 -9
- package/dist/types/llm/vertexai/index.d.ts +1 -0
- package/dist/types/messages/cache.d.ts +4 -1
- package/dist/types/messages/langchain.d.ts +27 -0
- package/dist/types/types/graph.d.ts +26 -38
- package/dist/types/types/llm.d.ts +3 -3
- package/dist/types/types/run.d.ts +2 -0
- package/dist/types/types/stream.d.ts +1 -1
- package/package.json +17 -16
- package/src/agents/AgentContext.ts +123 -44
- package/src/agents/__tests__/AgentContext.anthropic.live.test.ts +116 -0
- package/src/agents/__tests__/AgentContext.bedrock.live.test.ts +149 -0
- package/src/agents/__tests__/AgentContext.test.ts +155 -2
- package/src/agents/__tests__/promptCacheLiveHelpers.ts +165 -0
- package/src/graphs/Graph.ts +24 -4
- package/src/graphs/__tests__/composition.smoke.test.ts +188 -0
- package/src/llm/anthropic/index.ts +252 -84
- package/src/llm/anthropic/llm.spec.ts +751 -102
- package/src/llm/anthropic/types.ts +9 -1
- package/src/llm/anthropic/utils/message_inputs.ts +43 -20
- package/src/llm/anthropic/utils/message_outputs.ts +119 -101
- package/src/llm/anthropic/utils/server-tool-inputs.test.ts +77 -0
- package/src/llm/bedrock/index.ts +2 -2
- package/src/llm/bedrock/llm.spec.ts +341 -0
- package/src/llm/bedrock/utils/message_inputs.ts +303 -4
- package/src/llm/bedrock/utils/message_outputs.ts +2 -1
- package/src/llm/custom-chat-models.smoke.test.ts +662 -0
- package/src/llm/google/llm.spec.ts +339 -57
- package/src/llm/google/utils/common.ts +53 -48
- package/src/llm/openai/contentBlocks.test.ts +346 -0
- package/src/llm/openai/index.ts +736 -837
- package/src/llm/openai/utils/index.ts +84 -64
- package/src/llm/openrouter/index.ts +124 -247
- package/src/llm/openrouter/reasoning.test.ts +8 -1
- package/src/llm/vertexai/index.ts +11 -5
- package/src/llm/vertexai/llm.spec.ts +28 -1
- package/src/messages/cache.test.ts +106 -4
- package/src/messages/cache.ts +57 -5
- package/src/messages/core.ts +16 -9
- package/src/messages/format.ts +9 -6
- package/src/messages/langchain.ts +39 -0
- package/src/messages/prune.ts +12 -8
- package/src/scripts/caching.ts +2 -3
- package/src/specs/anthropic.simple.test.ts +61 -0
- package/src/specs/summarization.test.ts +58 -61
- package/src/tools/ToolNode.ts +5 -1
- package/src/types/graph.ts +35 -88
- package/src/types/llm.ts +3 -3
- package/src/types/run.ts +2 -0
- package/src/types/stream.ts +1 -1
- package/src/utils/llmConfig.ts +1 -6
package/src/types/graph.ts
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
// src/types/graph.ts
|
|
2
|
-
import type {
|
|
3
|
-
START,
|
|
4
|
-
StateType,
|
|
5
|
-
UpdateType,
|
|
6
|
-
StateGraph,
|
|
7
|
-
StateGraphArgs,
|
|
8
|
-
StateDefinition,
|
|
9
|
-
CompiledStateGraph,
|
|
10
|
-
BinaryOperatorAggregate,
|
|
11
|
-
} from '@langchain/langgraph';
|
|
2
|
+
import type { START, StateGraph, StateGraphArgs } from '@langchain/langgraph';
|
|
12
3
|
import type { BindToolsInput } from '@langchain/core/language_models/chat_models';
|
|
13
4
|
import type {
|
|
14
5
|
BaseMessage,
|
|
@@ -129,76 +120,40 @@ export type Workflow<
|
|
|
129
120
|
N extends string = string,
|
|
130
121
|
> = StateGraph<T, U, N>;
|
|
131
122
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
U extends Partial<T> = Partial<T>,
|
|
135
|
-
N extends string = string,
|
|
136
|
-
> = CompiledStateGraph<T, U, N>;
|
|
137
|
-
|
|
138
|
-
export type CompiledStateWorkflow = CompiledStateGraph<
|
|
139
|
-
StateType<{
|
|
140
|
-
messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
141
|
-
}>,
|
|
142
|
-
UpdateType<{
|
|
143
|
-
messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
144
|
-
}>,
|
|
145
|
-
string,
|
|
146
|
-
{
|
|
147
|
-
messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
151
|
-
},
|
|
152
|
-
StateDefinition
|
|
123
|
+
type LangChainEventStreamCallbackHandlerInput = NonNullable<
|
|
124
|
+
Parameters<Runnable['streamEvents']>[2]
|
|
153
125
|
>;
|
|
154
126
|
|
|
155
|
-
export type
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
162
|
-
agentMessages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
163
|
-
}>,
|
|
164
|
-
string,
|
|
165
|
-
{
|
|
166
|
-
messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
167
|
-
agentMessages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
168
|
-
},
|
|
169
|
-
{
|
|
170
|
-
messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
171
|
-
agentMessages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
172
|
-
},
|
|
173
|
-
StateDefinition
|
|
174
|
-
>;
|
|
127
|
+
export type EventStreamCallbackHandlerInput =
|
|
128
|
+
LangChainEventStreamCallbackHandlerInput & {
|
|
129
|
+
autoClose?: boolean;
|
|
130
|
+
raiseError?: boolean;
|
|
131
|
+
ignoreCustomEvent?: boolean;
|
|
132
|
+
};
|
|
175
133
|
|
|
176
|
-
export type
|
|
134
|
+
export type WorkflowValuesStreamConfig = RunnableConfig & {
|
|
135
|
+
streamMode: 'values';
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* LangGraph stream output is mode-dependent (`values`, `updates`, SSE, etc.).
|
|
140
|
+
* Keep the base Runnable stream output as unknown and narrow at callsites that
|
|
141
|
+
* choose a concrete streamMode.
|
|
142
|
+
*/
|
|
143
|
+
export type CompiledWorkflow<
|
|
144
|
+
TInput extends BaseGraphState = BaseGraphState,
|
|
145
|
+
TOutput extends BaseGraphState = TInput,
|
|
146
|
+
> = Omit<Runnable<TInput, unknown>, 'invoke'> & {
|
|
147
|
+
invoke(input: TInput, config?: RunnableConfig): Promise<TOutput>;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export type CompiledStateWorkflow = CompiledWorkflow;
|
|
151
|
+
|
|
152
|
+
export type CompiledMultiAgentWorkflow = CompiledWorkflow<MultiAgentGraphState>;
|
|
153
|
+
|
|
154
|
+
export type CompiledAgentWorfklow = CompiledWorkflow<
|
|
177
155
|
AgentSubgraphState,
|
|
178
|
-
|
|
179
|
-
'__start__' | `agent=${string}` | `tools=${string}` | `summarize=${string}`,
|
|
180
|
-
{
|
|
181
|
-
messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
182
|
-
summarizationRequest: BinaryOperatorAggregate<
|
|
183
|
-
SummarizationNodeInput | undefined,
|
|
184
|
-
SummarizationNodeInput | undefined
|
|
185
|
-
>;
|
|
186
|
-
},
|
|
187
|
-
{
|
|
188
|
-
messages: BinaryOperatorAggregate<BaseMessage[], BaseMessage[]>;
|
|
189
|
-
summarizationRequest: BinaryOperatorAggregate<
|
|
190
|
-
SummarizationNodeInput | undefined,
|
|
191
|
-
SummarizationNodeInput | undefined
|
|
192
|
-
>;
|
|
193
|
-
},
|
|
194
|
-
StateDefinition,
|
|
195
|
-
{
|
|
196
|
-
[x: `agent=${string}`]: Partial<BaseGraphState>;
|
|
197
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
198
|
-
[x: `tools=${string}`]: any;
|
|
199
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
200
|
-
[x: `summarize=${string}`]: any;
|
|
201
|
-
}
|
|
156
|
+
AgentSubgraphState
|
|
202
157
|
>;
|
|
203
158
|
|
|
204
159
|
export type SystemRunnable =
|
|
@@ -214,21 +169,11 @@ export type SystemRunnable =
|
|
|
214
169
|
* These are intentionally untyped to avoid coupling to library internals.
|
|
215
170
|
*/
|
|
216
171
|
export type CompileOptions = {
|
|
217
|
-
|
|
218
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
219
|
-
checkpointer?: any;
|
|
172
|
+
checkpointer?: unknown;
|
|
220
173
|
interruptBefore?: string[];
|
|
221
174
|
interruptAfter?: string[];
|
|
222
175
|
};
|
|
223
176
|
|
|
224
|
-
export type EventStreamCallbackHandlerInput =
|
|
225
|
-
Parameters<CompiledWorkflow['streamEvents']>[2] extends Omit<
|
|
226
|
-
infer T,
|
|
227
|
-
'autoClose'
|
|
228
|
-
>
|
|
229
|
-
? T
|
|
230
|
-
: never;
|
|
231
|
-
|
|
232
177
|
export type StreamChunk =
|
|
233
178
|
| (ChatGenerationChunk & {
|
|
234
179
|
message: AIMessageChunk;
|
|
@@ -471,10 +416,12 @@ export interface AgentInputs {
|
|
|
471
416
|
toolMap?: ToolMap;
|
|
472
417
|
tools?: GraphTools;
|
|
473
418
|
provider: Providers;
|
|
419
|
+
/** Stable/cacheable system instructions. */
|
|
474
420
|
instructions?: string;
|
|
475
421
|
streamBuffer?: number;
|
|
476
422
|
maxContextTokens?: number;
|
|
477
423
|
clientOptions?: ClientOptions;
|
|
424
|
+
/** Dynamic system tail appended after stable instructions without provider cache markers. */
|
|
478
425
|
additional_instructions?: string;
|
|
479
426
|
reasoningKey?: 'reasoning_content' | 'reasoning';
|
|
480
427
|
/** Format content blocks as strings (for legacy compatibility i.e. Ollama/Azure Serverless) */
|
|
@@ -500,7 +447,7 @@ export interface AgentInputs {
|
|
|
500
447
|
summarizationEnabled?: boolean;
|
|
501
448
|
summarizationConfig?: SummarizationConfig;
|
|
502
449
|
/** Cross-run summary from a previous run, forwarded from formatAgentMessages.
|
|
503
|
-
* Injected into the system
|
|
450
|
+
* Injected into the dynamic system tail via AgentContext. */
|
|
504
451
|
initialSummary?: { text: string; tokenCount: number };
|
|
505
452
|
contextPruningConfig?: ContextPruningConfig;
|
|
506
453
|
maxToolResultChars?: number;
|
package/src/types/llm.ts
CHANGED
|
@@ -12,7 +12,7 @@ import type {
|
|
|
12
12
|
} from '@langchain/openai';
|
|
13
13
|
import type { GoogleGenerativeAIChatInput } from '@langchain/google-genai';
|
|
14
14
|
import type { ChatVertexAIInput } from '@langchain/google-vertexai';
|
|
15
|
-
import type {
|
|
15
|
+
import type { ChatDeepSeekInput } from '@langchain/deepseek';
|
|
16
16
|
import type { ChatOpenRouterCallOptions } from '@/llm/openrouter';
|
|
17
17
|
import type { ChatBedrockConverseInput } from '@langchain/aws';
|
|
18
18
|
import type { ChatMistralAIInput } from '@langchain/mistralai';
|
|
@@ -70,7 +70,7 @@ export type AnthropicReasoning = {
|
|
|
70
70
|
export type GoogleThinkingConfig = {
|
|
71
71
|
thinkingBudget?: number;
|
|
72
72
|
includeThoughts?: boolean;
|
|
73
|
-
thinkingLevel?:
|
|
73
|
+
thinkingLevel?: 'THINKING_LEVEL_UNSPECIFIED' | 'LOW' | 'MEDIUM' | 'HIGH';
|
|
74
74
|
};
|
|
75
75
|
export type OpenAIClientOptions = ChatOpenAIFields;
|
|
76
76
|
export type AnthropicClientOptions = Omit<AnthropicInput, 'thinking'> & {
|
|
@@ -93,7 +93,7 @@ export type GoogleClientOptions = GoogleGenerativeAIChatInput & {
|
|
|
93
93
|
customHeaders?: RequestOptions['customHeaders'];
|
|
94
94
|
thinkingConfig?: GoogleThinkingConfig;
|
|
95
95
|
};
|
|
96
|
-
export type DeepSeekClientOptions =
|
|
96
|
+
export type DeepSeekClientOptions = Partial<ChatDeepSeekInput>;
|
|
97
97
|
export type XAIClientOptions = ChatXAIInput;
|
|
98
98
|
|
|
99
99
|
export type ClientOptions =
|
package/src/types/run.ts
CHANGED
|
@@ -75,7 +75,9 @@ export interface AgentStateChannels {
|
|
|
75
75
|
messages: BaseMessage[];
|
|
76
76
|
next: string;
|
|
77
77
|
[key: string]: unknown;
|
|
78
|
+
/** Stable/cacheable system instructions. */
|
|
78
79
|
instructions?: string;
|
|
80
|
+
/** Dynamic system tail appended after stable instructions. */
|
|
79
81
|
additional_instructions?: string;
|
|
80
82
|
}
|
|
81
83
|
|
package/src/types/stream.ts
CHANGED
package/src/utils/llmConfig.ts
CHANGED
|
@@ -56,9 +56,7 @@ export const llmConfigs: Record<string, t.LLMConfig | undefined> = {
|
|
|
56
56
|
provider: Providers.OPENROUTER,
|
|
57
57
|
streaming: true,
|
|
58
58
|
streamUsage: true,
|
|
59
|
-
|
|
60
|
-
// model: 'moonshotai/kimi-k2-thinking',
|
|
61
|
-
model: 'google/gemini-3-pro-preview',
|
|
59
|
+
model: process.env.OPENROUTER_MODEL ?? 'openai/gpt-4o-mini',
|
|
62
60
|
apiKey: process.env.OPENROUTER_API_KEY,
|
|
63
61
|
configuration: {
|
|
64
62
|
baseURL: process.env.OPENROUTER_BASE_URL,
|
|
@@ -67,9 +65,6 @@ export const llmConfigs: Record<string, t.LLMConfig | undefined> = {
|
|
|
67
65
|
'X-Title': 'LibreChat',
|
|
68
66
|
},
|
|
69
67
|
},
|
|
70
|
-
reasoning: {
|
|
71
|
-
max_tokens: 8000,
|
|
72
|
-
},
|
|
73
68
|
modelKwargs: {
|
|
74
69
|
max_tokens: 10000,
|
|
75
70
|
},
|