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,
)
| 197 | |
| 198 | @classmethod |
| 199 | def from_function( |
| 200 | cls, |
| 201 | func: Optional[Callable], |
| 202 | name: str, # We keep these required to support backwards compatibility |
| 203 | description: str, |
| 204 | return_direct: bool = False, |
| 205 | args_schema: Optional[Type[BaseModel]] = None, |
| 206 | coroutine: Optional[ |
| 207 | Callable[..., Awaitable[Any]] |
| 208 | ] = None, # This is last for compatibility, but should be after func |
| 209 | **kwargs: Any, |
| 210 | ) -> Tool: |
| 211 | """Initialize tool from a function.""" |
| 212 | if func is None and coroutine is None: |
| 213 | raise ValueError("Function and/or coroutine must be provided") |
| 214 | return cls( |
| 215 | name=name, |
| 216 | func=func, |
| 217 | coroutine=coroutine, |
| 218 | description=description, |
| 219 | return_direct=return_direct, |
| 220 | args_schema=args_schema, |
| 221 | **kwargs, |
| 222 | ) |
| 223 | |
| 224 | |
| 225 | class StructuredTool(BaseTool): |