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-coretoolssimpleToolfrom_function
    Method●Since v0.2

    from_function

    Initialize tool from a function.

    Copy
    from_function(
      cls,
      func: Callable | None,
      name: str,
      description: str,
      return_direct: bool = False,
      args_schema: ArgsSchema | None = None,
      coroutine: Callable[..., Awaitable[Any]] | None = None,
      **kwargs: Any = {}
    ) -> Tool

    Parameters

    NameTypeDescription
    func*Callable | None

    The function to create the tool from.

    name*str

    The name of the tool.

    description*str

    The description of the tool.

    return_directbool
    Default:False

    Whether to return the output directly.

    args_schemaArgsSchema | None
    Default:None

    The schema of the tool's input arguments.

    coroutineCallable[..., Awaitable[Any]] | None
    Default:None

    The asynchronous version of the function.

    **kwargsAny
    Default:{}

    Additional arguments to pass to the tool.

    View source on GitHub