Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core[minor]: Allow for simple tool schema to be passed to bindTools #8

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion langchain-core/src/language_models/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
} from "../callbacks/manager.js";
import type { RunnableConfig } from "../runnables/config.js";
import type { BaseCache } from "../caches/base.js";
import { StructuredToolInterface } from "../tools/index.js";
import { StructuredToolInterface, ToolSchema } from "../tools/index.js";
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

category Readability and Maintainability

The import statement for ToolSchema is added but not used anywhere in the file. Unused imports can clutter the code and make it harder to read and maintain. Please remove the unused import statement for ToolSchema to keep the code clean and maintainable.

Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.

import {
Runnable,
RunnableLambda,
Expand Down Expand Up @@ -184,6 +184,7 @@ export abstract class BaseChatModel<
| Record<string, unknown>
| ToolDefinition
| RunnableToolLike
| ToolSchema
)[],
kwargs?: Partial<CallOptions>
): Runnable<BaseLanguageModelInput, OutputMessageType, CallOptions>;
Expand Down
15 changes: 15 additions & 0 deletions langchain-core/src/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ export interface ToolParams extends BaseLangChainParams {
responseFormat?: ResponseFormat;
}

export interface ToolSchema {
/**
* The name of the tool to pass to the model.
*/
name: string;
/**
* An optional description of the tool to pass to the model.
*/
description?: string;
/**
* A Zod schema representing the parameters of the tool.
*/
schema: ZodObjectAny;
}
Comment on lines +50 to +63
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

category Functionality

The new ToolSchema interface has been added, which is a good addition for allowing more concise schema definitions. However, to ensure proper functionality and prevent misuse, we should add comments explaining its intended use and limitations. Specifically, we should note that this is not intended to be used in Agents or similar contexts, as it has no function attached. Consider adding a comment above the ToolSchema interface to clarify its purpose and usage constraints.

Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.


export interface StructuredToolInterface<T extends ZodObjectAny = ZodObjectAny>
extends RunnableInterface<
(z.output<T> extends string ? string : never) | z.input<T> | ToolCall,
Expand Down