@librechat/agents 2.4.52 → 2.4.53

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.
Files changed (64) hide show
  1. package/dist/cjs/graphs/Graph.cjs +7 -6
  2. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  3. package/dist/cjs/llm/anthropic/index.cjs +8 -8
  4. package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
  5. package/dist/cjs/llm/anthropic/types.cjs.map +1 -1
  6. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +15 -0
  7. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
  8. package/dist/cjs/main.cjs +2 -0
  9. package/dist/cjs/main.cjs.map +1 -1
  10. package/dist/cjs/stream.cjs +8 -0
  11. package/dist/cjs/stream.cjs.map +1 -1
  12. package/dist/cjs/tools/ToolNode.cjs +8 -2
  13. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  14. package/dist/cjs/tools/handlers.cjs +101 -1
  15. package/dist/cjs/tools/handlers.cjs.map +1 -1
  16. package/dist/cjs/tools/search/anthropic.cjs +40 -0
  17. package/dist/cjs/tools/search/anthropic.cjs.map +1 -0
  18. package/dist/cjs/tools/search/search.cjs +2 -2
  19. package/dist/cjs/tools/search/search.cjs.map +1 -1
  20. package/dist/esm/graphs/Graph.mjs +7 -6
  21. package/dist/esm/graphs/Graph.mjs.map +1 -1
  22. package/dist/esm/llm/anthropic/index.mjs +8 -8
  23. package/dist/esm/llm/anthropic/index.mjs.map +1 -1
  24. package/dist/esm/llm/anthropic/types.mjs.map +1 -1
  25. package/dist/esm/llm/anthropic/utils/message_inputs.mjs +15 -0
  26. package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
  27. package/dist/esm/main.mjs +1 -1
  28. package/dist/esm/stream.mjs +9 -1
  29. package/dist/esm/stream.mjs.map +1 -1
  30. package/dist/esm/tools/ToolNode.mjs +8 -2
  31. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  32. package/dist/esm/tools/handlers.mjs +101 -3
  33. package/dist/esm/tools/handlers.mjs.map +1 -1
  34. package/dist/esm/tools/search/anthropic.mjs +37 -0
  35. package/dist/esm/tools/search/anthropic.mjs.map +1 -0
  36. package/dist/esm/tools/search/search.mjs +2 -2
  37. package/dist/esm/tools/search/search.mjs.map +1 -1
  38. package/dist/types/graphs/Graph.d.ts +2 -0
  39. package/dist/types/llm/anthropic/types.d.ts +2 -0
  40. package/dist/types/llm/anthropic/utils/message_inputs.d.ts +1 -1
  41. package/dist/types/llm/anthropic/utils/output_parsers.d.ts +3 -3
  42. package/dist/types/scripts/ant_web_search.d.ts +1 -0
  43. package/dist/types/tools/CodeExecutor.d.ts +2 -2
  44. package/dist/types/tools/ToolNode.d.ts +1 -1
  45. package/dist/types/tools/handlers.d.ts +11 -0
  46. package/dist/types/tools/search/anthropic.d.ts +16 -0
  47. package/dist/types/types/llm.d.ts +3 -2
  48. package/dist/types/types/stream.d.ts +9 -1
  49. package/package.json +5 -3
  50. package/src/graphs/Graph.ts +8 -6
  51. package/src/llm/anthropic/Jacob_Lee_Resume_2023.pdf +0 -0
  52. package/src/llm/anthropic/index.ts +7 -12
  53. package/src/llm/anthropic/llm.spec.ts +447 -115
  54. package/src/llm/anthropic/types.ts +16 -0
  55. package/src/llm/anthropic/utils/message_inputs.ts +17 -2
  56. package/src/llm/anthropic/utils/output_parsers.ts +4 -4
  57. package/src/scripts/ant_web_search.ts +158 -0
  58. package/src/stream.ts +16 -5
  59. package/src/tools/ToolNode.ts +17 -3
  60. package/src/tools/handlers.ts +163 -1
  61. package/src/tools/search/anthropic.ts +51 -0
  62. package/src/tools/search/search.ts +2 -1
  63. package/src/types/llm.ts +4 -2
  64. package/src/types/stream.ts +14 -0
