Skip to content

Commit

Permalink
feat(tools): propagate run context to the CustomTool
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas2D committed Oct 10, 2024
1 parent 2f0ec77 commit b3cc10a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/tools/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export abstract class Tool<
protected abstract _run(
arg: ToolInput<this>,
options: TRunOptions | undefined,
run: GetRunContext<this>,
run: GetRunContext<typeof this>,
): Promise<TOutput>;

async getInputJsonSchema() {
Expand Down Expand Up @@ -400,7 +400,11 @@ export class DynamicTool<
name: string;
description: string;
inputSchema: TInputSchema;
handler: (input: TInput, options?: TRunOptions) => Promise<TOutput>;
handler: (
input: TInput,
options: TRunOptions | undefined,
run: GetRunContext<DynamicTool<TOutput, TInputSchema, TOptions, TRunOptions, TInput>>,
) => Promise<TOutput>;
options?: TOptions;
}) {
validate(
Expand All @@ -420,8 +424,12 @@ export class DynamicTool<
this.handler = fields.handler;
}

protected _run(arg: TInput, options?: TRunOptions): Promise<TOutput> {
return this.handler(arg, options);
protected _run(
arg: TInput,
options: TRunOptions | undefined,
run: GetRunContext<DynamicTool<TOutput, TInputSchema, TOptions, TRunOptions, TInput>>,
): Promise<TOutput> {
return this.handler(arg, options, run);
}

createSnapshot() {
Expand Down

0 comments on commit b3cc10a

Please sign in to comment.