From f9976b9630698814a9324d4a2f5a238369830005 Mon Sep 17 00:00:00 2001 From: arnob-sengupta <74873878+arnob-sengupta@users.noreply.github.com> Date: Wed, 24 Jan 2024 16:56:58 -0800 Subject: [PATCH] core[patch]: consolidate conditional in BaseTool (#16530) - **Description:** Refactor contradictory conditional to single line - **Issue:** #16528 --- libs/core/langchain_core/tools.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/libs/core/langchain_core/tools.py b/libs/core/langchain_core/tools.py index a536da4c79..10cc95cdeb 100644 --- a/libs/core/langchain_core/tools.py +++ b/libs/core/langchain_core/tools.py @@ -111,25 +111,24 @@ class BaseTool(RunnableSerializable[Union[str, Dict], Any]): args_schema_type = cls.__annotations__.get("args_schema", None) - if args_schema_type is not None: - if args_schema_type is None or args_schema_type == BaseModel: - # Throw errors for common mis-annotations. - # TODO: Use get_args / get_origin and fully - # specify valid annotations. - typehint_mandate = """ + if args_schema_type is not None and args_schema_type == BaseModel: + # Throw errors for common mis-annotations. + # TODO: Use get_args / get_origin and fully + # specify valid annotations. + typehint_mandate = """ class ChildTool(BaseTool): ... args_schema: Type[BaseModel] = SchemaClass ...""" - name = cls.__name__ - raise SchemaAnnotationError( - f"Tool definition for {name} must include valid type annotations" - f" for argument 'args_schema' to behave as expected.\n" - f"Expected annotation of 'Type[BaseModel]'" - f" but got '{args_schema_type}'.\n" - f"Expected class looks like:\n" - f"{typehint_mandate}" - ) + name = cls.__name__ + raise SchemaAnnotationError( + f"Tool definition for {name} must include valid type annotations" + f" for argument 'args_schema' to behave as expected.\n" + f"Expected annotation of 'Type[BaseModel]'" + f" but got '{args_schema_type}'.\n" + f"Expected class looks like:\n" + f"{typehint_mandate}" + ) name: str """The unique name of the tool that clearly communicates its purpose."""