LangGraph.js API Reference
    Preparing search index...

    Type Alias ToolCallsFromTools<T>

    ToolCallsFromTools: T extends readonly [infer First, ...(infer Rest)]
        ? ToolCallFromTool<First> | ToolCallsFromTools<Rest>
        : never

    Infer a union of tool call types from an array of tools. Works with tools created via tool() from @langchain/core/tools.

    Type Parameters

    • T extends readonly unknown[]

      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>;