Class GeminiLlmConnection
java.lang.Object
com.google.adk.models.GeminiLlmConnection
- All Implemented Interfaces:
BaseLlmConnection
Manages a persistent, bidirectional connection to the Gemini model via WebSockets for real-time
interaction.
This connection allows sending conversation history, individual messages, function responses, and real-time media blobs (like audio chunks) while continuously receiving responses from the model.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the connection.voidCloses the connection with an error.io.reactivex.rxjava3.core.Flowable<LlmResponse> receive()Receives the model responses.io.reactivex.rxjava3.core.CompletablesendContent(com.google.genai.types.Content content) Sends a user content to the model.io.reactivex.rxjava3.core.CompletablesendContent(com.google.genai.types.Content content, boolean partial) Sends user content to the model, optionally leaving the current turn open for more content.io.reactivex.rxjava3.core.CompletablesendHistory(List<com.google.genai.types.Content> history) Sendshistorywithout audio, which a live session cannot replay, or_adk_liveartifact references, which the model cannot resolve.io.reactivex.rxjava3.core.CompletablesendRealtime(com.google.genai.types.Blob blob) Sends a chunk of audio or a frame of video to the model in realtime.
-
Method Details
-
sendHistory
public io.reactivex.rxjava3.core.Completable sendHistory(List<com.google.genai.types.Content> history) Sendshistorywithout audio, which a live session cannot replay, or_adk_liveartifact references, which the model cannot resolve. Completes the turn so the model answers only when the remaining history ends with a user turn.- Specified by:
sendHistoryin interfaceBaseLlmConnection
-
sendContent
public io.reactivex.rxjava3.core.Completable sendContent(com.google.genai.types.Content content) Description copied from interface:BaseLlmConnectionSends a user content to the model.The model will respond immediately upon receiving the content. If you send function responses, all parts in the content should be function responses.
- Specified by:
sendContentin interfaceBaseLlmConnection
-
sendContent
public io.reactivex.rxjava3.core.Completable sendContent(com.google.genai.types.Content content, boolean partial) Description copied from interface:BaseLlmConnectionSends user content to the model, optionally leaving the current turn open for more content.The default implementation ignores
partialand callsBaseLlmConnection.sendContent(Content). Content made only of function responses is always sent as a tool response.- Specified by:
sendContentin interfaceBaseLlmConnection- Parameters:
content- the content to sendpartial- whether this content is a partial update that does not complete the current turn
-
sendRealtime
public io.reactivex.rxjava3.core.Completable sendRealtime(com.google.genai.types.Blob blob) Description copied from interface:BaseLlmConnectionSends a chunk of audio or a frame of video to the model in realtime.The model may not respond immediately upon receiving the blob. It will do voice activity detection and decide when to respond.
- Specified by:
sendRealtimein interfaceBaseLlmConnection
-
receive
Description copied from interface:BaseLlmConnectionReceives the model responses.- Specified by:
receivein interfaceBaseLlmConnection
-
close
public void close()Description copied from interface:BaseLlmConnectionCloses the connection.- Specified by:
closein interfaceBaseLlmConnection
-
close
Description copied from interface:BaseLlmConnectionCloses the connection with an error.- Specified by:
closein interfaceBaseLlmConnection
-