@Generated(value="by gapic-generator-java") public class AssistantServiceClient extends Object implements com.google.api.gax.core.BackgroundResource
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (AssistantServiceClient assistantServiceClient = AssistantServiceClient.create()) {
StreamAssistRequest request =
StreamAssistRequest.newBuilder()
.setName(
AssistantName.of(
"[PROJECT]", "[LOCATION]", "[COLLECTION]", "[ENGINE]", "[ASSISTANT]")
.toString())
.setQuery(Query.newBuilder().build())
.setSession(
SessionName.ofProjectLocationDataStoreSessionName(
"[PROJECT]", "[LOCATION]", "[DATA_STORE]", "[SESSION]")
.toString())
.setUserMetadata(AssistUserMetadata.newBuilder().build())
.setToolsSpec(StreamAssistRequest.ToolsSpec.newBuilder().build())
.setGenerationSpec(StreamAssistRequest.GenerationSpec.newBuilder().build())
.build();
ServerStream<StreamAssistResponse> stream =
assistantServiceClient.streamAssistCallable().call(request);
for (StreamAssistResponse response : stream) {
// Do something when a response is received.
}
}
Note: close() needs to be called on the AssistantServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
| Method | Description | Method Variants |
|---|---|---|
StreamAssist |
Assists the user with a query in a streaming fashion. |
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of AssistantServiceSettings to create(). For example:
To customize credentials:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
AssistantServiceSettings assistantServiceSettings =
AssistantServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
AssistantServiceClient assistantServiceClient =
AssistantServiceClient.create(assistantServiceSettings);
To customize the endpoint:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
AssistantServiceSettings assistantServiceSettings =
AssistantServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
AssistantServiceClient assistantServiceClient =
AssistantServiceClient.create(assistantServiceSettings);
To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over the wire:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
AssistantServiceSettings assistantServiceSettings =
AssistantServiceSettings.newHttpJsonBuilder().build();
AssistantServiceClient assistantServiceClient =
AssistantServiceClient.create(assistantServiceSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
| Modifier | Constructor and Description |
|---|---|
protected |
AssistantServiceClient(AssistantServiceSettings settings)
Constructs an instance of AssistantServiceClient, using the given settings.
|
protected |
AssistantServiceClient(AssistantServiceStub stub) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
void |
close() |
static AssistantServiceClient |
create()
Constructs an instance of AssistantServiceClient with default settings.
|
static AssistantServiceClient |
create(AssistantServiceSettings settings)
Constructs an instance of AssistantServiceClient, using the given settings.
|
static AssistantServiceClient |
create(AssistantServiceStub stub)
Constructs an instance of AssistantServiceClient, using the given stub for making calls.
|
AssistantServiceSettings |
getSettings() |
AssistantServiceStub |
getStub() |
boolean |
isShutdown() |
boolean |
isTerminated() |
void |
shutdown() |
void |
shutdownNow() |
com.google.api.gax.rpc.ServerStreamingCallable<StreamAssistRequest,StreamAssistResponse> |
streamAssistCallable()
Assists the user with a query in a streaming fashion.
|
protected AssistantServiceClient(AssistantServiceSettings settings) throws IOException
IOExceptionprotected AssistantServiceClient(AssistantServiceStub stub)
public static final AssistantServiceClient create() throws IOException
IOExceptionpublic static final AssistantServiceClient create(AssistantServiceSettings settings) throws IOException
IOExceptionpublic static final AssistantServiceClient create(AssistantServiceStub stub)
public final AssistantServiceSettings getSettings()
public AssistantServiceStub getStub()
public final com.google.api.gax.rpc.ServerStreamingCallable<StreamAssistRequest,StreamAssistResponse> streamAssistCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (AssistantServiceClient assistantServiceClient = AssistantServiceClient.create()) {
StreamAssistRequest request =
StreamAssistRequest.newBuilder()
.setName(
AssistantName.of(
"[PROJECT]", "[LOCATION]", "[COLLECTION]", "[ENGINE]", "[ASSISTANT]")
.toString())
.setQuery(Query.newBuilder().build())
.setSession(
SessionName.ofProjectLocationDataStoreSessionName(
"[PROJECT]", "[LOCATION]", "[DATA_STORE]", "[SESSION]")
.toString())
.setUserMetadata(AssistUserMetadata.newBuilder().build())
.setToolsSpec(StreamAssistRequest.ToolsSpec.newBuilder().build())
.setGenerationSpec(StreamAssistRequest.GenerationSpec.newBuilder().build())
.build();
ServerStream<StreamAssistResponse> stream =
assistantServiceClient.streamAssistCallable().call(request);
for (StreamAssistResponse response : stream) {
// Do something when a response is received.
}
}
public final void close()
close in interface AutoCloseablepublic void shutdown()
shutdown in interface com.google.api.gax.core.BackgroundResourcepublic boolean isShutdown()
isShutdown in interface com.google.api.gax.core.BackgroundResourcepublic boolean isTerminated()
isTerminated in interface com.google.api.gax.core.BackgroundResourcepublic void shutdownNow()
shutdownNow in interface com.google.api.gax.core.BackgroundResourcepublic boolean awaitTermination(long duration,
TimeUnit unit)
throws InterruptedException
awaitTermination in interface com.google.api.gax.core.BackgroundResourceInterruptedExceptionCopyright © 2026 Google LLC. All rights reserved.