Class AIOrchestrator.Builder
- Enclosing class:
AIOrchestrator
AIOrchestrator instance.
The builder requires an LLMProvider and a system prompt. All
other settings are optional:
withInput(AIInput)orwithInput(MessageInput)– connects a text input component so that user submissions are automatically forwarded to the LLM. If omitted, useAIOrchestrator.prompt(String)to send messages programmatically.withMessageList(AIMessageList)orwithMessageList(MessageList)– connects a message list component to display the conversation. If omitted, responses are still streamed but not rendered.withFileReceiver(AIFileReceiver)orwithFileReceiver(UploadManager)– enables file upload support. Uploaded files are sent to the LLM as attachments with the next prompt.withTools(Object...)– registers objects containing vendor-specific tool-annotated methods (e.g. LangChain4j's@Toolor Spring AI's@Tool) that the LLM can invoke.withUserName(String)– sets the display name for user messages (defaults to "You").withAssistantName(String)– sets the display name for assistant messages (defaults to "Assistant").
Both Flow components (MessageInput, MessageList,
UploadManager) and custom implementations of the AI interfaces
(AIInput, AIMessageList, AIFileReceiver) are
accepted.
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds the orchestrator.withAssistantName(String assistantName) Sets the display name for AI assistant messages in the message list.Sets a listener that is called when an attachment in the message list is clicked.Sets a listener that is called when a message with attachments is submitted to the LLM provider.withFileReceiver(AIFileReceiver fileReceiver) Sets the file receiver component for file uploads.withFileReceiver(com.vaadin.flow.component.upload.UploadManager uploadManager) Sets the file receiver component using a Flow UploadManager.Sets the input component.withInput(com.vaadin.flow.component.messages.MessageInput messageInput) Sets the input component using a Flow MessageInput component.withMessageList(AIMessageList messageList) Sets the message list component.withMessageList(com.vaadin.flow.component.messages.MessageList messageList) Sets the message list component using a Flow MessageList component.Sets the objects containing vendor-specific tool-annotated methods that will be available to the LLM.withUserName(String userName) Sets the display name for user messages in the message list.
-
Method Details
-
withMessageList
Sets the message list component.- Parameters:
messageList- the message list- Returns:
- this builder
-
withMessageList
public AIOrchestrator.Builder withMessageList(com.vaadin.flow.component.messages.MessageList messageList) Sets the message list component using a Flow MessageList component.- Parameters:
messageList- the Flow MessageList component- Returns:
- this builder
-
withInput
Sets the input component.- Parameters:
input- the input component- Returns:
- this builder
-
withInput
public AIOrchestrator.Builder withInput(com.vaadin.flow.component.messages.MessageInput messageInput) Sets the input component using a Flow MessageInput component.- Parameters:
messageInput- the Flow MessageInput component- Returns:
- this builder
-
withFileReceiver
Sets the file receiver component for file uploads.- Parameters:
fileReceiver- the file receiver- Returns:
- this builder
-
withFileReceiver
public AIOrchestrator.Builder withFileReceiver(com.vaadin.flow.component.upload.UploadManager uploadManager) Sets the file receiver component using a Flow UploadManager. The provided manager should not have an UploadHandler set beforehand.- Parameters:
uploadManager- the Flow UploadManager- Returns:
- this builder
- Throws:
IllegalArgumentException- if theUploadManageralready has anUploadHandler
-
withTools
Sets the objects containing vendor-specific tool-annotated methods that will be available to the LLM.For LangChain4j, use
@dev.langchain4j.agent.tool.Tool. For Spring AI, use@org.springframework.ai.tool.annotation.Tool.- Parameters:
tools- the objects containing tool methods- Returns:
- this builder
-
withUserName
Sets the display name for user messages in the message list.This name is shown as the author of messages sent by the user. If not set, defaults to "You".
- Parameters:
userName- the display name for user messages, notnull- Returns:
- this builder
-
withAssistantName
Sets the display name for AI assistant messages in the message list.This name is shown as the author of messages generated by the AI. If not set, defaults to "Assistant".
- Parameters:
assistantName- the display name for AI messages, notnull- Returns:
- this builder
-
withAttachmentSubmitListener
Sets a listener that is called when a message with attachments is submitted to the LLM provider. This allows you to store attachment data in your own storage. The listener receives a unique message ID that can later be used to identify the attachments when they are clicked.- Parameters:
listener- the listener to call on attachment submit- Returns:
- this builder
-
withAttachmentClickListener
Sets a listener that is called when an attachment in the message list is clicked. The listener receives the message ID and attachment index, allowing you to retrieve attachment data from your own storage using the same message ID provided inAttachmentSubmitListener.AttachmentSubmitEvent.getMessageId().Note: This listener requires a message list to be configured via
withMessageList(MessageList). If no message list is set, the listener will have no effect.- Parameters:
listener- the listener to call on attachment click- Returns:
- this builder
-
build
Builds the orchestrator.- Returns:
- the configured orchestrator
-