Record Class A2AStreamingClientListenerResult

java.lang.Object
java.lang.Record
dev.langchain4j.agentic.observability.A2AStreamingClientListenerResult

public record A2AStreamingClientListenerResult(boolean stop, String response, boolean withCurrentArtifacts) extends Record
Represents the outcome returned by an A2A (agent-to-agent) streaming client listener.

The result allows the listener to control whether the client should continue consuming the streaming response and, when stopping, optionally provide a final response to the caller.

This is particularly useful when the caller is only interested in certain events or does not need to observe the entire execution. In such cases, the listener can request the client to stop consuming the stream and return a response immediately, while the A2A server-side task may continue executing asynchronously.

Consumers should use the provided factory methods continueStreaming(), stopWithResponse(String), and stopWithCurrentArtifacts() to clearly express the desired behavior.

Typical usage:


// Continue consuming the streaming response
return A2AStreamingClientListenerResult.continueStreaming();

// Stop consuming the stream and return immediately
// while the server-side task may continue asynchronously
return A2AStreamingClientListenerResult.stopWithResponse("Task accepted");
  • Constructor Details

    • A2AStreamingClientListenerResult

      public A2AStreamingClientListenerResult(boolean stop, String response, boolean withCurrentArtifacts)
      Creates an instance of a A2AStreamingClientListenerResult record class.
      Parameters:
      stop - the value for the stop record component
      response - the value for the response record component
      withCurrentArtifacts - the value for the withCurrentArtifacts record component
  • Method Details

    • continueStreaming

      public static A2AStreamingClientListenerResult continueStreaming()
      Creates a result that signals the streaming process should continue.
      Returns:
      an instance with stop=false and response=null
    • stopWithResponse

      public static A2AStreamingClientListenerResult stopWithResponse(String response)
      Creates a result that signals the streaming process should stop and provides an optional final response to return to the caller.
      Parameters:
      response - the final response to use when stopping; may be null to indicate stopping without providing a message
      Returns:
      an instance with stop=true and the provided response
    • stopWithCurrentArtifacts

      public static A2AStreamingClientListenerResult stopWithCurrentArtifacts()
      Creates a result that signals the streaming process should stop and uses the artifacts received so far as the final response. The artifacts are extracted using the same extractText logic used by the default A2A client response handling.
      Returns:
      an instance with stop=true and the response extracted from the artifacts received so far
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • stop

      public boolean stop()
      Returns the value of the stop record component.
      Returns:
      the value of the stop record component
    • response

      public String response()
      Returns the value of the response record component.
      Returns:
      the value of the response record component
    • withCurrentArtifacts

      public boolean withCurrentArtifacts()
      Returns the value of the withCurrentArtifacts record component.
      Returns:
      the value of the withCurrentArtifacts record component