Skip to content

Commit

Permalink
feat(agent): add template for tool not found error
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas2D committed Sep 3, 2024
1 parent 6cda741 commit c4ea1c8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
8 changes: 8 additions & 0 deletions src/agents/bee/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,11 @@ export const BeeToolNoResultsPrompt = new PromptTemplate({
variables: [],
template: `No results were found!`,
});

export const BeeToolNotFoundPrompt = new PromptTemplate({
variables: ["tools"],
template: `Tool does not exist!
{{#tools.length}}
Use one of the following tools: {{#trim}}{{#tools}}{{name}},{{/tools}}{{/trim}}
{{/tools.length}}`,
});
20 changes: 11 additions & 9 deletions src/agents/bee/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
BeeToolErrorPrompt,
BeeToolInputErrorPrompt,
BeeToolNoResultsPrompt,
BeeToolNotFoundPrompt,
BeeUserPrompt,
} from "@/agents/bee/prompts.js";
import { BeeIterationToolResult, BeeOutputParser } from "@/agents/bee/parser.js";
Expand Down Expand Up @@ -190,17 +191,18 @@ export class BeeAgentRunner {
(tool) => tool.name.trim().toUpperCase() == iteration.tool_name?.toUpperCase(),
);
if (!tool) {
this.failedAttemptsCounter.use();
const availableTools = this.input.tools.map((tool) => tool.name);
this.failedAttemptsCounter.use(
new AgentError(`Agent was trying to use non-existing tool "${iteration.tool_name}"`, [], {
context: { iteration, meta },
}),
);

const template = this.input.templates?.toolNotFoundError ?? BeeToolNotFoundPrompt;
return {
success: false,
output: [
`Tool does not exist!`,
availableTools.length > 0 &&
`Use one of the following tools: ${availableTools.join(",")}`,
]
.filter(Boolean)
.join("\n"),
output: template.render({
tools: this.input.tools,
}),
};
}
const options = await (async () => {
Expand Down
2 changes: 2 additions & 0 deletions src/agents/bee/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
BeeToolErrorPrompt,
BeeToolInputErrorPrompt,
BeeToolNoResultsPrompt,
BeeToolNotFoundPrompt,
BeeUserPrompt,
} from "@/agents/bee/prompts.js";

Expand Down Expand Up @@ -126,4 +127,5 @@ export interface BeeAgentTemplates {
toolError: typeof BeeToolErrorPrompt;
toolInputError: typeof BeeToolInputErrorPrompt;
toolNoResultError: typeof BeeToolNoResultsPrompt;
toolNotFoundError: typeof BeeToolNotFoundPrompt;
}

0 comments on commit c4ea1c8

Please sign in to comment.