Skip to content

Commit f427716

Browse files
feat: allow defining LangChain-style tools with JSONSchema (#7973)
1 parent 6f43182 commit f427716

File tree

33 files changed

+869
-474
lines changed

33 files changed

+869
-474
lines changed

docs/core_docs/scripts/code-block-loader.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const SYMBOL_EDGE_CASE_MAP = {
3131
originalSource: "@langchain/core/messages/tool",
3232
originalSymbolName: null,
3333
},
34-
zodToGeminiParameters: {
34+
schemaToGeminiParameters: {
3535
sources: ["@langchain/google-vertexai/utils"],
3636
originalSource: "@langchain/google-common",
3737
originalSymbolName: null,

examples/src/models/chat/integration_googlevertexai-tools.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ChatVertexAI } from "@langchain/google-vertexai";
22
import { type GeminiTool } from "@langchain/google-vertexai/types";
3-
import { zodToGeminiParameters } from "@langchain/google-vertexai/utils";
3+
import { schemaToGeminiParameters } from "@langchain/google-vertexai/utils";
44
import { z } from "zod";
55
// Or, if using the web entrypoint:
66
// import { ChatVertexAI } from "@langchain/google-vertexai-web";
@@ -18,7 +18,7 @@ const geminiCalculatorTool: GeminiTool = {
1818
{
1919
name: "calculator",
2020
description: "A simple calculator tool",
21-
parameters: zodToGeminiParameters(calculatorSchema),
21+
parameters: schemaToGeminiParameters(calculatorSchema),
2222
},
2323
],
2424
};

examples/src/models/chat/ollama_functions/extraction.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ const model = new OllamaFunctions({
3232
{
3333
name: "information_extraction",
3434
description: "Extracts the relevant information from the passage.",
35-
parameters: {
36-
type: "object",
37-
properties: zodToJsonSchema(schema),
38-
},
35+
parameters: zodToJsonSchema(schema),
3936
},
4037
],
4138
function_call: {

langchain-core/src/language_models/base.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { AsyncCaller, AsyncCallerParams } from "../utils/async_caller.js";
1919
import { encodingForModel } from "../utils/tiktoken.js";
2020
import { Runnable, type RunnableInterface } from "../runnables/base.js";
2121
import { RunnableConfig } from "../runnables/config.js";
22+
import { JSONSchema } from "../utils/json_schema.js";
2223

2324
// https://www.npmjs.com/package/js-tiktoken
2425

@@ -226,7 +227,7 @@ export interface FunctionDefinition {
226227
* To describe a function that accepts no parameters, provide the value
227228
* `{"type": "object", "properties": {}}`.
228229
*/
229-
parameters: Record<string, unknown>;
230+
parameters: Record<string, unknown> | JSONSchema;
230231

231232
/**
232233
* A description of what the function does, used by the model to choose when and

0 commit comments

Comments
 (0)