@Generated(value="by gapic-generator-java") public class AgentsClient extends Object implements 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:
try (AgentsClient agentsClient = AgentsClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
Agent response = agentsClient.getAgent(parent);
}
Note: close() needs to be called on the AgentsClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
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 AgentsSettings to create(). For example:
To customize credentials:
AgentsSettings agentsSettings =
AgentsSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
AgentsClient agentsClient = AgentsClient.create(agentsSettings);
To customize the endpoint:
AgentsSettings agentsSettings = AgentsSettings.newBuilder().setEndpoint(myEndpoint).build();
AgentsClient agentsClient = AgentsClient.create(agentsSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
Modifier and Type | Class and Description |
---|---|
static class |
AgentsClient.SearchAgentsFixedSizeCollection |
static class |
AgentsClient.SearchAgentsPage |
static class |
AgentsClient.SearchAgentsPagedResponse |
Modifier | Constructor and Description |
---|---|
protected |
AgentsClient(AgentsSettings settings)
Constructs an instance of AgentsClient, using the given settings.
|
protected |
AgentsClient(AgentsStub stub) |
protected AgentsClient(AgentsSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") protected AgentsClient(AgentsStub stub)
public static final AgentsClient create() throws IOException
IOException
public static final AgentsClient create(AgentsSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public static final AgentsClient create(AgentsStub stub)
public final AgentsSettings getSettings()
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public AgentsStub getStub()
public final OperationsClient getOperationsClient()
public final Agent getAgent(ProjectName parent)
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
Agent response = agentsClient.getAgent(parent);
}
parent
- Required. The project that the agent to fetch is associated with. Format:
`projects/<Project ID>`.ApiException
- if the remote call failspublic final Agent getAgent(String parent)
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
String parent = AgentName.of("[PROJECT]").toString();
Agent response = agentsClient.getAgent(parent);
}
parent
- Required. The project that the agent to fetch is associated with. Format:
`projects/<Project ID>`.ApiException
- if the remote call failspublic final Agent getAgent(GetAgentRequest request)
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
GetAgentRequest request =
GetAgentRequest.newBuilder().setParent(AgentName.of("[PROJECT]").toString()).build();
Agent response = agentsClient.getAgent(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<GetAgentRequest,Agent> getAgentCallable()
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
GetAgentRequest request =
GetAgentRequest.newBuilder().setParent(AgentName.of("[PROJECT]").toString()).build();
ApiFuture<Agent> future = agentsClient.getAgentCallable().futureCall(request);
// Do something.
Agent response = future.get();
}
public final Agent setAgent(Agent agent)
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
Agent agent = Agent.newBuilder().build();
Agent response = agentsClient.setAgent(agent);
}
agent
- Required. The agent to update.ApiException
- if the remote call failspublic final Agent setAgent(SetAgentRequest request)
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
SetAgentRequest request =
SetAgentRequest.newBuilder()
.setAgent(Agent.newBuilder().build())
.setUpdateMask(FieldMask.newBuilder().build())
.build();
Agent response = agentsClient.setAgent(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<SetAgentRequest,Agent> setAgentCallable()
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
SetAgentRequest request =
SetAgentRequest.newBuilder()
.setAgent(Agent.newBuilder().build())
.setUpdateMask(FieldMask.newBuilder().build())
.build();
ApiFuture<Agent> future = agentsClient.setAgentCallable().futureCall(request);
// Do something.
Agent response = future.get();
}
public final void deleteAgent(ProjectName parent)
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
agentsClient.deleteAgent(parent);
}
parent
- Required. The project that the agent to delete is associated with. Format:
`projects/<Project ID>`.ApiException
- if the remote call failspublic final void deleteAgent(String parent)
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
String parent = AgentName.of("[PROJECT]").toString();
agentsClient.deleteAgent(parent);
}
parent
- Required. The project that the agent to delete is associated with. Format:
`projects/<Project ID>`.ApiException
- if the remote call failspublic final void deleteAgent(DeleteAgentRequest request)
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
DeleteAgentRequest request =
DeleteAgentRequest.newBuilder().setParent(AgentName.of("[PROJECT]").toString()).build();
agentsClient.deleteAgent(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<DeleteAgentRequest,Empty> deleteAgentCallable()
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
DeleteAgentRequest request =
DeleteAgentRequest.newBuilder().setParent(AgentName.of("[PROJECT]").toString()).build();
ApiFuture<Empty> future = agentsClient.deleteAgentCallable().futureCall(request);
// Do something.
future.get();
}
public final AgentsClient.SearchAgentsPagedResponse searchAgents(ProjectName parent)
Since there is at most one conversational agent per project, this method is useful primarily for listing all agents across projects the caller has access to. One can achieve that with a wildcard project collection id "-". Refer to [List Sub-Collections](https://cloud.google.com/apis/design/design_patterns#list_sub-collections).
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
for (Agent element : agentsClient.searchAgents(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent
- Required. The project to list agents from. Format: `projects/<Project ID or
'-'>`.ApiException
- if the remote call failspublic final AgentsClient.SearchAgentsPagedResponse searchAgents(String parent)
Since there is at most one conversational agent per project, this method is useful primarily for listing all agents across projects the caller has access to. One can achieve that with a wildcard project collection id "-". Refer to [List Sub-Collections](https://cloud.google.com/apis/design/design_patterns#list_sub-collections).
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
String parent = AgentName.of("[PROJECT]").toString();
for (Agent element : agentsClient.searchAgents(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent
- Required. The project to list agents from. Format: `projects/<Project ID or
'-'>`.ApiException
- if the remote call failspublic final AgentsClient.SearchAgentsPagedResponse searchAgents(SearchAgentsRequest request)
Since there is at most one conversational agent per project, this method is useful primarily for listing all agents across projects the caller has access to. One can achieve that with a wildcard project collection id "-". Refer to [List Sub-Collections](https://cloud.google.com/apis/design/design_patterns#list_sub-collections).
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
SearchAgentsRequest request =
SearchAgentsRequest.newBuilder()
.setParent(AgentName.of("[PROJECT]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
for (Agent element : agentsClient.searchAgents(request).iterateAll()) {
// doThingsWith(element);
}
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<SearchAgentsRequest,AgentsClient.SearchAgentsPagedResponse> searchAgentsPagedCallable()
Since there is at most one conversational agent per project, this method is useful primarily for listing all agents across projects the caller has access to. One can achieve that with a wildcard project collection id "-". Refer to [List Sub-Collections](https://cloud.google.com/apis/design/design_patterns#list_sub-collections).
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
SearchAgentsRequest request =
SearchAgentsRequest.newBuilder()
.setParent(AgentName.of("[PROJECT]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
ApiFuture<Agent> future = agentsClient.searchAgentsPagedCallable().futureCall(request);
// Do something.
for (Agent element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final UnaryCallable<SearchAgentsRequest,SearchAgentsResponse> searchAgentsCallable()
Since there is at most one conversational agent per project, this method is useful primarily for listing all agents across projects the caller has access to. One can achieve that with a wildcard project collection id "-". Refer to [List Sub-Collections](https://cloud.google.com/apis/design/design_patterns#list_sub-collections).
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
SearchAgentsRequest request =
SearchAgentsRequest.newBuilder()
.setParent(AgentName.of("[PROJECT]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
while (true) {
SearchAgentsResponse response = agentsClient.searchAgentsCallable().call(request);
for (Agent element : response.getResponsesList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final OperationFuture<Empty,Struct> trainAgentAsync(ProjectName parent)
Operation <response: [google.protobuf.Empty][google.protobuf.Empty]>
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
agentsClient.trainAgentAsync(parent).get();
}
parent
- Required. The project that the agent to train is associated with. Format:
`projects/<Project ID>`.ApiException
- if the remote call failspublic final OperationFuture<Empty,Struct> trainAgentAsync(String parent)
Operation <response: [google.protobuf.Empty][google.protobuf.Empty]>
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
String parent = AgentName.of("[PROJECT]").toString();
agentsClient.trainAgentAsync(parent).get();
}
parent
- Required. The project that the agent to train is associated with. Format:
`projects/<Project ID>`.ApiException
- if the remote call failspublic final OperationFuture<Empty,Struct> trainAgentAsync(TrainAgentRequest request)
Operation <response: [google.protobuf.Empty][google.protobuf.Empty]>
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
TrainAgentRequest request =
TrainAgentRequest.newBuilder().setParent(AgentName.of("[PROJECT]").toString()).build();
agentsClient.trainAgentAsync(request).get();
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final OperationCallable<TrainAgentRequest,Empty,Struct> trainAgentOperationCallable()
Operation <response: [google.protobuf.Empty][google.protobuf.Empty]>
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
TrainAgentRequest request =
TrainAgentRequest.newBuilder().setParent(AgentName.of("[PROJECT]").toString()).build();
OperationFuture<Empty, Struct> future =
agentsClient.trainAgentOperationCallable().futureCall(request);
// Do something.
future.get();
}
public final UnaryCallable<TrainAgentRequest,Operation> trainAgentCallable()
Operation <response: [google.protobuf.Empty][google.protobuf.Empty]>
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
TrainAgentRequest request =
TrainAgentRequest.newBuilder().setParent(AgentName.of("[PROJECT]").toString()).build();
ApiFuture<Operation> future = agentsClient.trainAgentCallable().futureCall(request);
// Do something.
future.get();
}
public final OperationFuture<ExportAgentResponse,Struct> exportAgentAsync(ProjectName parent)
Operation <response: [ExportAgentResponse][google.cloud.dialogflow.v2.ExportAgentResponse]>
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
ExportAgentResponse response = agentsClient.exportAgentAsync(parent).get();
}
parent
- Required. The project that the agent to export is associated with. Format:
`projects/<Project ID>`.ApiException
- if the remote call failspublic final OperationFuture<ExportAgentResponse,Struct> exportAgentAsync(String parent)
Operation <response: [ExportAgentResponse][google.cloud.dialogflow.v2.ExportAgentResponse]>
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
String parent = AgentName.of("[PROJECT]").toString();
ExportAgentResponse response = agentsClient.exportAgentAsync(parent).get();
}
parent
- Required. The project that the agent to export is associated with. Format:
`projects/<Project ID>`.ApiException
- if the remote call failspublic final OperationFuture<ExportAgentResponse,Struct> exportAgentAsync(ExportAgentRequest request)
Operation <response: [ExportAgentResponse][google.cloud.dialogflow.v2.ExportAgentResponse]>
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
ExportAgentRequest request =
ExportAgentRequest.newBuilder()
.setParent(AgentName.of("[PROJECT]").toString())
.setAgentUri("agentUri1469149223")
.build();
ExportAgentResponse response = agentsClient.exportAgentAsync(request).get();
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final OperationCallable<ExportAgentRequest,ExportAgentResponse,Struct> exportAgentOperationCallable()
Operation <response: [ExportAgentResponse][google.cloud.dialogflow.v2.ExportAgentResponse]>
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
ExportAgentRequest request =
ExportAgentRequest.newBuilder()
.setParent(AgentName.of("[PROJECT]").toString())
.setAgentUri("agentUri1469149223")
.build();
OperationFuture<ExportAgentResponse, Struct> future =
agentsClient.exportAgentOperationCallable().futureCall(request);
// Do something.
ExportAgentResponse response = future.get();
}
public final UnaryCallable<ExportAgentRequest,Operation> exportAgentCallable()
Operation <response: [ExportAgentResponse][google.cloud.dialogflow.v2.ExportAgentResponse]>
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
ExportAgentRequest request =
ExportAgentRequest.newBuilder()
.setParent(AgentName.of("[PROJECT]").toString())
.setAgentUri("agentUri1469149223")
.build();
ApiFuture<Operation> future = agentsClient.exportAgentCallable().futureCall(request);
// Do something.
Operation response = future.get();
}
public final OperationFuture<Empty,Struct> importAgentAsync(ImportAgentRequest request)
Uploads new intents and entity types without deleting the existing ones. Intents and entity types with the same name are replaced with the new versions from [ImportAgentRequest][google.cloud.dialogflow.v2.ImportAgentRequest]. After the import, the imported draft agent will be trained automatically (unless disabled in agent settings). However, once the import is done, training may not be completed yet. Please call [TrainAgent][google.cloud.dialogflow.v2.Agents.TrainAgent] and wait for the operation it returns in order to train explicitly.
Operation <response: [google.protobuf.Empty][google.protobuf.Empty]> An operation which tracks when importing is complete. It only tracks when the draft agent is updated not when it is done training.
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
ImportAgentRequest request =
ImportAgentRequest.newBuilder().setParent(AgentName.of("[PROJECT]").toString()).build();
agentsClient.importAgentAsync(request).get();
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final OperationCallable<ImportAgentRequest,Empty,Struct> importAgentOperationCallable()
Uploads new intents and entity types without deleting the existing ones. Intents and entity types with the same name are replaced with the new versions from [ImportAgentRequest][google.cloud.dialogflow.v2.ImportAgentRequest]. After the import, the imported draft agent will be trained automatically (unless disabled in agent settings). However, once the import is done, training may not be completed yet. Please call [TrainAgent][google.cloud.dialogflow.v2.Agents.TrainAgent] and wait for the operation it returns in order to train explicitly.
Operation <response: [google.protobuf.Empty][google.protobuf.Empty]> An operation which tracks when importing is complete. It only tracks when the draft agent is updated not when it is done training.
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
ImportAgentRequest request =
ImportAgentRequest.newBuilder().setParent(AgentName.of("[PROJECT]").toString()).build();
OperationFuture<Empty, Struct> future =
agentsClient.importAgentOperationCallable().futureCall(request);
// Do something.
future.get();
}
public final UnaryCallable<ImportAgentRequest,Operation> importAgentCallable()
Uploads new intents and entity types without deleting the existing ones. Intents and entity types with the same name are replaced with the new versions from [ImportAgentRequest][google.cloud.dialogflow.v2.ImportAgentRequest]. After the import, the imported draft agent will be trained automatically (unless disabled in agent settings). However, once the import is done, training may not be completed yet. Please call [TrainAgent][google.cloud.dialogflow.v2.Agents.TrainAgent] and wait for the operation it returns in order to train explicitly.
Operation <response: [google.protobuf.Empty][google.protobuf.Empty]> An operation which tracks when importing is complete. It only tracks when the draft agent is updated not when it is done training.
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
ImportAgentRequest request =
ImportAgentRequest.newBuilder().setParent(AgentName.of("[PROJECT]").toString()).build();
ApiFuture<Operation> future = agentsClient.importAgentCallable().futureCall(request);
// Do something.
future.get();
}
public final OperationFuture<Empty,Struct> restoreAgentAsync(RestoreAgentRequest request)
Replaces the current agent version with a new one. All the intents and entity types in the older version are deleted. After the restore, the restored draft agent will be trained automatically (unless disabled in agent settings). However, once the restore is done, training may not be completed yet. Please call [TrainAgent][google.cloud.dialogflow.v2.Agents.TrainAgent] and wait for the operation it returns in order to train explicitly.
Operation <response: [google.protobuf.Empty][google.protobuf.Empty]> An operation which tracks when restoring is complete. It only tracks when the draft agent is updated not when it is done training.
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
RestoreAgentRequest request =
RestoreAgentRequest.newBuilder().setParent(AgentName.of("[PROJECT]").toString()).build();
agentsClient.restoreAgentAsync(request).get();
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final OperationCallable<RestoreAgentRequest,Empty,Struct> restoreAgentOperationCallable()
Replaces the current agent version with a new one. All the intents and entity types in the older version are deleted. After the restore, the restored draft agent will be trained automatically (unless disabled in agent settings). However, once the restore is done, training may not be completed yet. Please call [TrainAgent][google.cloud.dialogflow.v2.Agents.TrainAgent] and wait for the operation it returns in order to train explicitly.
Operation <response: [google.protobuf.Empty][google.protobuf.Empty]> An operation which tracks when restoring is complete. It only tracks when the draft agent is updated not when it is done training.
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
RestoreAgentRequest request =
RestoreAgentRequest.newBuilder().setParent(AgentName.of("[PROJECT]").toString()).build();
OperationFuture<Empty, Struct> future =
agentsClient.restoreAgentOperationCallable().futureCall(request);
// Do something.
future.get();
}
public final UnaryCallable<RestoreAgentRequest,Operation> restoreAgentCallable()
Replaces the current agent version with a new one. All the intents and entity types in the older version are deleted. After the restore, the restored draft agent will be trained automatically (unless disabled in agent settings). However, once the restore is done, training may not be completed yet. Please call [TrainAgent][google.cloud.dialogflow.v2.Agents.TrainAgent] and wait for the operation it returns in order to train explicitly.
Operation <response: [google.protobuf.Empty][google.protobuf.Empty]> An operation which tracks when restoring is complete. It only tracks when the draft agent is updated not when it is done training.
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
RestoreAgentRequest request =
RestoreAgentRequest.newBuilder().setParent(AgentName.of("[PROJECT]").toString()).build();
ApiFuture<Operation> future = agentsClient.restoreAgentCallable().futureCall(request);
// Do something.
future.get();
}
public final ValidationResult getValidationResult(GetValidationResultRequest request)
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
GetValidationResultRequest request =
GetValidationResultRequest.newBuilder()
.setParent(AgentName.of("[PROJECT]").toString())
.setLanguageCode("languageCode-2092349083")
.build();
ValidationResult response = agentsClient.getValidationResult(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<GetValidationResultRequest,ValidationResult> getValidationResultCallable()
Sample code:
try (AgentsClient agentsClient = AgentsClient.create()) {
GetValidationResultRequest request =
GetValidationResultRequest.newBuilder()
.setParent(AgentName.of("[PROJECT]").toString())
.setLanguageCode("languageCode-2092349083")
.build();
ApiFuture<ValidationResult> future =
agentsClient.getValidationResultCallable().futureCall(request);
// Do something.
ValidationResult response = future.get();
}
public final void close()
close
in interface AutoCloseable
public void shutdown()
shutdown
in interface BackgroundResource
public boolean isShutdown()
isShutdown
in interface BackgroundResource
public boolean isTerminated()
isTerminated
in interface BackgroundResource
public void shutdownNow()
shutdownNow
in interface BackgroundResource
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
awaitTermination
in interface BackgroundResource
InterruptedException
Copyright © 2021 Google LLC. All rights reserved.