Package com.google.genai
Class AsyncSession
java.lang.Object
com.google.genai.AsyncSession
AsyncSession manages sending and receiving messages over a WebSocket connection for a live
session. The live module is experimental.
-
Method Summary
Modifier and TypeMethodDescriptionclose()Closes the WebSocket connection.receive(Consumer<LiveServerMessage> onMessage) Registers a callback to receive messages from the live session.sendClientContent(LiveSendClientContentParameters clientContent) Sends client content to the live session.sendRealtimeInput(LiveSendRealtimeInputParameters realtimeInput) Sends realtime input to the live session.sendToolResponse(LiveSendToolResponseParameters toolResponse) Sends tool response to the live session.Gets the session ID of the live session.
-
Method Details
-
sendClientContent
Sends client content to the live session.- Parameters:
clientContent- ALiveSendClientContentParametersto send.- Returns:
- A
CompletableFuturethat completes when the client content has been sent. The future will fail if the client content cannot be sent.
-
sendRealtimeInput
Sends realtime input to the live session.- Parameters:
realtimeInput- ALiveSendRealtimeInputParametersto send.- Returns:
- A
CompletableFuturethat completes when the realtime input has been sent. The future will fail if the realtime input cannot be sent.
-
sendToolResponse
Sends tool response to the live session.- Parameters:
toolResponse- ALiveSendToolResponseParametersto send.- Returns:
- A
CompletableFuturethat completes when the tool response has been sent. The future will fail if the tool response cannot be sent.
-
receive
Registers a callback to receive messages from the live session. Only one callback can be registered at a time.- Parameters:
onMessage- AConsumerthat will be called for eachLiveServerMessagereceived.- Returns:
- A
CompletableFuturethat completes when the callback has been registered. Note: This future doesn't represent the entire lifecycle of receiving messages, just the *registration* of the callback.
-
close
Closes the WebSocket connection.- Returns:
- A
CompletableFuturethat completes when the connection has been closed.
-
sessionId
Gets the session ID of the live session.- Returns:
- The session ID of the live session.
-