@ -332,9 +332,8 @@ def test_structured_tool_from_function_docstring() -> None:
" required " : [ " bar " , " baz " ] ,
}
prefix = " foo(bar: int, baz: str) -> str - "
assert foo . __doc__ is not None
assert structured_tool . description == prefix + textwrap. dedent ( foo . __doc__ . strip ( ) )
assert structured_tool . description == textwrap. dedent ( foo . __doc__ . strip ( ) )
def test_structured_tool_from_function_docstring_complex_args ( ) - > None :
@ -365,9 +364,8 @@ def test_structured_tool_from_function_docstring_complex_args() -> None:
" required " : [ " bar " , " baz " ] ,
}
prefix = " foo(bar: int, baz: List[str]) -> str - "
assert foo . __doc__ is not None
assert structured_tool . description == prefix + textwrap. dedent ( foo . __doc__ ) . strip ( )
assert structured_tool . description == textwrap. dedent ( foo . __doc__ ) . strip ( )
def test_structured_tool_lambda_multi_args_schema ( ) - > None :
@ -700,9 +698,8 @@ def test_structured_tool_from_function() -> None:
" required " : [ " bar " , " baz " ] ,
}
prefix = " foo(bar: int, baz: str) -> str - "
assert foo . __doc__ is not None
assert structured_tool . description == prefix + textwrap. dedent ( foo . __doc__ . strip ( ) )
assert structured_tool . description == textwrap. dedent ( foo . __doc__ . strip ( ) )
def test_validation_error_handling_bool ( ) - > None :
@ -906,3 +903,15 @@ async def test_async_tool_pass_context() -> None:
assert (
await foo . ainvoke ( { " bar " : " baz " } , { " configurable " : { " foo " : " not-bar " } } ) == " baz " # type: ignore
)
def test_tool_description ( ) - > None :
def foo ( bar : str ) - > str :
""" The foo. """
return bar
foo1 = tool ( foo )
assert foo1 . description == " The foo. " # type: ignore
foo2 = StructuredTool . from_function ( foo )
assert foo2 . description == " The foo. "