from_function() — langchain Function Reference
Architecture documentation for the from_function() function in simple.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD a4750a39_8afe_6ac4_ad0b_49c77bf6dcda["from_function()"] 4ddde15c_138a_6971_91c4_325c8c3034dd["Tool"] a4750a39_8afe_6ac4_ad0b_49c77bf6dcda -->|defined in| 4ddde15c_138a_6971_91c4_325c8c3034dd style a4750a39_8afe_6ac4_ad0b_49c77bf6dcda fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/tools/simple.py lines 165–204
def from_function(
cls,
func: Callable | None,
name: str, # We keep these required to support backwards compatibility
description: str,
return_direct: bool = False, # noqa: FBT001,FBT002
args_schema: ArgsSchema | None = None,
coroutine: Callable[..., Awaitable[Any]]
| None = None, # This is last for compatibility, but should be after func
**kwargs: Any,
) -> Tool:
"""Initialize tool from a function.
Args:
func: The function to create the tool from.
name: The name of the tool.
description: The description of the tool.
return_direct: Whether to return the output directly.
args_schema: The schema of the tool's input arguments.
coroutine: The asynchronous version of the function.
**kwargs: Additional arguments to pass to the tool.
Returns:
The tool.
Raises:
ValueError: If the function is not provided.
"""
if func is None and coroutine is None:
msg = "Function and/or coroutine must be provided"
raise ValueError(msg)
return cls(
name=name,
func=func,
coroutine=coroutine,
description=description,
return_direct=return_direct,
args_schema=args_schema,
**kwargs,
)
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does from_function() do?
from_function() is a function in the langchain codebase, defined in libs/core/langchain_core/tools/simple.py.
Where is from_function() defined?
from_function() is defined in libs/core/langchain_core/tools/simple.py at line 165.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free