@@ -2,6 +2,7 @@ import type OpenAITypes from 'openai';
2
2
  import type { MessageContentImageUrl, MessageContentText, ToolMessage, BaseMessage } from '@langchain/core/messages';
3
3
  import type { ToolCall, ToolCallChunk } from '@langchain/core/messages/tool';
4
4
  import type { LLMResult, Generation } from '@langchain/core/outputs';
5
+ import type { AnthropicContentBlock } from '@/llm/anthropic/types';
5
6
  import type { ToolEndEvent } from '@/types/tools';
6
7
  import { StepTypes, ContentTypes, GraphEvents } from '@/common/enum';
7
8
  export type HandleLLMEnd = (output: LLMResult, runId: string, parentRunId?: string, tags?: string[]) => void;
@@ -235,7 +236,14 @@ export type ToolCallContent = {
235
236
  type: ContentTypes.TOOL_CALL;
236
237
  tool_call?: ToolCallPart;
237
238
  };
238
- export type MessageContentComplex = (ThinkingContentText | AgentUpdate | ToolCallContent | ReasoningContentText | MessageContentText | MessageContentImageUrl | (Record<string, any> & {
239
+ export type ToolResultContent = {
240
+ content: string | Record<string, unknown> | Array<string | Record<string, unknown>> | AnthropicContentBlock[];
241
+ type: 'tool_result' | 'web_search_result' | 'web_search_tool_result';
242
+ tool_use_id?: string;
243
+ input?: string | Record<string, unknown>;
244
+ index?: number;
245
+ };
246
+ export type MessageContentComplex = (ToolResultContent | ThinkingContentText | AgentUpdate | ToolCallContent | ReasoningContentText | MessageContentText | MessageContentImageUrl | (Record<string, any> & {
239
247
  type?: 'text' | 'image_url' | 'think' | 'thinking' | string;
240
248
  }) | (Record<string, any> & {
241
249
  type?: never;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@librechat/agents",
3
- "version": "2.4.52",
3
+ "version": "2.4.53",
4
4
  "main": "./dist/cjs/main.cjs",
5
5
  "module": "./dist/esm/main.mjs",
6
6
  "types": "./dist/types/index.d.ts",
@@ -47,12 +47,13 @@
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 'openAI' --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 'anthropic' --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'",
54
54
  "tool-test": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/tools.ts --provider 'bedrock' --name 'Jo' --location 'New York, NY'",
55
55
  "search": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/search.ts --provider 'anthropic' --name 'Jo' --location 'New York, NY'",
56
+ "ant_web_search": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/ant_web_search.ts --name 'Jo' --location 'New York, NY'",
56
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'",
57
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'",
58
59
  "script2": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/proto/example_test.ts",
@@ -72,7 +73,7 @@
72
73
  "format": "prettier --write ."
73
74
  },
74
75
  "dependencies": {
75
- "@langchain/anthropic": "^0.3.23",
76
+ "@langchain/anthropic": "^0.3.24",
76
77
  "@langchain/aws": "^0.1.11",
77
78
  "@langchain/community": "^0.3.47",
78
79
  "@langchain/core": "^0.3.62",
@@ -94,6 +95,7 @@
94
95
  "~/*": "./*"
95
96
  },
96
97
  "devDependencies": {
98
+ "@anthropic-ai/vertex-sdk": "^0.12.0",
97
99
  "@eslint/compat": "^1.2.7",
98
100
  "@rollup/plugin-alias": "^5.1.0",
99
101
  "@rollup/plugin-commonjs": "^28.0.3",
@@ -123,6 +123,8 @@ export abstract class Graph<
123
123
  streamBuffer: number | undefined;
124
124
  tokenCounter?: t.TokenCounter;
125
125
  signal?: AbortSignal;
126
+ /** Set of invoked tool call IDs from non-message run steps completed mid-run, if any */
127
+ invokedToolIds?: Set<string>;
126
128
  }
127
129
 
128
130
  export class StandardGraph extends Graph<t.BaseGraphState, GraphNode> {
@@ -238,6 +240,7 @@ export class StandardGraph extends Graph<t.BaseGraphState, GraphNode> {
238
240
  this.currentUsage = resetIfNotEmpty(this.currentUsage, undefined);
239
241
  this.tokenCounter = resetIfNotEmpty(this.tokenCounter, undefined);
240
242
  this.maxContextTokens = resetIfNotEmpty(this.maxContextTokens, undefined);
243
+ this.invokedToolIds = resetIfNotEmpty(this.invokedToolIds, undefined);
241
244
  }
242
245
 
243
246
  /* Run Step Processing */
@@ -310,6 +313,10 @@ export class StandardGraph extends Graph<t.BaseGraphState, GraphNode> {
310
313
  keyList.push('reasoning');
311
314
  }
312
315
 
316
+ if (this.invokedToolIds != null && this.invokedToolIds.size > 0) {
317
+ keyList.push(this.invokedToolIds.size + '');
318
+ }
319
+
313
320
  return keyList;
314
321
  }
315
322
 
@@ -607,12 +614,7 @@ export class StandardGraph extends Graph<t.BaseGraphState, GraphNode> {
607
614
  config?: RunnableConfig
608
615
  ): string => {
609
616
  this.config = config;
610
- // const lastMessage = state.messages[state.messages.length - 1] as AIMessage;
611
- // if (!lastMessage?.tool_calls?.length) {
612
- // return END;
613
- // }
614
- // return TOOLS;
615
- return toolsCondition(state);
617
+ return toolsCondition(state, this.invokedToolIds);
616
618
  };
617
619
 
618
620
  const workflow = new StateGraph<t.BaseGraphState>({
@@ -128,6 +128,7 @@ export class CustomAnthropic extends ChatAnthropicMessages {
128
128
  private emitted_usage?: boolean;
129
129
  constructor(fields?: CustomAnthropicInput) {
130
130
  super(fields);
131
+ this.resetTokenEvents();
131
132
  this._lc_stream_delay = fields?._lc_stream_delay ?? 25;
132
133
  }
133
134
 
@@ -209,6 +210,7 @@ export class CustomAnthropic extends ChatAnthropicMessages {
209
210
  options: this['ParsedCallOptions'],
210
211
  runManager?: CallbackManagerForLLMRun
211
212
  ): AsyncGenerator<ChatGenerationChunk> {
213
+ this.resetTokenEvents();
212
214
  const params = this.invocationParams(options);
213
215
  const formattedMessages = _convertMessagesToAnthropicPayload(messages);
214
216
  const payload = {
@@ -221,16 +223,9 @@ export class CustomAnthropic extends ChatAnthropicMessages {
221
223
  !_documentsInParams(payload) &&
222
224
  !_thinkingInParams(payload);
223
225
 
224
- const stream = await this.createStreamWithRetry(
225
- {
226
- ...params,
227
- ...formattedMessages,
228
- stream: true,
229
- },
230
- {
231
- headers: options.headers,
232
- }
233
- );
226
+ const stream = await this.createStreamWithRetry(payload, {
227
+ headers: options.headers,
228
+ });
234
229
 
235
230
  const shouldStreamUsage = this.streamUsage ?? options.streamUsage;
236
231
 
@@ -263,7 +258,7 @@ export class CustomAnthropic extends ChatAnthropicMessages {
263
258
  if (
264
259
  !tokenType ||
265
260
  tokenType === 'input' ||
266
- (token === '' && usageMetadata)
261
+ (token === '' && (usageMetadata != null || chunk.id != null))
267
262
  ) {
268
263
  const generationChunk = this.createGenerationChunk({
269
264
  token,
@@ -309,7 +304,7 @@ export class CustomAnthropic extends ChatAnthropicMessages {
309
304
  yield generationChunk;
310
305
 
311
306
  await runManager?.handleLLMNewToken(
312
- token,
307
+ currentToken,
313
308
  undefined,
314
309
  undefined,
315
310
  undefined,