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

    attribute
    TypeBaseModel: type[BaseModel]
    attribute
    FILTERED_ARGS
    attribute
    TOOL_MESSAGE_BLOCK_TYPES

    Functions

    function
    ensure_config

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

    function
    patch_config

    Patch a config with new values.

    function
    run_in_executor

    Run a function in an executor.

    function
    set_config_context

    Set the child Runnable config + tracing context.

    function
    coro_with_context

    Await a coroutine with a context.

    function
    get_fields

    Return the field names of a Pydantic model.

    function
    is_basemodel_subclass

    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
    function
    is_pydantic_v1_subclass

    Check if the given class is Pydantic v1-like.

    function
    is_pydantic_v2_subclass

    Check if the given class is Pydantic v2-like.

    function
    create_schema_from_function

    Create a Pydantic schema from a function's signature.

    function
    get_all_basemodel_annotations

    Get all annotations from a Pydantic BaseModel and its parents.

    Classes

    class
    AsyncCallbackManager

    Async callback manager that handles callbacks from LangChain.

    class
    CallbackManager

    Callback manager for LangChain.

    class
    ToolCall

    Represents an AI's request to call a tool.

    class
    ToolMessage

    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.

    class
    ToolOutputMixin

    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.

    class
    RunnableConfig

    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"]}
    class
    RunnableSerializable

    Runnable that can be serialized to JSON.

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

    Type Aliases

    typeAlias
    Callbacks: list[BaseCallbackHandler] | BaseCallbackManager | None
    typeAlias
    ArgsSchema
    View source on GitHub