50
50
51
51
52
52
class AgentsClient (object ):
53
- """
54
- Agents are best described as Natural Language Understanding (NLU)
55
- modules that transform user requests into actionable data. You can
56
- include agents in your app, product, or service to determine user intent
57
- and respond to the user in a natural way.
58
-
59
- After you create an agent, you can add ``Intents``, ``Contexts``,
60
- ``Entity Types``, ``Webhooks``, and so on to manage the flow of a
61
- conversation and match user input to predefined intents and actions.
62
-
63
- You can create an agent using both Dialogflow Standard Edition and
64
- Dialogflow Enterprise Edition. For details, see `Dialogflow
65
- Editions <https://cloud.google.com/dialogflow/docs/editions>`__.
66
-
67
- You can save your agent for backup or versioning by exporting the agent
68
- by using the ``ExportAgent`` method. You can import a saved agent by
69
- using the ``ImportAgent`` method.
70
-
71
- Dialogflow provides several `prebuilt
72
- agents <https://cloud.google.com/dialogflow/docs/agents-prebuilt>`__ for
73
- common conversation scenarios such as determining a date and time,
74
- converting currency, and so on.
75
-
76
- For more information about agents, see the `Dialogflow
77
- documentation <https://cloud.google.com/dialogflow/docs/agents-overview>`__.
78
- """
53
+ """Service for managing ``Agents``."""
79
54
80
55
SERVICE_ADDRESS = "dialogflow.googleapis.com:443"
81
56
"""The default address of the service."""
@@ -224,36 +199,28 @@ def __init__(
224
199
self ._inner_api_calls = {}
225
200
226
201
# Service calls
227
- def set_agent (
202
+ def get_agent (
228
203
self ,
229
- agent ,
230
- update_mask = None ,
204
+ parent ,
231
205
retry = google .api_core .gapic_v1 .method .DEFAULT ,
232
206
timeout = google .api_core .gapic_v1 .method .DEFAULT ,
233
207
metadata = None ,
234
208
):
235
209
"""
236
- Creates/updates the specified agent.
210
+ Retrieves the specified agent.
237
211
238
212
Example:
239
213
>>> import dialogflow_v2
240
214
>>>
241
215
>>> client = dialogflow_v2.AgentsClient()
242
216
>>>
243
- >>> # TODO: Initialize `agent`:
244
- >>> agent = {}
217
+ >>> parent = client.project_path('[PROJECT]')
245
218
>>>
246
- >>> response = client.set_agent(agent )
219
+ >>> response = client.get_agent(parent )
247
220
248
221
Args:
249
- agent (Union[dict, ~google.cloud.dialogflow_v2.types.Agent]): Required. The agent to update.
250
-
251
- If a dict is provided, it must be of the same form as the protobuf
252
- message :class:`~google.cloud.dialogflow_v2.types.Agent`
253
- update_mask (Union[dict, ~google.cloud.dialogflow_v2.types.FieldMask]): Optional. The mask to control which fields get updated.
254
-
255
- If a dict is provided, it must be of the same form as the protobuf
256
- message :class:`~google.cloud.dialogflow_v2.types.FieldMask`
222
+ parent (str): Required. The project that the agent to fetch is associated with.
223
+ Format: ``projects/<Project ID>``.
257
224
retry (Optional[google.api_core.retry.Retry]): A retry object used
258
225
to retry requests. If ``None`` is specified, requests will
259
226
be retried using a default configuration.
@@ -274,22 +241,22 @@ def set_agent(
274
241
ValueError: If the parameters are invalid.
275
242
"""
276
243
# Wrap the transport method to add retry and timeout logic.
277
- if "set_agent " not in self ._inner_api_calls :
244
+ if "get_agent " not in self ._inner_api_calls :
278
245
self ._inner_api_calls [
279
- "set_agent "
246
+ "get_agent "
280
247
] = google .api_core .gapic_v1 .method .wrap_method (
281
- self .transport .set_agent ,
282
- default_retry = self ._method_configs ["SetAgent " ].retry ,
283
- default_timeout = self ._method_configs ["SetAgent " ].timeout ,
248
+ self .transport .get_agent ,
249
+ default_retry = self ._method_configs ["GetAgent " ].retry ,
250
+ default_timeout = self ._method_configs ["GetAgent " ].timeout ,
284
251
client_info = self ._client_info ,
285
252
)
286
253
287
- request = agent_pb2 .SetAgentRequest ( agent = agent , update_mask = update_mask )
254
+ request = agent_pb2 .GetAgentRequest ( parent = parent )
288
255
if metadata is None :
289
256
metadata = []
290
257
metadata = list (metadata )
291
258
try :
292
- routing_header = [("agent. parent" , agent . parent )]
259
+ routing_header = [("parent" , parent )]
293
260
except AttributeError :
294
261
pass
295
262
else :
@@ -298,32 +265,40 @@ def set_agent(
298
265
)
299
266
metadata .append (routing_metadata )
300
267
301
- return self ._inner_api_calls ["set_agent " ](
268
+ return self ._inner_api_calls ["get_agent " ](
302
269
request , retry = retry , timeout = timeout , metadata = metadata
303
270
)
304
271
305
- def delete_agent (
272
+ def set_agent (
306
273
self ,
307
- parent ,
274
+ agent ,
275
+ update_mask = None ,
308
276
retry = google .api_core .gapic_v1 .method .DEFAULT ,
309
277
timeout = google .api_core .gapic_v1 .method .DEFAULT ,
310
278
metadata = None ,
311
279
):
312
280
"""
313
- Deletes the specified agent.
281
+ Creates/updates the specified agent.
314
282
315
283
Example:
316
284
>>> import dialogflow_v2
317
285
>>>
318
286
>>> client = dialogflow_v2.AgentsClient()
319
287
>>>
320
- >>> parent = client.project_path('[PROJECT]')
288
+ >>> # TODO: Initialize `agent`:
289
+ >>> agent = {}
321
290
>>>
322
- >>> client.delete_agent(parent )
291
+ >>> response = client.set_agent(agent )
323
292
324
293
Args:
325
- parent (str): Required. The project that the agent to delete is associated with.
326
- Format: ``projects/<Project ID>``.
294
+ agent (Union[dict, ~google.cloud.dialogflow_v2.types.Agent]): Required. The agent to update.
295
+
296
+ If a dict is provided, it must be of the same form as the protobuf
297
+ message :class:`~google.cloud.dialogflow_v2.types.Agent`
298
+ update_mask (Union[dict, ~google.cloud.dialogflow_v2.types.FieldMask]): Optional. The mask to control which fields get updated.
299
+
300
+ If a dict is provided, it must be of the same form as the protobuf
301
+ message :class:`~google.cloud.dialogflow_v2.types.FieldMask`
327
302
retry (Optional[google.api_core.retry.Retry]): A retry object used
328
303
to retry requests. If ``None`` is specified, requests will
329
304
be retried using a default configuration.
@@ -333,6 +308,9 @@ def delete_agent(
333
308
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
334
309
that is provided to the method.
335
310
311
+ Returns:
312
+ A :class:`~google.cloud.dialogflow_v2.types.Agent` instance.
313
+
336
314
Raises:
337
315
google.api_core.exceptions.GoogleAPICallError: If the request
338
316
failed for any reason.
@@ -341,22 +319,22 @@ def delete_agent(
341
319
ValueError: If the parameters are invalid.
342
320
"""
343
321
# Wrap the transport method to add retry and timeout logic.
344
- if "delete_agent " not in self ._inner_api_calls :
322
+ if "set_agent " not in self ._inner_api_calls :
345
323
self ._inner_api_calls [
346
- "delete_agent "
324
+ "set_agent "
347
325
] = google .api_core .gapic_v1 .method .wrap_method (
348
- self .transport .delete_agent ,
349
- default_retry = self ._method_configs ["DeleteAgent " ].retry ,
350
- default_timeout = self ._method_configs ["DeleteAgent " ].timeout ,
326
+ self .transport .set_agent ,
327
+ default_retry = self ._method_configs ["SetAgent " ].retry ,
328
+ default_timeout = self ._method_configs ["SetAgent " ].timeout ,
351
329
client_info = self ._client_info ,
352
330
)
353
331
354
- request = agent_pb2 .DeleteAgentRequest ( parent = parent )
332
+ request = agent_pb2 .SetAgentRequest ( agent = agent , update_mask = update_mask )
355
333
if metadata is None :
356
334
metadata = []
357
335
metadata = list (metadata )
358
336
try :
359
- routing_header = [("parent" , parent )]
337
+ routing_header = [("agent. parent" , agent . parent )]
360
338
except AttributeError :
361
339
pass
362
340
else :
@@ -365,19 +343,19 @@ def delete_agent(
365
343
)
366
344
metadata .append (routing_metadata )
367
345
368
- self ._inner_api_calls ["delete_agent " ](
346
+ return self ._inner_api_calls ["set_agent " ](
369
347
request , retry = retry , timeout = timeout , metadata = metadata
370
348
)
371
349
372
- def get_agent (
350
+ def delete_agent (
373
351
self ,
374
352
parent ,
375
353
retry = google .api_core .gapic_v1 .method .DEFAULT ,
376
354
timeout = google .api_core .gapic_v1 .method .DEFAULT ,
377
355
metadata = None ,
378
356
):
379
357
"""
380
- Retrieves the specified agent.
358
+ Deletes the specified agent.
381
359
382
360
Example:
383
361
>>> import dialogflow_v2
@@ -386,10 +364,10 @@ def get_agent(
386
364
>>>
387
365
>>> parent = client.project_path('[PROJECT]')
388
366
>>>
389
- >>> response = client.get_agent (parent)
367
+ >>> client.delete_agent (parent)
390
368
391
369
Args:
392
- parent (str): Required. The project that the agent to fetch is associated with.
370
+ parent (str): Required. The project that the agent to delete is associated with.
393
371
Format: ``projects/<Project ID>``.
394
372
retry (Optional[google.api_core.retry.Retry]): A retry object used
395
373
to retry requests. If ``None`` is specified, requests will
@@ -400,9 +378,6 @@ def get_agent(
400
378
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
401
379
that is provided to the method.
402
380
403
- Returns:
404
- A :class:`~google.cloud.dialogflow_v2.types.Agent` instance.
405
-
406
381
Raises:
407
382
google.api_core.exceptions.GoogleAPICallError: If the request
408
383
failed for any reason.
@@ -411,17 +386,17 @@ def get_agent(
411
386
ValueError: If the parameters are invalid.
412
387
"""
413
388
# Wrap the transport method to add retry and timeout logic.
414
- if "get_agent " not in self ._inner_api_calls :
389
+ if "delete_agent " not in self ._inner_api_calls :
415
390
self ._inner_api_calls [
416
- "get_agent "
391
+ "delete_agent "
417
392
] = google .api_core .gapic_v1 .method .wrap_method (
418
- self .transport .get_agent ,
419
- default_retry = self ._method_configs ["GetAgent " ].retry ,
420
- default_timeout = self ._method_configs ["GetAgent " ].timeout ,
393
+ self .transport .delete_agent ,
394
+ default_retry = self ._method_configs ["DeleteAgent " ].retry ,
395
+ default_timeout = self ._method_configs ["DeleteAgent " ].timeout ,
421
396
client_info = self ._client_info ,
422
397
)
423
398
424
- request = agent_pb2 .GetAgentRequest (parent = parent )
399
+ request = agent_pb2 .DeleteAgentRequest (parent = parent )
425
400
if metadata is None :
426
401
metadata = []
427
402
metadata = list (metadata )
@@ -435,7 +410,7 @@ def get_agent(
435
410
)
436
411
metadata .append (routing_metadata )
437
412
438
- return self ._inner_api_calls ["get_agent " ](
413
+ self ._inner_api_calls ["delete_agent " ](
439
414
request , retry = retry , timeout = timeout , metadata = metadata
440
415
)
441
416
@@ -654,7 +629,10 @@ def export_agent(
654
629
>>>
655
630
>>> parent = client.project_path('[PROJECT]')
656
631
>>>
657
- >>> response = client.export_agent(parent)
632
+ >>> # TODO: Initialize `agent_uri`:
633
+ >>> agent_uri = ''
634
+ >>>
635
+ >>> response = client.export_agent(parent, agent_uri)
658
636
>>>
659
637
>>> def callback(operation_future):
660
638
... # Handle result.
@@ -741,9 +719,15 @@ def import_agent(
741
719
742
720
Uploads new intents and entity types without deleting the existing ones.
743
721
Intents and entity types with the same name are replaced with the new
744
- versions from ImportAgentRequest.
722
+ versions from ``ImportAgentRequest``. After the import, the imported
723
+ draft agent will be trained automatically (unless disabled in agent
724
+ settings). However, once the import is done, training may not be
725
+ completed yet. Please call ``TrainAgent`` and wait for the operation it
726
+ returns in order to train explicitly.
745
727
746
- Operation <response: ``google.protobuf.Empty``>
728
+ Operation <response: ``google.protobuf.Empty``> An operation which
729
+ tracks when importing is complete. It only tracks when the draft agent
730
+ is updated not when it is done training.
747
731
748
732
Example:
749
733
>>> import dialogflow_v2
@@ -844,9 +828,15 @@ def restore_agent(
844
828
Restores the specified agent from a ZIP file.
845
829
846
830
Replaces the current agent version with a new one. All the intents and
847
- entity types in the older version are deleted.
831
+ entity types in the older version are deleted. After the restore, the
832
+ restored draft agent will be trained automatically (unless disabled in
833
+ agent settings). However, once the restore is done, training may not be
834
+ completed yet. Please call ``TrainAgent`` and wait for the operation it
835
+ returns in order to train explicitly.
848
836
849
- Operation <response: ``google.protobuf.Empty``>
837
+ Operation <response: ``google.protobuf.Empty``> An operation which
838
+ tracks when restoring is complete. It only tracks when the draft agent
839
+ is updated not when it is done training.
850
840
851
841
Example:
852
842
>>> import dialogflow_v2
@@ -951,13 +941,15 @@ def get_validation_result(
951
941
>>>
952
942
>>> client = dialogflow_v2.AgentsClient()
953
943
>>>
954
- >>> response = client.get_validation_result()
944
+ >>> parent = client.project_path('[PROJECT]')
945
+ >>>
946
+ >>> response = client.get_validation_result(parent)
955
947
956
948
Args:
957
949
parent (str): Required. The project that the agent is associated with. Format:
958
950
``projects/<Project ID>``.
959
- language_code (str): Optional. The language for which you want a validation result. If not
960
- specified, the agent's default language is used. `Many
951
+ language_code (str): Optional. The language for which you want a validation result. If
952
+ not specified, the agent's default language is used. `Many
961
953
languages <https://cloud.google.com/dialogflow/docs/reference/language>`__
962
954
are supported. Note: languages must be enabled in the agent before they
963
955
can be used.
0 commit comments