Interface ChatExecutor
When built with an event listener registrar, the built-in executors fire an
AiServiceRequestIssuedEvent for every request they send. They fire
an AiServiceResponseReceivedEvent only for the methods that take
chat messages (used for output guardrail reprompts): for execute() and executeAsync(), the caller
fires it.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classAn abstract base-builder class for constructing instances ofChatExecutor.static classStreamingToSynchronousBuilder for constructing instances ofChatExecutor.static classSynchronousBuilder for constructing instances ofChatExecutor. -
Method Summary
Modifier and TypeMethodDescriptionCreates a newChatExecutor.SynchronousBuilderinstance for constructingChatExecutorobjects that perform synchronous chat requests.builder(StreamingChatModel streamingChatModel) Creates a newChatExecutor.StreamingToSynchronousBuilderinstance for constructingChatExecutorobjects that perform streaming chat requests.default ChatExchangeexchange(List<ChatMessage> chatMessages) Likeexecute(List), but also returns the request that produced the response.default CompletableFuture<ChatExchange> exchangeAsync(List<ChatMessage> chatMessages) Non-blocking counterpart ofexchange(List).execute()Execute a chat requestexecute(List<ChatMessage> chatMessages) Executes a chat request using the provided chat messagesdefault CompletableFuture<ChatResponse> Non-blocking counterpart ofexecute().default CompletableFuture<ChatResponse> executeAsync(List<ChatMessage> chatMessages) Non-blocking counterpart ofexecute(List).
-
Method Details
-
execute
-
execute
Executes a chat request using the provided chat messages- Parameters:
chatMessages- The chat messages containing the context of the conversation. It provides the history of messages required for proper interaction with the chat model- Returns:
- A response object containing the AI's response and additional metadata.
-
executeAsync
Non-blocking counterpart ofexecute().The default implementation returns a failed future carrying
AsyncNotSupportedException; the built-in executors override it to call the model without blocking (via the async/reactive model APIs). Used by output-guardrail reprompts on the non-blocking AI Service paths. Consistent withChatModel#doChatAsyncand the other async defaults, a blocking executor is not silently run on the calling thread.- Returns:
- a
CompletableFuturethat completes with the response - Since:
- 1.20.0
-
executeAsync
Non-blocking counterpart ofexecute(List).The default implementation returns a failed future carrying
AsyncNotSupportedException; the built-in executors override it to call the model without blocking (via the async/reactive model APIs). Used by output-guardrail reprompts on the non-blocking AI Service paths. Consistent withChatModel#doChatAsyncand the other async defaults, a blocking executor is not silently run on the calling thread.- Parameters:
chatMessages- The chat messages containing the context of the conversation.- Returns:
- a
CompletableFuturethat completes with the response - Since:
- 1.20.0
-
exchange
Likeexecute(List), but also returns the request that produced the response. When the response is the result of a tool-calling loop, the request is the last one sent to the model, with the tool calls and tool results of all rounds.The default implementation calls
execute(List)and returnsnullas the request, because the request that the executor sent is not known.- Parameters:
chatMessages- The chat messages containing the context of the conversation.- Returns:
- the response and the request that produced it;
ChatExchange.request()isnullwhen the request is not known - Since:
- 1.23.0
-
exchangeAsync
Non-blocking counterpart ofexchange(List).The default implementation calls
executeAsync(List)and returnsnullas the request, because the request that the executor sent is not known.- Parameters:
chatMessages- The chat messages containing the context of the conversation.- Returns:
- a
CompletableFuturethat completes with the request and the response - Since:
- 1.23.0
-
builder
Creates a newChatExecutor.SynchronousBuilderinstance for constructingChatExecutorobjects that perform synchronous chat requests.- Returns:
- A new
ChatExecutor.SynchronousBuilderinstance to configure and build aChatExecutor.
-
builder
Creates a newChatExecutor.StreamingToSynchronousBuilderinstance for constructingChatExecutorobjects that perform streaming chat requests.- Returns:
- A new
ChatExecutor.StreamingToSynchronousBuilderinstance to configure and build aChatExecutor.
-