Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ public ToolCallback[] getToolCallbacks() {
}

private boolean isFunctionalType(Method toolMethod) {
var isFunction = ClassUtils.isAssignable(toolMethod.getReturnType(), Function.class)
|| ClassUtils.isAssignable(toolMethod.getReturnType(), Supplier.class)
|| ClassUtils.isAssignable(toolMethod.getReturnType(), Consumer.class);
var isFunction = ClassUtils.isAssignable(Function.class, toolMethod.getReturnType())
|| ClassUtils.isAssignable(Supplier.class, toolMethod.getReturnType())
|| ClassUtils.isAssignable(Consumer.class, toolMethod.getReturnType());

if (isFunction) {
logger.warn("Method {} is annotated with @Tool but returns a functional type. "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ void whenMultipleToolObjectsWithSameToolNameThenThrow() {
.hasMessageContaining("Multiple tools with the same name (validTool) found in sources");
}

@Test
void whenToolObjectHasObjectTypeMethodThenSuccess() {
MethodToolCallbackProvider provider = MethodToolCallbackProvider.builder()
.toolObjects(new ObjectTypeToolMethodsObject())
.build();
assertThat(provider.getToolCallbacks()).hasSize(1);
assertThat(provider.getToolCallbacks()[0].getToolDefinition().name()).isEqualTo("objectTool");
}

static class ValidToolObject {

@Tool
Expand Down Expand Up @@ -137,4 +146,13 @@ public String validTool() {

}

static class ObjectTypeToolMethodsObject {

@Tool
public Object objectTool() {
return "Object tool result";
}

}

}