LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
    • Overview
    • Caches
    • Callbacks
    • Documents
    • Document loaders
    • Embeddings
    • Exceptions
    • Language models
    • Serialization
    • Output parsers
    • Prompts
    • Rate limiters
    • Retrievers
    • Runnables
    • Utilities
    • Vector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    OverviewCachesCallbacksDocumentsDocument loadersEmbeddingsExceptionsLanguage modelsSerializationOutput parsersPromptsRate limitersRetrieversRunnablesUtilitiesVector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-coretools
    Moduleā—Since v0.1

    tools

    Tools are classes that an Agent uses to interact with the world.

    Each tool has a description. Agent uses the description to choose the righ tool for the job.

    Attributes

    attribute
    FILTERED_ARGS
    attribute
    ToolsRenderer: Callable[[list[BaseTool]], str]

    Functions

    function
    import_attr

    Import an attribute from a module located in a package.

    This utility function is used in custom __getattr__ methods within __init__.py files to dynamically import attributes.

    function
    create_schema_from_function

    Create a Pydantic schema from a function's signature.

    function
    convert_runnable_to_tool

    Convert a Runnable into a BaseTool.

    function
    tool

    Convert Python functions and Runnables to LangChain tools.

    Can be used as a decorator with or without arguments to create tools from functions.

    Functions can have any signature - the tool will automatically infer input schemas unless disabled.

    Requirements
    • Functions should have type hints for proper schema inference.
    • Functions may accept multiple arguments and return types are flexible; outputs will be serialized if needed.
    • When using with Runnable, a string name must be provided.
    function
    render_text_description

    Render the tool name and description in plain text.

    function
    render_text_description_and_args

    Render the tool name, description, and args in plain text.

    function
    create_retriever_tool

    Create a tool to do retrieval of documents.

    Classes

    class
    BaseTool

    Base class for all LangChain tools.

    This abstract class defines the interface that all LangChain tools must implement.

    Tools are components that can be called by agents to perform specific actions.

    class
    BaseToolkit

    Base class for toolkits containing related tools.

    A toolkit is a collection of related tools that can be used together to accomplish a specific task or work with a particular system.

    class
    InjectedToolArg

    Annotation for tool arguments that are injected at runtime.

    Tool arguments annotated with this class are not included in the tool schema sent to language models and are instead injected during execution.

    class
    InjectedToolCallId

    Annotation for injecting the tool call ID.

    This annotation is used to mark a tool parameter that should receive the tool call ID at runtime.

    from typing import Annotated
    from langchain_core.messages import ToolMessage
    from langchain_core.tools import tool, InjectedToolCallId
    
    @tool
    def foo(
        x: int, tool_call_id: Annotated[str, InjectedToolCallId]
    ) -> ToolMessage:
        """Return x."""
        return ToolMessage(
            str(x),
            artifact=x,
            name="foo",
            tool_call_id=tool_call_id
        )
    class
    SchemaAnnotationError

    Raised when args_schema is missing or has an incorrect type annotation.

    class
    ToolException

    Exception thrown when a tool execution error occurs.

    This exception allows tools to signal errors without stopping the agent.

    The error is handled according to the tool's handle_tool_error setting, and the result is returned as an observation to the agent.

    class
    RetrieverInput

    Input to the retriever.

    class
    Tool

    Tool that takes in function or coroutine directly.

    class
    StructuredTool

    Tool that can operate on any number of inputs.

    Type Aliases

    typeAlias
    ArgsSchema

    Modules

    module
    simple

    Tool that takes in function or coroutine directly.

    module
    convert

    Convert functions and runnables to tools.

    module
    retriever

    Retriever tool.

    module
    structured

    Structured tool.

    module
    render

    Utilities to render tools.

    module
    base

    Base classes and utilities for LangChain tools.

    View source on GitHub