LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangChain
  • Universal
  • Hub
  • Node
  • Load
  • Serializable
  • Encoder Backed
  • File System
  • In Memory
LangChain Core
  • Agents
  • Caches
  • Base
  • Dispatch
  • Web
  • Manager
  • Promises
  • Chat History
  • Context
  • Base
  • Langsmith
  • Documents
  • Embeddings
  • Errors
  • Example Selectors
  • Indexing
  • Base
  • Chat Models
  • Llms
  • Profile
  • Load
  • Serializable
  • Memory
  • Messages
  • Tool
  • Output Parsers
  • Openai Functions
  • Openai Tools
  • Outputs
  • Prompt Values
  • Prompts
  • Retrievers
  • Document Compressors
  • Runnables
  • Graph
  • Singletons
  • Stores
  • Structured Query
  • Tools
  • Base
  • Console
  • Log Stream
  • Run Collector
  • Tracer Langchain
  • Stream
  • Async Caller
  • Chunk Array
  • Context
  • Env
  • Event Source Parse
  • Format
  • Function Calling
  • Hash
  • Json Patch
  • Json Schema
  • Math
  • Ssrf
  • Stream
  • Testing
  • Tiktoken
  • Types
  • Vectorstores
Text Splitters
MCP Adapters
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangChain
UniversalHubNodeLoadSerializableEncoder BackedFile SystemIn Memory
LangChain Core
AgentsCachesBaseDispatchWebManagerPromisesChat HistoryContextBaseLangsmithDocumentsEmbeddingsErrorsExample SelectorsIndexingBaseChat ModelsLlmsProfileLoadSerializableMemoryMessagesToolOutput ParsersOpenai FunctionsOpenai ToolsOutputsPrompt ValuesPromptsRetrieversDocument CompressorsRunnablesGraphSingletonsStoresStructured QueryToolsBaseConsoleLog StreamRun CollectorTracer LangchainStreamAsync CallerChunk ArrayContextEnvEvent Source ParseFormatFunction CallingHashJson PatchJson SchemaMathSsrfStreamTestingTiktokenTypesVectorstores
Text Splitters
MCP Adapters
Language
Theme
JavaScript@langchain/coreutilsfunction_calling
Moduleā—Since v1.0

utils/function_calling

Copy
import { ... } from "@langchain/core/utils/function_calling";

Functions

function
convertToOpenAIFunction→ FunctionDefinition

Formats a StructuredTool or RunnableToolLike instance into a format that is compatible with OpenAI function calling. If StructuredTool or RunnableToolLike has a zod schema, the output will be converted into a JSON schema, which is then used as the parameters for the OpenAI tool.

function
convertToOpenAITool→ ToolDefinition

Formats a StructuredTool or RunnableToolLike instance into a format that is compatible with OpenAI tool calling. If StructuredTool or RunnableToolLike has a zod schema, the output will be converted into a JSON schema, which is then used as the parameters for the OpenAI tool.

function
isLangChainTool→ tool is StructuredToolParams

Whether or not the tool is one of StructuredTool, RunnableTool or StructuredToolParams. It returns is StructuredToolParams since that is the most minimal interface of the three, while still containing the necessary properties to be passed to a LLM for tool calling.

function
isRunnableToolLike→ tool is RunnableToolLike<InteropZodType, unknown>

Confirm whether the inputted tool is an instance of RunnableToolLike.

function
isStructuredTool→ tool is StructuredToolInterface<ToolSchemaBase, any, any>

Confirm whether the inputted tool is an instance of StructuredToolInterface.

function
isStructuredToolParams→ tool is StructuredToolParams

Confirm whether or not the tool contains the necessary properties to be considered a StructuredToolParams.

View source on GitHub