Class DeferredResponse<T>

java.lang.Object
dev.langchain4j.agentic.internal.DeferredResponse<T>
Type Parameters:
T - the type of the response value
All Implemented Interfaces:
DelayedResponse<T>
Direct Known Subclasses:
PendingResponse, SuspendedResponse

public abstract class DeferredResponse<T> extends Object implements DelayedResponse<T>
Abstract base for responses that are deferred to an external actor (e.g., a human, a REST endpoint, a message queue) and must be explicitly completed via complete(Object).

After serialization/deserialization, a new incomplete CompletableFuture is created, allowing an external system to reconnect and complete the response.

Concrete subclasses determine the runtime behavior when the response is not yet available:

  • Constructor Details

    • DeferredResponse

      protected DeferredResponse(String responseId)
  • Method Details

    • responseId

      public String responseId()
      Returns the unique identifier for this deferred response.
      Returns:
      the response identifier
    • isDone

      public boolean isDone()
      Specified by:
      isDone in interface DelayedResponse<T>
    • blockingGet

      public T blockingGet()
      Specified by:
      blockingGet in interface DelayedResponse<T>
    • blockingGet

      public T blockingGet(long timeout, TimeUnit unit) throws TimeoutException
      Waits for the response with a timeout.
      Parameters:
      timeout - the maximum time to wait
      unit - the time unit of the timeout argument
      Returns:
      the response value
      Throws:
      TimeoutException - if the wait timed out
    • complete

      public boolean complete(T value)
      Completes this deferred response with the given value. Any threads blocked on blockingGet() will be released.
      Parameters:
      value - the response value
      Returns:
      true if this invocation caused the response to transition to a completed state, false if it was already completed
    • completeExceptionally

      public boolean completeExceptionally(Throwable exception)
      Completes this deferred response exceptionally.
      Parameters:
      exception - the exception
      Returns:
      true if this invocation caused the response to transition to a completed state
    • toString

      public String toString()
      Overrides:
      toString in class Object