diff --git a/langchain-core/src/tools/index.ts b/langchain-core/src/tools/index.ts index b58f673cd551..32ecf3ff41d4 100644 --- a/langchain-core/src/tools/index.ts +++ b/langchain-core/src/tools/index.ts @@ -457,8 +457,7 @@ export abstract class BaseToolkit { /** * Parameters for the tool function. - * @template {ZodObjectAny} RunInput The input schema for the tool. - * @template {any} RunOutput The output type for the tool. + * @template {ZodObjectAny | z.ZodString = ZodObjectAny} RunInput The input schema for the tool. Either any Zod object, or a Zod string. */ interface ToolWrapperParams< RunInput extends ZodObjectAny | z.ZodString = ZodObjectAny @@ -493,18 +492,17 @@ interface ToolWrapperParams< /** * Creates a new StructuredTool instance with the provided function, name, description, and schema. + * * @function - * @template {RunInput extends ZodObjectAny = ZodObjectAny} RunInput The input schema for the tool. This corresponds to the input type when the tool is invoked. - * @template {RunOutput = any} RunOutput The output type for the tool. This corresponds to the output type when the tool is invoked. - * @template {FuncInput extends z.infer | ToolCall = z.infer} FuncInput The input type for the function. + * @template {ZodObjectAny | z.ZodString = ZodObjectAny} T The input schema for the tool. Either any Zod object, or a Zod string. * - * @param {RunnableFunc | ToolCall, RunOutput>} func - The function to invoke when the tool is called. - * @param fields - An object containing the following properties: + * @param {RunnableFunc, ToolReturnType>} func - The function to invoke when the tool is called. + * @param {ToolWrapperParams} fields - An object containing the following properties: * @param {string} fields.name The name of the tool. * @param {string | undefined} fields.description The description of the tool. Defaults to either the description on the Zod schema, or `${fields.name} tool`. - * @param {z.ZodObject} fields.schema The Zod schema defining the input for the tool. + * @param {ZodObjectAny | z.ZodString | undefined} fields.schema The Zod schema defining the input for the tool. If undefined, it will default to a Zod string schema. * - * @returns {DynamicStructuredTool} A new StructuredTool instance. + * @returns {DynamicStructuredTool} A new StructuredTool instance. */ export function tool( func: RunnableFunc, ToolReturnType>, diff --git a/langchain-core/src/tools/tests/tools.test.ts b/langchain-core/src/tools/tests/tools.test.ts index 0dcb5a8b8684..bf577a4a1dc9 100644 --- a/langchain-core/src/tools/tests/tools.test.ts +++ b/langchain-core/src/tools/tests/tools.test.ts @@ -101,7 +101,7 @@ test("Returns tool message if responseFormat is content_and_artifact and returns }); test("Tool can accept single string input", async () => { - const stringTool = tool( + const stringTool = tool( (input: string): string => { return `${input}a`; },