@librechat/agents 3.9.5 → 3.9.6

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.
@@ -129,6 +129,7 @@ import {
129
129
  resolveLocalExecutionTools,
130
130
  } from '@/tools/local';
131
131
  import { stripCodeSessionFileSummary } from '@/tools/CodeSessionFileSummary';
132
+ import { formatToolErrorContent } from '@/tools/toolErrorContent';
132
133
  import { Constants, GraphEvents, CODE_EXECUTION_TOOLS } from '@/common';
133
134
  import { PreparedSubagentError } from '@/tools/preparedSubagents';
134
135
  import { attachRunStepResumeState } from '@/tools/runStepResume';
@@ -2201,9 +2202,11 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
2201
2202
  });
2202
2203
  }
2203
2204
  }
2204
- const errorContent = truncateToolResultContent(
2205
- `Error: ${e.message}\n Please fix your mistakes.`,
2206
- this.maxToolResultChars
2205
+ const errorContent = formatToolErrorContent(
2206
+ e.message,
2207
+ this.maxToolResultChars,
2208
+ config.signal,
2209
+ e
2207
2210
  );
2208
2211
  const refMeta =
2209
2212
  unresolvedRefs.length > 0
@@ -4461,9 +4464,10 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
4461
4464
  let finalToolOutput: unknown = result.content;
4462
4465
 
4463
4466
  if (result.status === 'error') {
4464
- contentString = truncateToolResultContent(
4465
- `Error: ${result.errorMessage ?? 'Unknown error'}\n Please fix your mistakes.`,
4466
- this.maxToolResultChars
4467
+ contentString = formatToolErrorContent(
4468
+ result.errorMessage,
4469
+ this.maxToolResultChars,
4470
+ config.signal
4467
4471
  );
4468
4472
  /**
4469
4473
  * Error results bypass registration but stamp the
@@ -4977,9 +4981,10 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
4977
4981
  ): Promise<boolean> {
4978
4982
  const output =
4979
4983
  result.status === 'error'
4980
- ? truncateToolResultContent(
4981
- `Error: ${result.errorMessage ?? 'Unknown error'}\n Please fix your mistakes.`,
4982
- this.maxToolResultChars
4984
+ ? formatToolErrorContent(
4985
+ result.errorMessage,
4986
+ this.maxToolResultChars,
4987
+ config.signal
4983
4988
  )
4984
4989
  : serializeToolOutputWithinLimits(
4985
4990
  result.content,
@@ -0,0 +1,48 @@
1
+ import { PreparedSubagentError } from '@/tools/preparedSubagents';
2
+ import { truncateToolResultContent } from '@/utils/truncation';
3
+ import { StreamLimitExceededError } from '@/llm/streamLimits';
4
+
5
+ export const STOPPED_RUN_TOOL_ERROR =
6
+ 'STOP. The user doesn\'t want to proceed with this tool use. ' +
7
+ 'The run was stopped; the tool may not have completed, and its effects should not be assumed. ' +
8
+ 'STOP what you are doing and wait for the user to tell you how to proceed.';
9
+
10
+ /** A host result only carries error text, so require the run signal as well. */
11
+ function isStoppedRunToolError(
12
+ message: string | undefined,
13
+ signal?: AbortSignal,
14
+ error?: Error
15
+ ): boolean {
16
+ if (
17
+ signal?.aborted !== true ||
18
+ signal.reason instanceof StreamLimitExceededError ||
19
+ signal.reason instanceof PreparedSubagentError
20
+ ) {
21
+ return false;
22
+ }
23
+ if (
24
+ (error != null && error === signal.reason) ||
25
+ (error instanceof Error &&
26
+ (error.name === 'AbortError' ||
27
+ ('code' in error &&
28
+ (error.code === 'ABORT_ERR' || error.code === 'ERR_CANCELED'))))
29
+ ) {
30
+ return true;
31
+ }
32
+ return (
33
+ message != null &&
34
+ /AbortError|(?:operation|request|stream) was aborted/i.test(message)
35
+ );
36
+ }
37
+
38
+ export function formatToolErrorContent(
39
+ message: string | undefined,
40
+ maxChars: number,
41
+ signal?: AbortSignal,
42
+ error?: Error
43
+ ): string {
44
+ const content = isStoppedRunToolError(message, signal, error)
45
+ ? STOPPED_RUN_TOOL_ERROR
46
+ : `Error: ${message ?? 'Unknown error'}\n Please fix your mistakes.`;
47
+ return truncateToolResultContent(content, maxChars);
48
+ }