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 Summary
ConstructorsConstructorDescriptionA2AStreamingClientListenerResult(boolean stop, String response, boolean withCurrentArtifacts) Creates an instance of aA2AStreamingClientListenerResultrecord class. -
Method Summary
Modifier and TypeMethodDescriptionCreates a result that signals the streaming process should continue.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.response()Returns the value of theresponserecord component.booleanstop()Returns the value of thestoprecord component.Creates a result that signals the streaming process should stop and uses the artifacts received so far as the final response.stopWithResponse(String response) Creates a result that signals the streaming process should stop and provides an optional final response to return to the caller.final StringtoString()Returns a string representation of this record class.booleanReturns the value of thewithCurrentArtifactsrecord component.
-
Constructor Details
-
A2AStreamingClientListenerResult
public A2AStreamingClientListenerResult(boolean stop, String response, boolean withCurrentArtifacts) Creates an instance of aA2AStreamingClientListenerResultrecord class.- Parameters:
stop- the value for thestoprecord componentresponse- the value for theresponserecord componentwithCurrentArtifacts- the value for thewithCurrentArtifactsrecord component
-
-
Method Details
-
continueStreaming
Creates a result that signals the streaming process should continue.- Returns:
- an instance with
stop=falseandresponse=null
-
stopWithResponse
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 benullto indicate stopping without providing a message- Returns:
- an instance with
stop=trueand the providedresponse
-
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 sameextractTextlogic used by the default A2A client response handling.- Returns:
- an instance with
stop=trueand the response extracted from the artifacts received so far
-
toString
-
hashCode
-
equals
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 withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
stop
public boolean stop()Returns the value of thestoprecord component.- Returns:
- the value of the
stoprecord component
-
response
Returns the value of theresponserecord component.- Returns:
- the value of the
responserecord component
-
withCurrentArtifacts
public boolean withCurrentArtifacts()Returns the value of thewithCurrentArtifactsrecord component.- Returns:
- the value of the
withCurrentArtifactsrecord component
-