@librechat/agents 2.4.53 → 2.4.55

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.
@@ -7,16 +7,18 @@ import type { ToolCall, ToolCallChunk } from '@langchain/core/messages/tool';
7
7
  import type { Graph } from '@/graphs';
8
8
  import type * as t from '@/types';
9
9
  import {
10
- coerceAnthropicSearchResults,
11
- isAnthropicWebSearchResult,
12
- } from '@/tools/search/anthropic';
13
- import {
14
- StepTypes,
15
- ContentTypes,
16
10
  ToolCallTypes,
11
+ ContentTypes,
12
+ GraphEvents,
13
+ StepTypes,
17
14
  Providers,
18
15
  Constants,
19
16
  } from '@/common';
17
+ import {
18
+ coerceAnthropicSearchResults,
19
+ isAnthropicWebSearchResult,
20
+ } from '@/tools/search/anthropic';
21
+ import { formatResultsForLLM } from '@/tools/search/format';
20
22
  import { getMessageId } from '@/messages';
21
23
 
22
24
  export function handleToolCallChunks({
@@ -277,7 +279,7 @@ function handleAnthropicSearchResults({
277
279
  graph,
278
280
  }: {
279
281
  contentPart: t.ToolResultContent;
280
- toolCall: ToolCall;
282
+ toolCall: Partial<ToolCall>;
281
283
  metadata?: Record<string, unknown>;
282
284
  graph: Graph;
283
285
  }): void {
@@ -297,29 +299,34 @@ function handleAnthropicSearchResults({
297
299
  return;
298
300
  }
299
301
 
302
+ const turn = graph.invokedToolIds?.size ?? 0;
300
303
  const searchResultData = coerceAnthropicSearchResults({
304
+ turn,
301
305
  results: contentPart.content as AnthropicWebSearchResultBlockParam[],
302
- turn: graph.invokedToolIds?.size,
303
306
  });
304
307
 
305
308
  const name = toolCall.name;
306
- const input = toolCall.args;
309
+ const input = toolCall.args ?? {};
307
310
  const artifact = {
308
311
  [Constants.WEB_SEARCH]: searchResultData,
309
312
  };
313
+ const { output: formattedOutput } = formatResultsForLLM(
314
+ turn,
315
+ searchResultData
316
+ );
310
317
  const output = new ToolMessage({
311
318
  name,
312
319
  artifact,
313
- content: 'Anthropic web search results',
320
+ content: formattedOutput,
314
321
  tool_call_id: toolCall.id!,
315
322
  });
316
- graph.handleToolCallCompleted(
317
- {
318
- input,
319
- output,
320
- },
321
- metadata
322
- );
323
+ const toolEndData: t.ToolEndData = {
324
+ input,
325
+ output,
326
+ };
327
+ graph.handlerRegistry
328
+ ?.getHandler(GraphEvents.TOOL_END)
329
+ ?.handle(GraphEvents.TOOL_END, toolEndData, metadata, graph);
323
330
 
324
331
  if (graph.invokedToolIds == null) {
325
332
  graph.invokedToolIds = new Set<string>();