core[patch]: use args_schema doc for tool description (#23503)

This commit is contained in:
Bagatur 2024-06-25 15:26:35 -07:00 committed by GitHub
parent 6f7fe82830
commit 32f8f39974
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 1 deletions

View File

@ -827,6 +827,8 @@ class StructuredTool(BaseTool):
raise ValueError("Function and/or coroutine must be provided") raise ValueError("Function and/or coroutine must be provided")
name = name or source_function.__name__ name = name or source_function.__name__
description_ = description or source_function.__doc__ description_ = description or source_function.__doc__
if description_ is None and args_schema:
description_ = args_schema.__doc__
if description_ is None: if description_ is None:
raise ValueError( raise ValueError(
"Function must have a docstring if description not provided." "Function must have a docstring if description not provided."

View File

@ -44,6 +44,8 @@ def test_unnamed_decorator() -> None:
class _MockSchema(BaseModel): class _MockSchema(BaseModel):
"""Return the arguments directly."""
arg1: int arg1: int
arg2: bool arg2: bool
arg3: Optional[dict] = None arg3: Optional[dict] = None
@ -133,7 +135,6 @@ def test_decorator_with_specified_schema() -> None:
@tool(args_schema=_MockSchema) @tool(args_schema=_MockSchema)
def tool_func(arg1: int, arg2: bool, arg3: Optional[dict] = None) -> str: def tool_func(arg1: int, arg2: bool, arg3: Optional[dict] = None) -> str:
"""Return the arguments directly."""
return f"{arg1} {arg2} {arg3}" return f"{arg1} {arg2} {arg3}"
assert isinstance(tool_func, BaseTool) assert isinstance(tool_func, BaseTool)