Skip to content

Commit

Permalink
feat(agent): make bee runner easier to override
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Dvorak <[email protected]>
  • Loading branch information
Tomas2D committed Oct 28, 2024
1 parent 8fce700 commit e7b99a0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/agents/bee/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ import {
BeeRunOutput,
} from "@/agents/bee/types.js";
import { GetRunContext } from "@/context.js";
import { BeeAgentRunner } from "@/agents/bee/runner.js";
import { BeeAgentError } from "@/agents/bee/errors.js";
import { BeeIterationToolResult } from "@/agents/bee/parser.js";
import { assign } from "@/internals/helpers/object.js";
import { BeeAgentRunner } from "@/agents/bee/runner.js";

export interface BeeInput {
llm: ChatLLM<ChatLLMOutput>;
Expand All @@ -52,6 +52,8 @@ export class BeeAgent extends BaseAgent<BeeRunInput, BeeRunOutput, BeeRunOptions
creator: this,
});

protected runner: typeof BeeAgentRunner = BeeAgentRunner;

constructor(protected readonly input: BeeInput) {
super();

Expand Down Expand Up @@ -102,7 +104,7 @@ export class BeeAgent extends BaseAgent<BeeRunInput, BeeRunOutput, BeeRunOptions
const iterations: BeeAgentRunIteration[] = [];
const maxIterations = options?.execution?.maxIterations ?? Infinity;

const runner = await BeeAgentRunner.create(this.input, options, input.prompt);
const runner = await this.runner.create(this.input, options, input.prompt);

let finalMessage: BaseMessage | undefined;
while (!finalMessage) {
Expand Down Expand Up @@ -195,6 +197,7 @@ export class BeeAgent extends BaseAgent<BeeRunInput, BeeRunOutput, BeeRunOptions
return {
input: this.input,
emitter: this.emitter,
runner: this.runner,
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/agents/bee/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { NonUndefined } from "@/internals/types.js";
import type { LinePrefixParser } from "@/agents/parsers/linePrefix.js";
import type { BeeAgentRunner } from "@/agents/bee/runner.js";

type Parser = ReturnType<typeof BeeAgentRunner.createParser>["parser"];
type Parser = ReturnType<InstanceType<typeof BeeAgentRunner>["createParser"]>["parser"];
export type BeeIterationResult = LinePrefixParser.inferOutput<Parser>;
export type BeeIterationResultPartial = LinePrefixParser.inferPartialOutput<Parser>;
export type BeeIterationToolResult = NonUndefined<BeeIterationResult, "tool_input" | "tool_name">;
6 changes: 3 additions & 3 deletions src/agents/bee/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ export class BeeAgentRunner {
);
}

return new BeeAgentRunner(input, options, memory);
return new this(input, options, memory);
}

static createParser(tools: AnyTool[]) {
protected createParser(tools: AnyTool[]) {
const parserRegex =
/Thought:.+\n(?:Final Answer:[\S\s]+|Function Name:.+\nFunction Input: \{.*\}\nFunction Caption:.+\nFunction Output:)?/;

Expand Down Expand Up @@ -251,7 +251,7 @@ export class BeeAgentRunner {
executor: async () => {
await emitter.emit("start", { meta });

const { parser, parserRegex } = BeeAgentRunner.createParser(this.input.tools);
const { parser, parserRegex } = this.createParser(this.input.tools);
const llmOutput = await this.input.llm
.generate(this.memory.messages.slice(), {
signal,
Expand Down

0 comments on commit e7b99a0

Please sign in to comment.