Skip to content

The agent engineering platform.

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

Bagatur32f8f3997496
diff --git a/libs/core/langchain_core/tools.py b/libs/core/langchain_core/tools.py
index 86cedd51aa..cf168e784b 100644
--- a/libs/core/langchain_core/tools.py
+++ b/libs/core/langchain_core/tools.py
@@ -827,6 +827,8 @@ class StructuredTool(BaseTool):
raise ValueError("Function and/or coroutine must be provided")
name = name or source_function.__name__
description_ = description or source_function.__doc__
+ if description_ is None and args_schema:
+ description_ = args_schema.__doc__
if description_ is None:
raise ValueError(
"Function must have a docstring if description not provided."
diff --git a/libs/core/tests/unit_tests/test_tools.py b/libs/core/tests/unit_tests/test_tools.py
index cc624f4cfd..5e7b05dbff 100644
--- a/libs/core/tests/unit_tests/test_tools.py
+++ b/libs/core/tests/unit_tests/test_tools.py
@@ -44,6 +44,8 @@ def test_unnamed_decorator() -> None:
class _MockSchema(BaseModel):
+ """Return the arguments directly."""
+
arg1: int
arg2: bool
arg3: Optional[dict] = None
@@ -133,7 +135,6 @@ def test_decorator_with_specified_schema() -> None:
@tool(args_schema=_MockSchema)
def tool_func(arg1: int, arg2: bool, arg3: Optional[dict] = None) -> str:
- """Return the arguments directly."""
return f"{arg1} {arg2} {arg3}"
assert isinstance(tool_func, BaseTool)