@@ -129,10 +129,10 @@ def from_function(
129129 coroutine : Callable [..., Awaitable [Any ]] | None = None ,
130130 name : str | None = None ,
131131 description : str | None = None ,
132- return_direct : bool = False , # noqa: FBT001,FBT002
133- args_schema : ArgsSchema | None = None ,
134- infer_schema : bool = True , # noqa: FBT001,FBT002
135132 * ,
133+ return_direct : bool = False ,
134+ args_schema : ArgsSchema | None = None ,
135+ infer_schema : bool = True ,
136136 response_format : Literal ["content" , "content_and_artifact" ] = "content" ,
137137 parse_docstring : bool = False ,
138138 error_on_invalid_docstring : bool = False ,
@@ -189,14 +189,14 @@ def add(a: int, b: int) -> int:
189189 raise ValueError (msg )
190190 name = name or source_function .__name__
191191 if args_schema is None and infer_schema :
192- # schema name is appended within function
193192 args_schema = create_schema_from_function (
194193 name ,
195194 source_function ,
196195 parse_docstring = parse_docstring ,
197196 error_on_invalid_docstring = error_on_invalid_docstring ,
198197 filter_args = _filter_schema_args (source_function ),
199198 )
199+
200200 description_ = description
201201 if description is None and not parse_docstring :
202202 description_ = source_function .__doc__ or None
@@ -213,20 +213,20 @@ def add(a: int, b: int) -> int:
213213 elif isinstance (args_schema , dict ):
214214 description_ = args_schema .get ("description" )
215215 else :
216- msg = (
217- "Invalid args_schema: expected BaseModel or dict, "
218- f"got { args_schema } "
219- )
216+ msg = f"""Invalid args_schema: expected BaseModel or
217+ dict, got { args_schema } """
220218 raise TypeError (msg )
219+
221220 if description_ is None :
222- msg = "Function must have a docstring if description not provided."
223- raise ValueError (msg )
221+ if is_basemodel_subclass (source_function ):
222+ description_ = ""
223+ else :
224+ msg = "Function must have a docstring if description not provided."
225+ raise ValueError (msg )
226+
224227 if description is None :
225- # Only apply if using the function's docstring
226228 description_ = textwrap .dedent (description_ ).strip ()
227229
228- # Description example:
229- # search_api(query: str) - Searches the API for the query.
230230 description_ = f"{ description_ .strip ()} "
231231 return cls (
232232 name = name ,
0 commit comments