A tuple/array of tools
import { tool } from "@langchain/core/tools";
import { z } from "zod";
const getWeather = tool(
async ({ location }) => `Weather in ${location}`,
{ name: "get_weather", schema: z.object({ location: z.string() }) }
);
const search = tool(
async ({ query }) => `Results for ${query}`,
{ name: "search", schema: z.object({ query: z.string() }) }
);
const tools = [getWeather, search] as const;
// Infer union:
// | { name: "get_weather"; args: { location: string }; id?: string; type?: "tool_call" }
// | { name: "search"; args: { query: string }; id?: string; type?: "tool_call" }
type MyToolCalls = ToolCallsFromTools<typeof tools>;
Infer a union of tool call types from an array of tools. Works with tools created via
tool()from@langchain/core/tools.