Class ExecutableMethodToolExecutor
java.lang.Object
io.micronaut.langchain4j.tools.ExecutableMethodToolExecutor
- All Implemented Interfaces:
dev.langchain4j.service.tool.ToolExecutor
@Internal
public final class ExecutableMethodToolExecutor
extends Object
implements dev.langchain4j.service.tool.ToolExecutor
A LangChain4j
ToolExecutor that invokes a Tool method of a bean through its Micronaut
ExecutableMethod, with a ToolSpecification built from the compile-time annotation metadata and
argument names of the method. LangChain4j neither scans the class of the bean for @Tool methods nor invokes
them reflectively, so tool classes work without reflection metadata, in native images and in the classes generated
for other languages (Python).
The specification, the coercion of the arguments and the conversion of the result follow LangChain4j's
ToolSpecifications and DefaultToolExecutor. The JSON schema of a POJO parameter is still derived by
LangChain4j from the class of the parameter.
- Since:
- 2.4.0
-
Constructor Summary
ConstructorsConstructorDescriptionExecutableMethodToolExecutor(@NonNull Object bean, @NonNull io.micronaut.inject.ExecutableMethod<?, ?> method) -
Method Summary
Modifier and TypeMethodDescriptionCompletableFuture<dev.langchain4j.service.tool.ToolExecutionResult> executeAsync(dev.langchain4j.agent.tool.ToolExecutionRequest request, dev.langchain4j.invocation.InvocationContext context) dev.langchain4j.service.tool.ToolExecutionResultexecuteWithContext(dev.langchain4j.agent.tool.ToolExecutionRequest request, dev.langchain4j.invocation.InvocationContext context) static @NonNull dev.langchain4j.service.tool.AiServiceTooltoAiServiceTool(@NonNull Object bean, @NonNull io.micronaut.inject.ExecutableMethod<?, ?> method) Builds the tool for aToolmethod of a bean.@NonNull dev.langchain4j.agent.tool.ToolSpecification
-
Constructor Details
-
ExecutableMethodToolExecutor
public ExecutableMethodToolExecutor(@NonNull Object bean, @NonNull io.micronaut.inject.ExecutableMethod<?, ?> method) - Parameters:
bean- The bean declaring the toolmethod- The tool method
-
-
Method Details
-
toAiServiceTool
public static @NonNull dev.langchain4j.service.tool.AiServiceTool toAiServiceTool(@NonNull Object bean, @NonNull io.micronaut.inject.ExecutableMethod<?, ?> method) Builds the tool for aToolmethod of a bean.- Parameters:
bean- The beanmethod- The tool method- Returns:
- The tool
-
toolSpecification
public @NonNull dev.langchain4j.agent.tool.ToolSpecification toolSpecification()- Returns:
- The specification of the tool, as LangChain4j's
ToolSpecifications.toolSpecificationFrombuilds it
-
execute
-
executeWithContext
public dev.langchain4j.service.tool.ToolExecutionResult executeWithContext(dev.langchain4j.agent.tool.ToolExecutionRequest request, dev.langchain4j.invocation.InvocationContext context) - Specified by:
executeWithContextin interfacedev.langchain4j.service.tool.ToolExecutor
-
executeAsync
public CompletableFuture<dev.langchain4j.service.tool.ToolExecutionResult> executeAsync(dev.langchain4j.agent.tool.ToolExecutionRequest request, dev.langchain4j.invocation.InvocationContext context) - Specified by:
executeAsyncin interfacedev.langchain4j.service.tool.ToolExecutor
-