Skip to content

Commit

Permalink
RunnableToolLike
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Jul 10, 2024
1 parent 5c7629a commit af5b8ad
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
35 changes: 34 additions & 1 deletion langchain-core/src/runnables/tool.ts
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
// todo implement
import { ZodAny } from "../types/zod.js";
import { RunnableLambda } from "./base.js";
import { RunnableConfig } from "./config.js";

export interface RunnableToolLikeFields<RunInput, RunOutput> {
name?: string;

description?: string;

schema: RunInput;

func:
| ((input: RunInput, config?: RunnableConfig) => RunOutput)
| ((input: RunInput, config?: RunnableConfig) => Promise<RunOutput>);
}

export class RunnableToolLike<
RunInput extends ZodAny,
RunOutput = string
> extends RunnableLambda<RunInput, RunOutput> {
description?: string;

schema: RunInput;

constructor(fields: RunnableToolLikeFields<RunInput, RunOutput>) {
super({
func: fields.func,
});

this.name = fields.name;
this.description = fields.description;
this.schema = fields.schema;
}
}
4 changes: 1 addition & 3 deletions langchain-core/src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import {
} from "./language_models/base.js";
import { ensureConfig, type RunnableConfig } from "./runnables/config.js";
import type { RunnableFunc, RunnableInterface } from "./runnables/base.js";

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type ZodAny = z.ZodObject<any, any, any, any>;
import { ZodAny } from "./types/zod.js";

/**
* Parameters for the Tool classes.
Expand Down
4 changes: 4 additions & 0 deletions langchain-core/src/types/zod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import type { z } from "zod";

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type ZodAny = z.ZodObject<any, any, any, any>;

0 comments on commit af5b8ad

Please sign in to comment.