Reference documentation and code samples for the Gemini Enterprise for Customer Experience V1BETA API class Google::Cloud::Ces::V1beta::SessionService::Client.
Client for the SessionService service.
Session service provides APIs for interacting with CES agents.
Inherits
- Object
Methods
.configure
def self.configure() { |config| ... } -> Client::ConfigurationConfigure the SessionService Client class.
See Configuration for a description of the configuration fields.
- (config) — Configure the Client client.
- config (Client::Configuration)
# Modify the configuration for all SessionService clients ::Google::Cloud::Ces::V1beta::SessionService::Client.configure do |config| config.timeout = 10.0 end
#bidi_run_session
def bidi_run_session(request, options = nil) { |response, operation| ... } -> ::Enumerable<::Google::Cloud::Ces::V1beta::BidiSessionServerMessage>Establishes a bidirectional streaming connection with the CES agent. The agent processes continuous multimodal inputs (e.g., text, audio) and generates real-time multimodal output streams.
--- Client Request Stream --- The client streams requests in the following order:
Initialization: The first message must contain SessionConfig. For audio sessions, this should also include InputAudioConfig and OutputAudioConfig to define audio processing and synthesis parameters.
Interaction: Subsequent messages stream SessionInput containing real-time user input data.
Termination: The client should half-close the stream when there is no more user input. It should also half-close upon receiving EndSession or GoAway from the agent.
--- Server Response Stream --- For each interaction turn, the agent streams messages in the following sequence:
Speech Recognition (First N messages): Contains RecognitionResult representing the concatenated user speech segments captured so far. This is only populated for audio sessions.
Response (Next M messages): Contains SessionOutput delivering the agent's response in various modalities (e.g., text, audio).
Turn Completion (Final message of the turn): Contains SessionOutput with turn_completed set to true. This signals the end of the current turn and includes DiagnosticInfo with execution details.
--- Audio Best Practices ---
Streaming: Stream audio data CONTINUOUSLY, even during silence. Recommended chunk size: 40-120ms (balances latency vs. efficiency).
Playback & Interruption: Play audio responses upon receipt. Stop playback immediately if an InterruptionSignal is received (e.g., user barge-in or new agent response).
- request (::Gapic::StreamInput, ::Enumerable<::Google::Cloud::Ces::V1beta::BidiSessionClientMessage, ::Hash>) — An enumerable of BidiSessionClientMessage instances.
- options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
- (response, operation) — Access the result along with the RPC operation
- response (::Enumerable<::Google::Cloud::Ces::V1beta::BidiSessionServerMessage>)
- operation (::GRPC::ActiveCall::Operation)
- (::Enumerable<::Google::Cloud::Ces::V1beta::BidiSessionServerMessage>)
- (::Google::Cloud::Error) — if the RPC is aborted.
Basic example
require "google/cloud/ces/v1beta" # Create a client object. The client can be reused for multiple calls. client = Google::Cloud::Ces::V1beta::SessionService::Client.new # Create an input stream. input = Gapic::StreamInput.new # Call the bidi_run_session method to start streaming. output = client.bidi_run_session input # Send requests on the stream. For each request object, set fields by # passing keyword arguments. Be sure to close the stream when done. input << Google::Cloud::Ces::V1beta::BidiSessionClientMessage.new input << Google::Cloud::Ces::V1beta::BidiSessionClientMessage.new input.close # The returned object is a streamed enumerable yielding elements of type # ::Google::Cloud::Ces::V1beta::BidiSessionServerMessage output.each do |current_response| p current_response end
#configure
def configure() { |config| ... } -> Client::ConfigurationConfigure the SessionService Client instance.
The configuration is set to the derived mode, meaning that values can be changed, but structural changes (adding new fields, etc.) are not allowed. Structural changes should be made on Client.configure.
See Configuration for a description of the configuration fields.
- (config) — Configure the Client client.
- config (Client::Configuration)
#initialize
def initialize() { |config| ... } -> ClientCreate a new SessionService client object.
- (config) — Configure the SessionService client.
- config (Client::Configuration)
- (Client) — a new instance of Client
# Create a client using the default configuration client = ::Google::Cloud::Ces::V1beta::SessionService::Client.new # Create a client using a custom configuration client = ::Google::Cloud::Ces::V1beta::SessionService::Client.new do |config| config.timeout = 10.0 end
#location_client
def location_client() -> Google::Cloud::Location::Locations::ClientGet the associated client for mix-in of the Locations.
- (Google::Cloud::Location::Locations::Client)
#logger
def logger() -> LoggerThe logger used for request/response debug logging.
- (Logger)
#run_session
def run_session(request, options = nil) -> ::Google::Cloud::Ces::V1beta::RunSessionResponse
def run_session(config: nil, inputs: nil) -> ::Google::Cloud::Ces::V1beta::RunSessionResponseInitiates a single-turn interaction with the CES agent within a session.
def run_session(request, options = nil) -> ::Google::Cloud::Ces::V1beta::RunSessionResponserun_session via a request object, either of type
RunSessionRequest or an equivalent Hash.
- request (::Google::Cloud::Ces::V1beta::RunSessionRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
- options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def run_session(config: nil, inputs: nil) -> ::Google::Cloud::Ces::V1beta::RunSessionResponserun_session via keyword arguments. Note that at
least one keyword argument is required. To specify no parameters, or to keep all
the default parameter values, pass an empty Hash as a request object (see above).
- config (::Google::Cloud::Ces::V1beta::SessionConfig, ::Hash) — Required. The configuration for the session.
- inputs (::Array<::Google::Cloud::Ces::V1beta::SessionInput, ::Hash>) — Required. Inputs for the session.
- (response, operation) — Access the result along with the RPC operation
- response (::Google::Cloud::Ces::V1beta::RunSessionResponse)
- operation (::GRPC::ActiveCall::Operation)
- (::Google::Cloud::Error) — if the RPC is aborted.
Basic example
require "google/cloud/ces/v1beta" # Create a client object. The client can be reused for multiple calls. client = Google::Cloud::Ces::V1beta::SessionService::Client.new # Create a request. To set request fields, pass in keyword arguments. request = Google::Cloud::Ces::V1beta::RunSessionRequest.new # Call the run_session method. result = client.run_session request # The returned object is of type Google::Cloud::Ces::V1beta::RunSessionResponse. p result
#stream_run_session
def stream_run_session(request, options = nil) -> ::Enumerable<::Google::Cloud::Ces::V1beta::RunSessionResponse>
def stream_run_session(config: nil, inputs: nil) -> ::Enumerable<::Google::Cloud::Ces::V1beta::RunSessionResponse>Initiates a single-turn interaction with the CES agent. Uses server-side streaming to deliver incremental results and partial responses as they are generated.
By default, complete responses (e.g., messages from callbacks or full LLM responses) are sent to the client as soon as they are available. To enable streaming individual text chunks directly from the model, set enable_text_streaming to true.
def stream_run_session(request, options = nil) -> ::Enumerable<::Google::Cloud::Ces::V1beta::RunSessionResponse>stream_run_session via a request object, either of type
RunSessionRequest or an equivalent Hash.
- request (::Google::Cloud::Ces::V1beta::RunSessionRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
- options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def stream_run_session(config: nil, inputs: nil) -> ::Enumerable<::Google::Cloud::Ces::V1beta::RunSessionResponse>stream_run_session via keyword arguments. Note that at
least one keyword argument is required. To specify no parameters, or to keep all
the default parameter values, pass an empty Hash as a request object (see above).
- config (::Google::Cloud::Ces::V1beta::SessionConfig, ::Hash) — Required. The configuration for the session.
- inputs (::Array<::Google::Cloud::Ces::V1beta::SessionInput, ::Hash>) — Required. Inputs for the session.
- (response, operation) — Access the result along with the RPC operation
- response (::Enumerable<::Google::Cloud::Ces::V1beta::RunSessionResponse>)
- operation (::GRPC::ActiveCall::Operation)
- (::Enumerable<::Google::Cloud::Ces::V1beta::RunSessionResponse>)
- (::Google::Cloud::Error) — if the RPC is aborted.
Basic example
require "google/cloud/ces/v1beta" # Create a client object. The client can be reused for multiple calls. client = Google::Cloud::Ces::V1beta::SessionService::Client.new # Create a request. To set request fields, pass in keyword arguments. request = Google::Cloud::Ces::V1beta::RunSessionRequest.new # Call the stream_run_session method to start streaming. output = client.stream_run_session request # The returned object is a streamed enumerable yielding elements of type # ::Google::Cloud::Ces::V1beta::RunSessionResponse output.each do |current_response| p current_response end
#universe_domain
def universe_domain() -> StringThe effective universe domain
- (String)