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-coretoolsbase
    Module●Since v0.2

    base

    Base classes and utilities for LangChain tools.

    Attributes

    Functions

    Classes

    Type Aliases

    View source on GitHub
    attribute
    TypeBaseModel: type[BaseModel]
    attribute
    FILTERED_ARGS
    attribute
    TOOL_MESSAGE_BLOCK_TYPES
    function
    ensure_config
    function
    patch_config
    function
    run_in_executor
    function
    set_config_context
    function
    coro_with_context
    function
    get_fields
    function
    is_basemodel_subclass
    function
    is_pydantic_v1_subclass
    function
    is_pydantic_v2_subclass
    function
    create_schema_from_function
    function
    get_all_basemodel_annotations
    class
    AsyncCallbackManager
    class
    CallbackManager
    class
    ToolCall
    class
    ToolMessage
    class
    ToolOutputMixin
    class
    RunnableConfig
    class
    RunnableSerializable
    class
    SchemaAnnotationError
    class
    ToolException
    class
    BaseTool
    class
    InjectedToolArg
    class
    InjectedToolCallId
    class
    BaseToolkit
    typeAlias
    Callbacks: list[BaseCallbackHandler] | BaseCallbackManager | None
    typeAlias
    ArgsSchema

    Ensure that a config is a dict with all keys present.

    Patch a config with new values.

    Run a function in an executor.

    Set the child Runnable config + tracing context.

    Await a coroutine with a context.

    Return the field names of a Pydantic model.

    Check if the given class is a subclass of Pydantic BaseModel.

    Check if the given class is a subclass of any of the following:

    • pydantic.BaseModel in Pydantic 2.x
    • pydantic.v1.BaseModel in Pydantic 2.x

    Check if the given class is Pydantic v1-like.

    Check if the given class is Pydantic v2-like.

    Create a Pydantic schema from a function's signature.

    Get all annotations from a Pydantic BaseModel and its parents.

    Async callback manager that handles callbacks from LangChain.

    Callback manager for LangChain.

    Represents an AI's request to call a tool.

    Message for passing the result of executing a tool back to a model.

    ToolMessage objects contain the result of a tool invocation. Typically, the result is encoded inside the content field.

    tool_call_id is used to associate the tool call request with the tool call response. Useful in situations where a chat model is able to request multiple tool calls in parallel.

    Mixin for objects that tools can return directly.

    If a custom BaseTool is invoked with a ToolCall and the output of custom code is not an instance of ToolOutputMixin, the output will automatically be coerced to a string and wrapped in a ToolMessage.

    Runnable that can be serialized to JSON.

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

    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.

    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.

    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.

    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.

    Configuration for a Runnable.

    Note

    Custom values

    The TypedDict has total=False set intentionally to:

    • Allow partial configs to be created and merged together via merge_configs
    • Support config propagation from parent to child runnables via var_child_runnable_config (a ContextVar that automatically passes config down the call stack without explicit parameter passing), where configs are merged rather than replaced
    Example
    # Parent sets tags
    chain.invoke(input, config={"tags": ["parent"]})
    # Child automatically inherits and can add:
    # ensure_config({"tags": ["child"]}) -> {"tags": ["parent", "child"]}

    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
        )