Skip to content

Commit

Permalink
feat(react): improve max retries error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas2D committed Aug 28, 2024
1 parent dba7ad7 commit 54895f9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/agents/bee/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
BeeUserPrompt,
} from "@/agents/bee/prompts.js";
import { BeeIterationToolResult, BeeOutputParser } from "@/agents/bee/parser.js";
import { AgentError } from "@/agents/base.js";

export class BeeAgentRunnerFatalError extends BeeAgentError {
isFatal = true;
Expand All @@ -50,7 +51,7 @@ export class BeeAgentRunner {
protected readonly options: BeeRunOptions,
public readonly memory: TokenMemory,
) {
this.failedAttemptsCounter = new RetryCounter(options?.execution?.totalMaxRetries);
this.failedAttemptsCounter = new RetryCounter(options?.execution?.totalMaxRetries, AgentError);
}

static async create(
Expand Down
10 changes: 7 additions & 3 deletions src/internals/helpers/counter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export class RetryCounter extends Serializable {
protected readonly maxRetries: number;
protected lastError?: Error;

constructor(maxRetries = 0) {
constructor(
maxRetries = 0,
protected ErrorClass: typeof FrameworkError,
) {
super();
this.maxRetries = maxRetries;
this.remaining = maxRetries;
Expand All @@ -32,8 +35,8 @@ export class RetryCounter extends Serializable {
this.lastError = error ?? this.lastError;

if (this.remaining <= 0) {
throw new FrameworkError(
`Maximal amount of global retries '${this.maxRetries}' has been reached!`,
throw new this.ErrorClass(
`Maximal amount of global retries (${this.maxRetries}) has been reached.`,
this.lastError ? [this.lastError] : undefined,
{ isFatal: true },
);
Expand All @@ -46,6 +49,7 @@ export class RetryCounter extends Serializable {
remaining: this.remaining,
maxRetries: this.maxRetries,
lastError: this.lastError,
ErrorClass: this.ErrorClass,
};
}

Expand Down
1 change: 1 addition & 0 deletions src/tools/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ export abstract class Tool<

protected toError(e: Error, context: any) {
if (e instanceof ToolError) {
Object.assign(e.context, context);
return e;
} else {
return new ToolError(`Tool "${this.name}" has occurred an error!`, [e], {
Expand Down

0 comments on commit 54895f9

Please sign in to comment.