Class AiOrchestrator

java.lang.Object
com.vaadin.flow.component.ai.orchestrator.AiOrchestrator

public class AiOrchestrator extends Object
Orchestrator for AI-powered chat interfaces.

This class is a generic coordination engine that connects UI components with an LLM provider. It provides:

  • LLM integration
  • Component wiring (input, message list, file receiver)
  • Tool execution coordination
  • Programmatic invocation via prompt(String)

The orchestrator is configured via a fluent builder:

 AiOrchestrator orchestrator = AiOrchestrator
         .builder(llmProvider, systemPrompt).withInput(messageInput) // optional
         .withMessageList(messageList) // optional
         .withFileReceiver(upload) // optional
         .withTools(toolObj) // optional, for @Tool annotations
         .withUserName(userName) // optional
         .withAiName(aiName) // optional
         .build();
 

Conversation history is managed internally by the LLMProvider instance. Each orchestrator maintains its own conversation context through its provider instance.

Note: AiOrchestrator is not serializable. If your application uses session persistence, you will need to create a new orchestrator instance after session restore.

Author:
Vaadin Ltd
  • Method Details

    • builder

      public static AiOrchestrator.Builder builder(LLMProvider provider)
      Creates a new builder for AiOrchestrator.
      Parameters:
      provider - the LLM provider
      Returns:
      a new builder
    • builder

      public static AiOrchestrator.Builder builder(LLMProvider provider, String systemPrompt)
      Creates a new builder for AiOrchestrator with a system prompt.
      Parameters:
      provider - the LLM provider
      systemPrompt - the system prompt for the LLM
      Returns:
      a new builder
    • prompt

      public void prompt(String userMessage)
      Sends a prompt to the AI orchestrator programmatically. This method allows sending prompts without requiring an input component.

      This is useful for scenarios where you want to trigger AI interaction from button clicks or other UI events without using a message input component.

      If a request is already being processed, this method will log a warning and return without processing the new prompt.

      Parameters:
      userMessage - the prompt to send to the AI
      Throws:
      IllegalStateException - if no UI context is available