MCPcopy
hub / github.com/langchain-ai/langchain / from_function

Method from_function

libs/core/langchain_core/tools.py:676–699  ·  view source on GitHub ↗

Initialize tool from a function.

(
        cls,
        func: Optional[Callable],
        name: str,  # We keep these required to support backwards compatibility
        description: str,
        return_direct: bool = False,
        args_schema: Optional[Type[BaseModel]] = None,
        coroutine: Optional[
            Callable[..., Awaitable[Any]]
        ] = None,  # This is last for compatibility, but should be after func
        **kwargs: Any,
    )

Source from the content-addressed store, hash-verified

674
675 @classmethod
676 def from_function(
677 cls,
678 func: Optional[Callable],
679 name: str, # We keep these required to support backwards compatibility
680 description: str,
681 return_direct: bool = False,
682 args_schema: Optional[Type[BaseModel]] = None,
683 coroutine: Optional[
684 Callable[..., Awaitable[Any]]
685 ] = None, # This is last for compatibility, but should be after func
686 **kwargs: Any,
687 ) -> Tool:
688 """Initialize tool from a function."""
689 if func is None and coroutine is None:
690 raise ValueError("Function and/or coroutine must be provided")
691 return cls(
692 name=name,
693 func=func,
694 coroutine=coroutine,
695 description=description,
696 return_direct=return_direct,
697 args_schema=args_schema,
698 **kwargs,
699 )
700
701
702class StructuredTool(BaseTool):

Calls

no outgoing calls