File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed
main/java/org/springframework/ai/tool/method
test/java/org/springframework/ai/tool/method Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -103,9 +103,9 @@ public ToolCallback[] getToolCallbacks() {
103
103
}
104
104
105
105
private boolean isFunctionalType (Method toolMethod ) {
106
- var isFunction = ClassUtils .isAssignable (toolMethod .getReturnType (), Function . class )
107
- || ClassUtils .isAssignable (toolMethod .getReturnType (), Supplier . class )
108
- || ClassUtils .isAssignable (toolMethod .getReturnType (), Consumer . class );
106
+ var isFunction = ClassUtils .isAssignable (Function . class , toolMethod .getReturnType ())
107
+ || ClassUtils .isAssignable (Supplier . class , toolMethod .getReturnType ())
108
+ || ClassUtils .isAssignable (Consumer . class , toolMethod .getReturnType ());
109
109
110
110
if (isFunction ) {
111
111
logger .warn ("Method {} is annotated with @Tool but returns a functional type. "
Original file line number Diff line number Diff line change @@ -78,6 +78,15 @@ void whenMultipleToolObjectsWithSameToolNameThenThrow() {
78
78
.hasMessageContaining ("Multiple tools with the same name (validTool) found in sources" );
79
79
}
80
80
81
+ @ Test
82
+ void whenToolObjectHasObjectTypeMethodThenSuccess () {
83
+ MethodToolCallbackProvider provider = MethodToolCallbackProvider .builder ()
84
+ .toolObjects (new ObjectTypeToolMethodsObject ())
85
+ .build ();
86
+ assertThat (provider .getToolCallbacks ()).hasSize (1 );
87
+ assertThat (provider .getToolCallbacks ()[0 ].getToolDefinition ().name ()).isEqualTo ("objectTool" );
88
+ }
89
+
81
90
static class ValidToolObject {
82
91
83
92
@ Tool
@@ -137,4 +146,13 @@ public String validTool() {
137
146
138
147
}
139
148
149
+ static class ObjectTypeToolMethodsObject {
150
+
151
+ @ Tool
152
+ public Object objectTool () {
153
+ return "Object tool result" ;
154
+ }
155
+
156
+ }
157
+
140
158
}
You can’t perform that action at this time.
0 commit comments