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/coretools
Module●Since v1.0

tools

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

Used in Docs

  • Anthropic integration
  • OpenAI integration

Functions

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.

function
tool→ DynamicTool<ToolOutputT>

Creates a new StructuredTool instance with the provided function, name, description, and schema.

Schema can be provided as Zod or JSON schema, and both will be validated.

Classes

class
BaseToolkit

Abstract base class for toolkits in LangChain. Toolkits are collections of tools that agents can use. Subclasses must implement the tools property to provide the specific tools for the toolkit.

class
DynamicStructuredTool

A tool that can be created dynamically from a function, name, and description, designed to work with structured data. It extends the StructuredTool class and overrides the _call method to execute the provided function when the tool is called.

Schema can be passed as Zod or JSON schema. The tool will not validate input if JSON schema is passed.

class
DynamicTool

A tool that can be created dynamically from a function, name, and description.

class
StructuredTool

Base class for Tools that accept input of any shape defined by a Zod schema.

class
Tool

Base class for Tools that accept input as a string.

class
ToolInputParsingException

Custom error class used to handle exceptions related to tool input parsing. It extends the built-in Error class and adds an optional output property that can hold the output that caused the exception.

Interfaces

interface
BaseDynamicToolInput

Base interface for the input parameters of the DynamicTool and DynamicStructuredTool classes.

interface
DynamicStructuredToolInput

Interface for the input parameters of the DynamicStructuredTool class.

interface
DynamicToolInput

Interface for the input parameters of the DynamicTool class.

interface
StructuredToolInterface

Interface that defines the shape of a LangChain structured tool.

A structured tool is a tool that uses a schema to define the structure of the arguments that the LLM generates as part of its ToolCall.

interface
StructuredToolParams

Schema for defining tools.

interface
ToolInterface

A special interface for tools that accept a string input, usually defined with the Tool class.

interface
ToolParams

Parameters for the Tool classes.

Type Aliases

typeAlias
ClientTool: StructuredToolInterface | DynamicTool | RunnableToolLike
typeAlias
ContentAndArtifact: [MessageContent, any]
typeAlias
ResponseFormat: "content" | "content_and_artifact" | string
typeAlias
ServerTool: Record<string, unknown>
typeAlias
StructuredToolCallInput: ToolInputSchemaOutputType<SchemaT> extends string ? string : never | SchemaInputT | ToolCall

Defines the type that will be passed into a tool handler function as a result of a tool call.

typeAlias
ToolReturnType: TOutput extends DirectToolOutput ? TOutput : TConfig extends __type ? ToolMessage : TConfig extends __type ? TOutput : TConfig extends __type ? TOutput | ToolMessage : TInput extends ToolCall ? ToolMessage : TOutput

Conditional type that determines the return type of the StructuredTool.invoke method.

  • If the input is a ToolCall, it returns a ToolMessage
  • If the config is a runnable config and contains a toolCall property, it returns a ToolMessage
  • Otherwise, it returns the original output type
typeAlias
ToolRunnableConfig: RunnableConfig<ConfigurableFieldType> & __type
typeAlias
ToolRuntime: RunnableConfig & __type

Runtime context automatically injected into tools.

When a tool function has a parameter named tool_runtime with type hint ToolRuntime, the tool execution system will automatically inject an instance containing:

  • state: The current graph state
  • toolCallId: The ID of the current tool call
  • config: RunnableConfig for the current execution
  • context: Runtime context
  • store: BaseStore instance for persistent storage
  • writer: Stream writer for streaming output

No Annotated wrapper is needed - just use runtime: ToolRuntime as a parameter.

typeAlias
ToolSchemaBase: z3.ZodTypeAny | JsonSchema7Type

Base type that establishes the types of input schemas that can be used for LangChain tool definitions.

View source on GitHub