@@ -38,23 +38,6 @@ class BaseTool[InputSchema: BaseIOSchema, OutputSchema: BaseIOSchema](ABC):
38
38
tool_description (str): Description of the tool, derived from the input schema's description or overridden by the config.
39
39
"""
40
40
41
- def __init_subclass__ (cls , ** kwargs ):
42
- """
43
- Hook called when a class is subclassed.
44
-
45
- Captures generic type parameters during class creation and stores them as class attributes
46
- to work around the unreliable __orig_class__ attribute in modern Python generic syntax.
47
- """
48
- super ().__init_subclass__ (** kwargs )
49
- if hasattr (cls , "__orig_bases__" ):
50
- for base in cls .__orig_bases__ :
51
- if hasattr (base , "__origin__" ) and base .__origin__ is BaseTool :
52
- args = get_args (base )
53
- if len (args ) == 2 :
54
- cls ._input_schema_cls = args [0 ]
55
- cls ._output_schema_cls = args [1 ]
56
- break
57
-
58
41
def __init__ (self , config : BaseToolConfig = BaseToolConfig ()):
59
42
"""
60
43
Initializes the BaseTool with an optional configuration override.
@@ -72,7 +55,12 @@ def input_schema(self) -> Type[InputSchema]:
72
55
Returns:
73
56
Type[InputSchema]: The input schema class.
74
57
"""
75
- return getattr (self .__class__ , "_input_schema_cls" , BaseIOSchema )
58
+ if hasattr (self , "__orig_class__" ):
59
+ TI , _ = get_args (self .__orig_class__ )
60
+ else :
61
+ TI = BaseIOSchema
62
+
63
+ return TI
76
64
77
65
@property
78
66
def output_schema (self ) -> Type [OutputSchema ]:
@@ -82,7 +70,12 @@ def output_schema(self) -> Type[OutputSchema]:
82
70
Returns:
83
71
Type[OutputSchema]: The output schema class.
84
72
"""
85
- return getattr (self .__class__ , "_output_schema_cls" , BaseIOSchema )
73
+ if hasattr (self , "__orig_class__" ):
74
+ _ , TO = get_args (self .__orig_class__ )
75
+ else :
76
+ TO = BaseIOSchema
77
+
78
+ return TO
86
79
87
80
@property
88
81
def tool_name (self ) -> str :
0 commit comments