Skip to content

Commit

Permalink
drop default description
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Jul 11, 2024
1 parent 9aa961c commit a226063
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
20 changes: 4 additions & 16 deletions langchain-core/src/runnables/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
type TraceableFunction,
isTraceableFunction,
} from "langsmith/singletons/traceable";
import { zodToJsonSchema } from "zod-to-json-schema";
import type { RunnableInterface, RunnableBatchOptions } from "./types.js";
import { CallbackManagerForChainRun } from "../callbacks/manager.js";
import {
Expand Down Expand Up @@ -1088,7 +1087,7 @@ export abstract class Runnable<
*
* @param fields
* @param {string | undefined} [fields.name] The name of the tool. If not provided, it will default to the name of the runnable.
* @param {string | undefined} [fields.description] The description of the tool. If not provided, it will default to `Takes {schema}` where `schema` is a JSON string representation of the input schema.
* @param {string | undefined} [fields.description] The description of the tool.
* @param {z.ZodType<T>} [fields.schema] The Zod schema for the input of the tool. Infers the Zod type from the input type of the runnable.
* @returns {RunnableToolLike<z.ZodType<T>, RunOutput>} An instance of `RunnableToolLike` which is a runnable that can be used as a tool.
*/
Expand Down Expand Up @@ -2842,15 +2841,6 @@ export class RunnableToolLike<
}
}

/**
* Generate a placeholder description of a runnable
*/
const _getDescriptionFromRunnable = <RunInput = unknown>(
schema: RunInput
): string => {
return `Takes ${JSON.stringify(schema, null, 2)}`;
};

/**
* Given a runnable and a Zod schema, convert the runnable to a tool.
*
Expand All @@ -2860,7 +2850,7 @@ const _getDescriptionFromRunnable = <RunInput = unknown>(
* @param {Runnable<RunInput, RunOutput>} runnable The runnable to convert to a tool.
* @param fields
* @param {string | undefined} [fields.name] The name of the tool. If not provided, it will default to the name of the runnable.
* @param {string | undefined} [fields.description] The description of the tool. If not provided, it will default to `Takes {schema}` where `schema` is a JSON string representation of the input schema.
* @param {string | undefined} [fields.description] The description of the tool.
* @param {z.ZodType<RunInput>} [fields.schema] The Zod schema for the input of the tool. Infers the Zod type from the input type of the runnable.
* @returns {RunnableToolLike<z.ZodType<RunInput>, RunOutput>} An instance of `RunnableToolLike` which is a runnable that can be used as a tool.
*/
Expand All @@ -2872,15 +2862,13 @@ export function convertRunnableToTool<RunInput, RunOutput>(
schema: z.ZodType<RunInput>;
}
): RunnableToolLike<z.ZodType<RunInput>, RunOutput> {
const description =
fields.description ??
_getDescriptionFromRunnable(zodToJsonSchema(fields.schema));
const { description, schema } = fields;
const name = fields.name ?? runnable.getName();

return new RunnableToolLike<z.ZodType<RunInput>, RunOutput>({
name,
description,
schema: fields.schema,
schema,
bound: runnable,
});
}
3 changes: 0 additions & 3 deletions langchain-core/src/runnables/tests/runnable_tools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ test("Runnable asTool works", async () => {

expect(tool).toBeInstanceOf(RunnableToolLike);
expect(tool.schema).toBe(schema);
expect(tool.description).toBe(
`Takes ${JSON.stringify(zodToJsonSchema(schema), null, 2)}`
);
expect(tool.name).toBe(runnable.getName());
});

Expand Down

0 comments on commit a226063

Please sign in to comment.