Skip to content

Commit

Permalink
feat(agents): extend bee start event (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas2D authored Dec 13, 2024
1 parent 2925dfc commit 368aa2a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/agents/bee/runners/default/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { TokenMemory } from "@/memory/tokenMemory.js";
import { getProp } from "@/internals/helpers/object.js";
import { BaseMemory } from "@/memory/base.js";
import { Cache } from "@/cache/decoratorCache.js";
import { shallowCopy } from "@/serializer/utils.js";

export class DefaultRunner extends BaseRunner {
static {
Expand Down Expand Up @@ -85,9 +86,10 @@ export class DefaultRunner extends BaseRunner {
}
},
executor: async () => {
await emitter.emit("start", { meta });
const tools = this.input.tools.slice();
await emitter.emit("start", { meta, tools, memory: this.memory });

const { parser, parserRegex } = this.createParser(this.input.tools);
const { parser, parserRegex } = this.createParser(tools);
const llmOutput = await this.input.llm
.generate(this.memory.messages.slice(), {
signal,
Expand Down Expand Up @@ -184,24 +186,26 @@ export class DefaultRunner extends BaseRunner {
this.failedAttemptsCounter.use(error);
},
executor: async () => {
const toolOptions = shallowCopy(this.options);

try {
await emitter.emit("toolStart", {
data: {
tool,
input: state.tool_input,
options: this.options,
options: toolOptions,
iteration: state,
},
meta,
});
const toolOutput: ToolOutput = await tool.run(state.tool_input, this.options).context({
const toolOutput: ToolOutput = await tool.run(state.tool_input, toolOptions).context({
[Tool.contextKeys.Memory]: this.memory,
});
await emitter.emit("toolSuccess", {
data: {
tool,
input: state.tool_input,
options: this.options,
options: toolOptions,
result: toolOutput,
iteration: state,
},
Expand All @@ -221,7 +225,7 @@ export class DefaultRunner extends BaseRunner {
data: {
tool,
input: state.tool_input,
options: this.options,
options: toolOptions,
error,
iteration: state,
},
Expand Down
2 changes: 1 addition & 1 deletion src/agents/bee/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export interface BeeUpdateMeta extends BeeMeta {
}

export interface BeeCallbacks {
start?: Callback<{ meta: BeeMeta }>;
start?: Callback<{ meta: BeeMeta; tools: AnyTool[]; memory: BaseMemory }>;
error?: Callback<{ error: Error; meta: BeeMeta }>;
retry?: Callback<{ meta: BeeMeta }>;
success?: Callback<{
Expand Down

0 comments on commit 368aa2a

Please sign in to comment.