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 @@ -99,6 +99,18 @@ void resolveMultipleFunctionAndToolCallbacks() {
});
}

@Test
void resolveMissingToolCallbacks() {
new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(ToolCallingAutoConfiguration.class))
.withUserConfiguration(Config.class)
.run(context -> {
var toolCallbackResolver = context.getBean(ToolCallbackResolver.class);
assertThat(toolCallbackResolver).isInstanceOf(DelegatingToolCallbackResolver.class);

assertThat(toolCallbackResolver.resolve("NonExisting")).isNull();
});
}

static class WeatherService {

@Tool(description = "Get the weather in location. Return temperature in 36°F or 36°C format.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,24 @@ public ToolCallback resolve(String toolName) {
return resolvedToolCallback;
}

ResolvableType toolType = TypeResolverHelper.resolveBeanType(this.applicationContext, toolName);
ResolvableType toolInputType = (ResolvableType.forType(Supplier.class).isAssignableFrom(toolType))
? ResolvableType.forType(Void.class) : TypeResolverHelper.getFunctionArgumentType(toolType, 0);
try {
ResolvableType toolType = TypeResolverHelper.resolveBeanType(this.applicationContext, toolName);
ResolvableType toolInputType = (ResolvableType.forType(Supplier.class).isAssignableFrom(toolType))
? ResolvableType.forType(Void.class) : TypeResolverHelper.getFunctionArgumentType(toolType, 0);

String toolDescription = resolveToolDescription(toolName, toolInputType.toClass());
Object bean = this.applicationContext.getBean(toolName);
String toolDescription = resolveToolDescription(toolName, toolInputType.toClass());
Object bean = this.applicationContext.getBean(toolName);

resolvedToolCallback = buildToolCallback(toolName, toolType, toolInputType, toolDescription, bean);
resolvedToolCallback = buildToolCallback(toolName, toolType, toolInputType, toolDescription, bean);

toolCallbacksCache.put(toolName, resolvedToolCallback);
toolCallbacksCache.put(toolName, resolvedToolCallback);

return resolvedToolCallback;
return resolvedToolCallback;
}
catch (Exception e) {
logger.debug("ToolCallback resolution failed from Spring application context", e);
return null;
}
}

public SchemaType getSchemaType() {
Expand Down