Interface ResponseListener

All Superinterfaces:
Serializable
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface ResponseListener extends Serializable
Listener for LLM response events.

The listener is called once per turn — when the assistant's stream has completed, whether successfully or with an error. The same lifecycle moment as AIController.onResponse(Throwable). Use it to persist conversation state (via AIOrchestrator.getHistory()), trigger follow-up actions, or surface errors to the user.

On success the response text may still be empty if the model emitted only tool calls or stopped without producing visible content. Such turns are successful exchanges; check event.getResponse().isEmpty() if the listener should only react to text-bearing responses. Empty responses are not appended to AIOrchestrator.getHistory().

On failure ResponseListener.ResponseEvent.getError() carries the cause (timeout, stream error, or any throw between AIController.onRequest() and the start of the stream); the response text is either empty or a partial stream that was received before the failure.

The listener is not called when history is restored via Builder.withHistory().

Threading: the listener is called from a background thread (Reactor scheduler). Blocking I/O (e.g. database writes) is safe directly. To update Vaadin UI components from this listener, use ui.access().

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static class 
    Event fired after the assistant's stream has completed, on success or failure.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Called when the assistant's stream has completed.
  • Method Details

    • onResponse

      void onResponse(ResponseListener.ResponseEvent event)
      Called when the assistant's stream has completed.
      Parameters:
      event - the response event