Skip to content

Commit 94d1b91

Browse files
committed
fix method tool call throws same method name
Signed-off-by: finyu <[email protected]>
1 parent 15a5069 commit 94d1b91

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public ToolCallback[] getToolCallbacks() {
6666
AopUtils.isAopProxy(toolObject) ? AopUtils.getTargetClass(toolObject) : toolObject.getClass()))
6767
.filter(toolMethod -> toolMethod.isAnnotationPresent(Tool.class))
6868
.filter(toolMethod -> !isFunctionalType(toolMethod))
69+
.filter(ReflectionUtils.USER_DECLARED_METHODS::matches)
6970
.map(toolMethod -> MethodToolCallback.builder()
7071
.toolDefinition(ToolDefinition.from(toolMethod))
7172
.toolMetadata(ToolMetadata.from(toolMethod))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.springframework.ai.tool.method;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.ai.tool.ToolCallback;
5+
import org.springframework.ai.tool.annotation.Tool;
6+
7+
import static org.junit.jupiter.api.Assertions.*;
8+
9+
class MethodToolCallbackProviderTest {
10+
11+
abstract class TestObjectClass<T> {
12+
13+
public abstract String test(T input);
14+
}
15+
16+
class TestObjectSuperClass extends TestObjectClass<String> {
17+
18+
@Tool
19+
public String test(String input) {
20+
return input;
21+
}
22+
}
23+
24+
@Test
25+
public void buildToolsWithBridgeMethodReturnOnlyUserDeclaredMethods() {
26+
MethodToolCallbackProvider provider = MethodToolCallbackProvider.builder().toolObjects(new TestObjectSuperClass()).build();
27+
ToolCallback[] toolCallbacks = provider.getToolCallbacks();
28+
assertEquals(1, toolCallbacks.length);
29+
assertInstanceOf(MethodToolCallback.class, toolCallbacks[0]);
30+
}
31+
32+
}

0 commit comments

Comments
 (0)