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() {
103103 }
104104
105105 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 ());
109109
110110 if (isFunction ) {
111111 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() {
7878 .hasMessageContaining ("Multiple tools with the same name (validTool) found in sources" );
7979 }
8080
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+
8190 static class ValidToolObject {
8291
8392 @ Tool
@@ -137,4 +146,13 @@ public String validTool() {
137146
138147 }
139148
149+ static class ObjectTypeToolMethodsObject {
150+
151+ @ Tool
152+ public Object objectTool () {
153+ return "Object tool result" ;
154+ }
155+
156+ }
157+
140158}
You can’t perform that action at this time.
0 commit comments