Skip to content

Commit fcbdac9

Browse files
sunyuhan1998spring-builds
authored andcommitted
fix: MethodToolCallbackProvider#isFunctionalType logic to check functiontype
- Change LHR <-> RHR in the ClassUtils.isAssignable Fixes #GH-3355 Signed-off-by: Sun Yuhan <sunyuhan1998@users.noreply.github.com> (cherry picked from commit fe4f0d1)
1 parent 25662fc commit fcbdac9

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

spring-ai-model/src/main/java/org/springframework/ai/tool/method/MethodToolCallbackProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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. "

spring-ai-model/src/test/java/org/springframework/ai/tool/method/MethodToolCallbackProviderTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)