Class DefaultToolExecutor
- All Implemented Interfaces:
ToolExecutor
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionDefaultToolExecutor(Object object, ToolExecutionRequest toolExecutionRequest) DefaultToolExecutor(Object object, Method method) DefaultToolExecutor(Object object, Method originalMethod, Method methodToInvoke) When methods annotated with @Tool are wrapped into proxies (AOP), the parameters of the proxied method do not retain their original names. -
Method Summary
Modifier and TypeMethodDescriptionstatic DefaultToolExecutor.Builderbuilder()execute(ToolExecutionRequest request, Object memoryId) Executes a tool request.executeAsync(ToolExecutionRequest request, InvocationContext context) Non-blocking counterpart ofToolExecutor.executeWithContext(ToolExecutionRequest, InvocationContext), invoked by the asynchronous AI Service tool loop (AI Service methods returningCompletableFutureorCompletionStage), which composes the returned future instead of waiting on a thread.executeWithContext(ToolExecutionRequest request, InvocationContext context) Executes a tool request.static longgetBoundedLongValue(Object argument, String parameterName, Class<?> parameterType, long minValue, long maxValue)
-
Constructor Details
-
DefaultToolExecutor
-
DefaultToolExecutor
-
DefaultToolExecutor
-
DefaultToolExecutor
When methods annotated with @Tool are wrapped into proxies (AOP), the parameters of the proxied method do not retain their original names. Therefore, access to the original method is required to retrieve those names.- Parameters:
object- the object on which the method should be invokedoriginalMethod- the original method, used to retrieve parameter names and prepare argumentsmethodToInvoke- the method that should actually be invoked
-
-
Method Details
-
originalMethod
-
executeWithContext
public ToolExecutionResult executeWithContext(ToolExecutionRequest request, InvocationContext context) Description copied from interface:ToolExecutorExecutes a tool request. Override this method if you wish to:- access the
InvocationParameterswhen passing extra data into the tool - propagate the tool result object (ToolExecutionResult.result()) into theToolExecution- Specified by:
executeWithContextin interfaceToolExecutor- Parameters:
request- The tool execution request. Contains tool name and arguments.context- The AI Service invocation context, containsChatMemoryID (seeMemoryIdfor more details), andInvocationParameters.- Returns:
- The result of the tool execution that will be sent to the LLM.
-
executeAsync
public CompletableFuture<ToolExecutionResult> executeAsync(ToolExecutionRequest request, InvocationContext context) Non-blocking counterpart ofToolExecutor.executeWithContext(ToolExecutionRequest, InvocationContext), invoked by the asynchronous AI Service tool loop (AI Service methods returningCompletableFutureorCompletionStage), which composes the returned future instead of waiting on a thread.The default implementation returns a failed future carrying
AsyncNotSupportedException: asynchronous AI Services are opt-in, and silently executing a tool synchronously there would block the thread delivering model responses without any visible signal. This failure is not passed to the tool error handlers (and thus never reaches the LLM) — it fails the AI Service invocation, making the gap visible.Override this method to use this tool with an asynchronous AI Service. If the tool performs I/O that can be initiated without holding a thread (e.g. it delegates to an asynchronous client), return that future. If blocking execution is acceptable, it can simply return
CompletableFuture.completedFuture(executeWithContext(request, context)).Errors may be signaled either synchronously (thrown from this method) or via a failed future; the AI Service applies the configured tool error handlers to both identically.
When the
@Toolmethod returns a single-value asynchronous type (CompletableFuture,CompletionStage, or a type handled by aCompletableFutureAdaptersuch as MutinyUnior ReactorMono), the returned value is composed instead of waited on: the tool can perform truly asynchronous work without holding a thread. Other return types execute synchronously on the calling thread, like the default implementation.- Specified by:
executeAsyncin interfaceToolExecutor- Parameters:
request- The tool execution request. Contains tool name and arguments.context- The AI Service invocation context, containsChatMemoryID (seeMemoryIdfor more details), andInvocationParameters.- Returns:
- a
CompletableFutureof the result of the tool execution that will be sent to the LLM
-
execute
Description copied from interface:ToolExecutorExecutes a tool request.- Specified by:
executein interfaceToolExecutor- Parameters:
request- The tool execution request. Contains tool name and arguments.memoryId- The ID of the chat memory. .- Returns:
- The result of the tool execution that will be sent to the LLM.
-
getBoundedLongValue
-
builder
-