Skip to content

Commit

Permalink
feat(agent): update tool error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas2D committed Sep 24, 2024
1 parent 48663ba commit d403665
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/agents/bee/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ import { BeeAgentError } from "@/agents/bee/errors.js";
import { BaseMessage, Role } from "@/llms/primitives/message.js";
import { TokenMemory } from "@/memory/tokenMemory.js";
import { BeeAgentRunIteration, BeeCallbacks, BeeMeta, BeeRunOptions } from "@/agents/bee/types.js";
import { BaseToolRunOptions, ToolInputValidationError, ToolOutput } from "@/tools/base.js";
import {
BaseToolRunOptions,
ToolError,
ToolInputValidationError,
ToolOutput,
} from "@/tools/base.js";
import { getProp } from "@/internals/helpers/object.js";
import { Retryable } from "@/internals/helpers/retryable.js";
import { FrameworkError } from "@/errors.js";
Expand Down Expand Up @@ -271,17 +276,16 @@ export class BeeAgentRunner {
this.failedAttemptsCounter.use(error);
},
executor: async () => {
await emitter.emit("toolStart", {
data: {
tool,
input: iteration.tool_input,
options,
iteration,
},
meta,
});

try {
await emitter.emit("toolStart", {
data: {
tool,
input: iteration.tool_input,
options,
iteration,
},
meta,
});
const toolOutput: ToolOutput = await tool.run(iteration.tool_input, options);
await emitter.emit("toolSuccess", {
data: {
Expand Down Expand Up @@ -327,14 +331,14 @@ export class BeeAgentRunner {
};
}

if (FrameworkError.isRetryable(error)) {
if (error instanceof ToolError) {
this.failedAttemptsCounter.use(error);

const template = this.input.templates?.toolError ?? BeeToolErrorPrompt;
return {
success: false,
output: template.render({
reason: FrameworkError.ensure(error).explain(),
reason: error.explain(),
}),
};
}
Expand Down

0 comments on commit d403665

Please sign in to comment.