google-cloud-agentplatform 1.165.1.dev0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. agentplatform/__init__.py +72 -0
  2. agentplatform/_genai/__init__.py +43 -0
  3. agentplatform/_genai/_agent_engines_utils.py +2341 -0
  4. agentplatform/_genai/_bigquery_utils.py +49 -0
  5. agentplatform/_genai/_datasets_utils.py +344 -0
  6. agentplatform/_genai/_evals_builtin_tools.py +209 -0
  7. agentplatform/_genai/_evals_common.py +4268 -0
  8. agentplatform/_genai/_evals_constant.py +122 -0
  9. agentplatform/_genai/_evals_data_converters.py +926 -0
  10. agentplatform/_genai/_evals_metric_handlers.py +1783 -0
  11. agentplatform/_genai/_evals_metric_loaders.py +401 -0
  12. agentplatform/_genai/_evals_utils.py +1043 -0
  13. agentplatform/_genai/_evals_visualization.py +2070 -0
  14. agentplatform/_genai/_gcs_utils.py +262 -0
  15. agentplatform/_genai/_logging_utils.py +47 -0
  16. agentplatform/_genai/_memory_bank_utils.py +206 -0
  17. agentplatform/_genai/_observability_data_converter.py +186 -0
  18. agentplatform/_genai/_operations_utils.py +94 -0
  19. agentplatform/_genai/_prompt_management_utils.py +147 -0
  20. agentplatform/_genai/_prompt_optimizer_utils.py +215 -0
  21. agentplatform/_genai/_skills_utils.py +69 -0
  22. agentplatform/_genai/_transformers.py +628 -0
  23. agentplatform/_genai/a2a_task_events.py +509 -0
  24. agentplatform/_genai/a2a_tasks.py +861 -0
  25. agentplatform/_genai/agent_engines.py +3931 -0
  26. agentplatform/_genai/client.py +519 -0
  27. agentplatform/_genai/datasets.py +3045 -0
  28. agentplatform/_genai/endpoints.py +1149 -0
  29. agentplatform/_genai/evals.py +6883 -0
  30. agentplatform/_genai/example_stores.py +1445 -0
  31. agentplatform/_genai/feedback_contexts.py +700 -0
  32. agentplatform/_genai/feedback_entries.py +1644 -0
  33. agentplatform/_genai/live.py +64 -0
  34. agentplatform/_genai/live_agent_engines.py +179 -0
  35. agentplatform/_genai/memories.py +2962 -0
  36. agentplatform/_genai/memory_banks.py +1927 -0
  37. agentplatform/_genai/memory_revisions.py +465 -0
  38. agentplatform/_genai/model_garden.py +2638 -0
  39. agentplatform/_genai/prompt_optimizer.py +995 -0
  40. agentplatform/_genai/prompts.py +4515 -0
  41. agentplatform/_genai/rag.py +4961 -0
  42. agentplatform/_genai/runtime_revisions.py +1257 -0
  43. agentplatform/_genai/runtimes.py +78 -0
  44. agentplatform/_genai/sandbox_snapshots.py +1015 -0
  45. agentplatform/_genai/sandbox_templates.py +1088 -0
  46. agentplatform/_genai/sandboxes.py +1604 -0
  47. agentplatform/_genai/session_events.py +543 -0
  48. agentplatform/_genai/sessions.py +1449 -0
  49. agentplatform/_genai/skill_revisions.py +377 -0
  50. agentplatform/_genai/skills.py +1708 -0
  51. agentplatform/_genai/types/__init__.py +4695 -0
  52. agentplatform/_genai/types/agent_engines.py +16 -0
  53. agentplatform/_genai/types/common.py +32784 -0
  54. agentplatform/_genai/types/evals.py +1031 -0
  55. agentplatform/_genai/types/prompt_optimizer.py +107 -0
  56. agentplatform/_genai/types/prompts.py +107 -0
  57. agentplatform/version.py +17 -0
  58. google_cloud_agentplatform-1.165.1.dev0.dist-info/METADATA +79 -0
  59. google_cloud_agentplatform-1.165.1.dev0.dist-info/RECORD +62 -0
  60. google_cloud_agentplatform-1.165.1.dev0.dist-info/WHEEL +5 -0
  61. google_cloud_agentplatform-1.165.1.dev0.dist-info/licenses/LICENSE +202 -0
  62. google_cloud_agentplatform-1.165.1.dev0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1015 @@
1
+ # Copyright 2025 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
15
+
16
+ # Code generated by the Google Gen AI SDK generator DO NOT EDIT.
17
+
18
+ import functools
19
+ import json
20
+ import logging
21
+ from typing import Any, Iterator, Optional, Union
22
+ from urllib.parse import urlencode
23
+
24
+ from google.genai import _api_module
25
+ from google.genai import _common
26
+ from google.genai._common import get_value_by_path as getv
27
+ from google.genai._common import set_value_by_path as setv
28
+ from google.genai.pagers import Pager
29
+
30
+ from . import _agent_engines_utils
31
+ from . import types
32
+
33
+ logger = logging.getLogger("agentplatform_genai.sandboxsnapshots")
34
+
35
+ logger.setLevel(logging.INFO)
36
+
37
+
38
+ def _CreateAgentEngineSandboxSnapshotConfig_to_vertex(
39
+ from_object: Union[dict[str, Any], object],
40
+ parent_object: Optional[dict[str, Any]] = None,
41
+ ) -> dict[str, Any]:
42
+ to_object: dict[str, Any] = {}
43
+
44
+ if getv(from_object, ["display_name"]) is not None:
45
+ setv(parent_object, ["displayName"], getv(from_object, ["display_name"]))
46
+
47
+ if getv(from_object, ["owner"]) is not None:
48
+ setv(parent_object, ["owner"], getv(from_object, ["owner"]))
49
+
50
+ if getv(from_object, ["ttl"]) is not None:
51
+ setv(parent_object, ["ttl"], getv(from_object, ["ttl"]))
52
+
53
+ return to_object
54
+
55
+
56
+ def _CreateSandboxEnvironmentSnapshotRequestParameters_to_vertex(
57
+ from_object: Union[dict[str, Any], object],
58
+ parent_object: Optional[dict[str, Any]] = None,
59
+ ) -> dict[str, Any]:
60
+ to_object: dict[str, Any] = {}
61
+ if getv(from_object, ["source_sandbox_environment_name"]) is not None:
62
+ setv(
63
+ to_object,
64
+ ["_url", "name"],
65
+ getv(from_object, ["source_sandbox_environment_name"]),
66
+ )
67
+
68
+ if getv(from_object, ["config"]) is not None:
69
+ _CreateAgentEngineSandboxSnapshotConfig_to_vertex(
70
+ getv(from_object, ["config"]), to_object
71
+ )
72
+
73
+ return to_object
74
+
75
+
76
+ def _DeleteSandboxEnvironmentSnapshotRequestParameters_to_vertex(
77
+ from_object: Union[dict[str, Any], object],
78
+ parent_object: Optional[dict[str, Any]] = None,
79
+ ) -> dict[str, Any]:
80
+ to_object: dict[str, Any] = {}
81
+ if getv(from_object, ["name"]) is not None:
82
+ setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
83
+
84
+ return to_object
85
+
86
+
87
+ def _GetAgentEngineSandboxSnapshotOperationParameters_to_vertex(
88
+ from_object: Union[dict[str, Any], object],
89
+ parent_object: Optional[dict[str, Any]] = None,
90
+ ) -> dict[str, Any]:
91
+ to_object: dict[str, Any] = {}
92
+ if getv(from_object, ["operation_name"]) is not None:
93
+ setv(
94
+ to_object, ["_url", "operationName"], getv(from_object, ["operation_name"])
95
+ )
96
+
97
+ return to_object
98
+
99
+
100
+ def _GetSandboxEnvironmentSnapshotRequestParameters_to_vertex(
101
+ from_object: Union[dict[str, Any], object],
102
+ parent_object: Optional[dict[str, Any]] = None,
103
+ ) -> dict[str, Any]:
104
+ to_object: dict[str, Any] = {}
105
+ if getv(from_object, ["name"]) is not None:
106
+ setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
107
+
108
+ return to_object
109
+
110
+
111
+ def _ListSandboxEnvironmentSnapshotsConfig_to_vertex(
112
+ from_object: Union[dict[str, Any], object],
113
+ parent_object: Optional[dict[str, Any]] = None,
114
+ ) -> dict[str, Any]:
115
+ to_object: dict[str, Any] = {}
116
+
117
+ if getv(from_object, ["page_size"]) is not None:
118
+ setv(parent_object, ["_query", "pageSize"], getv(from_object, ["page_size"]))
119
+
120
+ if getv(from_object, ["page_token"]) is not None:
121
+ setv(parent_object, ["_query", "pageToken"], getv(from_object, ["page_token"]))
122
+
123
+ if getv(from_object, ["filter"]) is not None:
124
+ setv(parent_object, ["_query", "filter"], getv(from_object, ["filter"]))
125
+
126
+ return to_object
127
+
128
+
129
+ def _ListSandboxEnvironmentSnapshotsRequestParameters_to_vertex(
130
+ from_object: Union[dict[str, Any], object],
131
+ parent_object: Optional[dict[str, Any]] = None,
132
+ ) -> dict[str, Any]:
133
+ to_object: dict[str, Any] = {}
134
+ if getv(from_object, ["name"]) is not None:
135
+ setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
136
+
137
+ if getv(from_object, ["config"]) is not None:
138
+ _ListSandboxEnvironmentSnapshotsConfig_to_vertex(
139
+ getv(from_object, ["config"]), to_object
140
+ )
141
+
142
+ return to_object
143
+
144
+
145
+ class SandboxSnapshots(_api_module.BaseModule):
146
+ """Sandbox environment snapshot commands."""
147
+
148
+ def _create(
149
+ self,
150
+ *,
151
+ source_sandbox_environment_name: str,
152
+ config: Optional[types.CreateAgentEngineSandboxSnapshotConfigOrDict] = None,
153
+ ) -> types.AgentEngineSandboxSnapshotOperation:
154
+ """
155
+ Snapshots an existing sandbox environment.
156
+
157
+ Args:
158
+ source_sandbox_environment_name (str):
159
+ Required. The name of the sandbox environment to snapshot.
160
+ projects/{project}/locations/{location}/reasoningEngines/{resource_id}/sandboxEnvironments/{sandbox_environment_id}
161
+ config (CreateAgentEngineSandboxSnapshotConfig):
162
+ Optional. The configuration for the sandbox snapshot.
163
+
164
+ """
165
+
166
+ parameter_model = types._CreateSandboxEnvironmentSnapshotRequestParameters(
167
+ source_sandbox_environment_name=source_sandbox_environment_name,
168
+ config=config,
169
+ )
170
+
171
+ request_url_dict: Optional[dict[str, str]]
172
+ if not self._api_client.vertexai:
173
+ raise ValueError(
174
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
175
+ )
176
+ else:
177
+ request_dict = _CreateSandboxEnvironmentSnapshotRequestParameters_to_vertex(
178
+ parameter_model
179
+ )
180
+ request_url_dict = request_dict.get("_url")
181
+ if request_url_dict:
182
+ path = "{name}:snapshot".format_map(request_url_dict)
183
+ else:
184
+ path = "{name}:snapshot"
185
+
186
+ query_params = request_dict.get("_query")
187
+ if query_params:
188
+ path = f"{path}?{urlencode(query_params)}"
189
+ # TODO: remove the hack that pops config.
190
+ request_dict.pop("config", None)
191
+
192
+ http_options: Optional[types.HttpOptions] = None
193
+ if (
194
+ parameter_model.config is not None
195
+ and parameter_model.config.http_options is not None
196
+ ):
197
+ http_options = parameter_model.config.http_options
198
+
199
+ request_dict = _common.convert_to_dict(request_dict)
200
+ request_dict = _common.encode_unserializable_types(request_dict)
201
+
202
+ response = self._api_client.request("post", path, request_dict, http_options)
203
+
204
+ response_dict = {} if not response.body else json.loads(response.body)
205
+
206
+ return_value = types.AgentEngineSandboxSnapshotOperation._from_response(
207
+ response=response_dict,
208
+ kwargs=(
209
+ {
210
+ "config": {
211
+ "response_schema": getattr(
212
+ parameter_model.config, "response_schema", None
213
+ ),
214
+ "response_json_schema": getattr(
215
+ parameter_model.config, "response_json_schema", None
216
+ ),
217
+ "include_all_fields": getattr(
218
+ parameter_model.config, "include_all_fields", None
219
+ ),
220
+ }
221
+ }
222
+ if getattr(parameter_model, "config", None)
223
+ else {}
224
+ ),
225
+ )
226
+
227
+ self._api_client._verify_response(return_value)
228
+ return return_value
229
+
230
+ def _delete(
231
+ self,
232
+ *,
233
+ name: str,
234
+ config: Optional[types.DeleteSandboxEnvironmentSnapshotConfigOrDict] = None,
235
+ ) -> types.DeleteSandboxEnvironmentSnapshotOperation:
236
+ """
237
+ Deletes a sandbox environment snapshot.
238
+
239
+ """
240
+
241
+ parameter_model = types._DeleteSandboxEnvironmentSnapshotRequestParameters(
242
+ name=name,
243
+ config=config,
244
+ )
245
+
246
+ request_url_dict: Optional[dict[str, str]]
247
+ if not self._api_client.vertexai:
248
+ raise ValueError(
249
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
250
+ )
251
+ else:
252
+ request_dict = _DeleteSandboxEnvironmentSnapshotRequestParameters_to_vertex(
253
+ parameter_model
254
+ )
255
+ request_url_dict = request_dict.get("_url")
256
+ if request_url_dict:
257
+ path = "{name}".format_map(request_url_dict)
258
+ else:
259
+ path = "{name}"
260
+
261
+ query_params = request_dict.get("_query")
262
+ if query_params:
263
+ path = f"{path}?{urlencode(query_params)}"
264
+ # TODO: remove the hack that pops config.
265
+ request_dict.pop("config", None)
266
+
267
+ http_options: Optional[types.HttpOptions] = None
268
+ if (
269
+ parameter_model.config is not None
270
+ and parameter_model.config.http_options is not None
271
+ ):
272
+ http_options = parameter_model.config.http_options
273
+
274
+ request_dict = _common.convert_to_dict(request_dict)
275
+ request_dict = _common.encode_unserializable_types(request_dict)
276
+
277
+ response = self._api_client.request("delete", path, request_dict, http_options)
278
+
279
+ response_dict = {} if not response.body else json.loads(response.body)
280
+
281
+ return_value = types.DeleteSandboxEnvironmentSnapshotOperation._from_response(
282
+ response=response_dict,
283
+ kwargs=(
284
+ {
285
+ "config": {
286
+ "response_schema": getattr(
287
+ parameter_model.config, "response_schema", None
288
+ ),
289
+ "response_json_schema": getattr(
290
+ parameter_model.config, "response_json_schema", None
291
+ ),
292
+ "include_all_fields": getattr(
293
+ parameter_model.config, "include_all_fields", None
294
+ ),
295
+ }
296
+ }
297
+ if getattr(parameter_model, "config", None)
298
+ else {}
299
+ ),
300
+ )
301
+
302
+ self._api_client._verify_response(return_value)
303
+ return return_value
304
+
305
+ def _get(
306
+ self,
307
+ *,
308
+ name: str,
309
+ config: Optional[types.GetSandboxEnvironmentSnapshotConfigOrDict] = None,
310
+ ) -> types.SandboxEnvironmentSnapshot:
311
+ """
312
+ Gets a sandbox environment snapshot.
313
+
314
+ """
315
+
316
+ parameter_model = types._GetSandboxEnvironmentSnapshotRequestParameters(
317
+ name=name,
318
+ config=config,
319
+ )
320
+
321
+ request_url_dict: Optional[dict[str, str]]
322
+ if not self._api_client.vertexai:
323
+ raise ValueError(
324
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
325
+ )
326
+ else:
327
+ request_dict = _GetSandboxEnvironmentSnapshotRequestParameters_to_vertex(
328
+ parameter_model
329
+ )
330
+ request_url_dict = request_dict.get("_url")
331
+ if request_url_dict:
332
+ path = "{name}".format_map(request_url_dict)
333
+ else:
334
+ path = "{name}"
335
+
336
+ query_params = request_dict.get("_query")
337
+ if query_params:
338
+ path = f"{path}?{urlencode(query_params)}"
339
+ # TODO: remove the hack that pops config.
340
+ request_dict.pop("config", None)
341
+
342
+ http_options: Optional[types.HttpOptions] = None
343
+ if (
344
+ parameter_model.config is not None
345
+ and parameter_model.config.http_options is not None
346
+ ):
347
+ http_options = parameter_model.config.http_options
348
+
349
+ request_dict = _common.convert_to_dict(request_dict)
350
+ request_dict = _common.encode_unserializable_types(request_dict)
351
+
352
+ response = self._api_client.request("get", path, request_dict, http_options)
353
+
354
+ response_dict = {} if not response.body else json.loads(response.body)
355
+
356
+ return_value = types.SandboxEnvironmentSnapshot._from_response(
357
+ response=response_dict,
358
+ kwargs=(
359
+ {
360
+ "config": {
361
+ "response_schema": getattr(
362
+ parameter_model.config, "response_schema", None
363
+ ),
364
+ "response_json_schema": getattr(
365
+ parameter_model.config, "response_json_schema", None
366
+ ),
367
+ "include_all_fields": getattr(
368
+ parameter_model.config, "include_all_fields", None
369
+ ),
370
+ }
371
+ }
372
+ if getattr(parameter_model, "config", None)
373
+ else {}
374
+ ),
375
+ )
376
+
377
+ self._api_client._verify_response(return_value)
378
+ return return_value
379
+
380
+ def _list(
381
+ self,
382
+ *,
383
+ name: str,
384
+ config: Optional[types.ListSandboxEnvironmentSnapshotsConfigOrDict] = None,
385
+ ) -> types.ListSandboxEnvironmentSnapshotsResponse:
386
+ """
387
+ Lists sandbox environment snapshots.
388
+
389
+ """
390
+
391
+ parameter_model = types._ListSandboxEnvironmentSnapshotsRequestParameters(
392
+ name=name,
393
+ config=config,
394
+ )
395
+
396
+ request_url_dict: Optional[dict[str, str]]
397
+ if not self._api_client.vertexai:
398
+ raise ValueError(
399
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
400
+ )
401
+ else:
402
+ request_dict = _ListSandboxEnvironmentSnapshotsRequestParameters_to_vertex(
403
+ parameter_model
404
+ )
405
+ request_url_dict = request_dict.get("_url")
406
+ if request_url_dict:
407
+ path = "{name}/sandboxEnvironmentSnapshots".format_map(request_url_dict)
408
+ else:
409
+ path = "{name}/sandboxEnvironmentSnapshots"
410
+
411
+ query_params = request_dict.get("_query")
412
+ if query_params:
413
+ path = f"{path}?{urlencode(query_params)}"
414
+ # TODO: remove the hack that pops config.
415
+ request_dict.pop("config", None)
416
+
417
+ http_options: Optional[types.HttpOptions] = None
418
+ if (
419
+ parameter_model.config is not None
420
+ and parameter_model.config.http_options is not None
421
+ ):
422
+ http_options = parameter_model.config.http_options
423
+
424
+ request_dict = _common.convert_to_dict(request_dict)
425
+ request_dict = _common.encode_unserializable_types(request_dict)
426
+
427
+ response = self._api_client.request("get", path, request_dict, http_options)
428
+
429
+ response_dict = {} if not response.body else json.loads(response.body)
430
+
431
+ return_value = types.ListSandboxEnvironmentSnapshotsResponse._from_response(
432
+ response=response_dict,
433
+ kwargs=(
434
+ {
435
+ "config": {
436
+ "response_schema": getattr(
437
+ parameter_model.config, "response_schema", None
438
+ ),
439
+ "response_json_schema": getattr(
440
+ parameter_model.config, "response_json_schema", None
441
+ ),
442
+ "include_all_fields": getattr(
443
+ parameter_model.config, "include_all_fields", None
444
+ ),
445
+ }
446
+ }
447
+ if getattr(parameter_model, "config", None)
448
+ else {}
449
+ ),
450
+ )
451
+
452
+ self._api_client._verify_response(return_value)
453
+ return return_value
454
+
455
+ def get_sandbox_snapshot_operation(
456
+ self,
457
+ *,
458
+ operation_name: str,
459
+ config: Optional[types.GetAgentEngineOperationConfigOrDict] = None,
460
+ ) -> types.AgentEngineSandboxSnapshotOperation:
461
+ parameter_model = types._GetAgentEngineSandboxSnapshotOperationParameters(
462
+ operation_name=operation_name,
463
+ config=config,
464
+ )
465
+
466
+ request_url_dict: Optional[dict[str, str]]
467
+ if not self._api_client.vertexai:
468
+ raise ValueError(
469
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
470
+ )
471
+ else:
472
+ request_dict = _GetAgentEngineSandboxSnapshotOperationParameters_to_vertex(
473
+ parameter_model
474
+ )
475
+ request_url_dict = request_dict.get("_url")
476
+ if request_url_dict:
477
+ path = "{operationName}".format_map(request_url_dict)
478
+ else:
479
+ path = "{operationName}"
480
+
481
+ query_params = request_dict.get("_query")
482
+ if query_params:
483
+ path = f"{path}?{urlencode(query_params)}"
484
+ # TODO: remove the hack that pops config.
485
+ request_dict.pop("config", None)
486
+
487
+ http_options: Optional[types.HttpOptions] = None
488
+ if (
489
+ parameter_model.config is not None
490
+ and parameter_model.config.http_options is not None
491
+ ):
492
+ http_options = parameter_model.config.http_options
493
+
494
+ request_dict = _common.convert_to_dict(request_dict)
495
+ request_dict = _common.encode_unserializable_types(request_dict)
496
+
497
+ response = self._api_client.request("get", path, request_dict, http_options)
498
+
499
+ response_dict = {} if not response.body else json.loads(response.body)
500
+
501
+ return_value = types.AgentEngineSandboxSnapshotOperation._from_response(
502
+ response=response_dict,
503
+ kwargs=(
504
+ {
505
+ "config": {
506
+ "response_schema": getattr(
507
+ parameter_model.config, "response_schema", None
508
+ ),
509
+ "response_json_schema": getattr(
510
+ parameter_model.config, "response_json_schema", None
511
+ ),
512
+ "include_all_fields": getattr(
513
+ parameter_model.config, "include_all_fields", None
514
+ ),
515
+ }
516
+ }
517
+ if getattr(parameter_model, "config", None)
518
+ else {}
519
+ ),
520
+ )
521
+
522
+ self._api_client._verify_response(return_value)
523
+ return return_value
524
+
525
+ def create(
526
+ self,
527
+ *,
528
+ source_sandbox_environment_name: str,
529
+ config: Optional[types.CreateAgentEngineSandboxSnapshotConfigOrDict] = None,
530
+ poll_interval_seconds: float = 0.1,
531
+ ) -> types.AgentEngineSandboxSnapshotOperation:
532
+ """Snapshots an existing sandbox environment.
533
+
534
+ Args:
535
+ source_sandbox_environment_name (str):
536
+ Required. The name of the sandbox environment to snapshot.
537
+ projects/{project}/locations/{location}/reasoningEngines/{resource_id}/sandboxEnvironments/{sandbox_environment_id}
538
+ config (CreateAgentEngineSandboxSnapshotConfig):
539
+ Optional. The configuration for the sandbox snapshot.
540
+ poll_interval_seconds (int):
541
+ Optional. Seconds to wait between polling for operation status. Defaults to 0.1.
542
+
543
+ Returns:
544
+ AgentEngineSandboxSnapshotOperation: The operation for creating the sandbox snapshot.
545
+ """
546
+ operation = self._create(
547
+ source_sandbox_environment_name=source_sandbox_environment_name,
548
+ config=config,
549
+ )
550
+ if config is None:
551
+ config = types.CreateAgentEngineSandboxSnapshotConfig()
552
+ elif isinstance(config, dict):
553
+ config = types.CreateAgentEngineSandboxSnapshotConfig.model_validate(config)
554
+ if config.wait_for_completion:
555
+ if not operation.done:
556
+ operation = _agent_engines_utils._await_operation(
557
+ operation_name=operation.name,
558
+ get_operation_fn=self.get_sandbox_snapshot_operation,
559
+ poll_interval_seconds=poll_interval_seconds,
560
+ )
561
+ # We need to make a call to get the sandbox snapshot because the operation
562
+ # response might not contain the relevant fields.
563
+ if not operation.response:
564
+ raise ValueError("Error retrieving sandbox snapshot.")
565
+ operation.response = self.get(name=operation.response.name)
566
+ return operation
567
+
568
+ def list(
569
+ self,
570
+ *,
571
+ name: str,
572
+ config: Optional[types.ListSandboxEnvironmentSnapshotsConfigOrDict] = None,
573
+ ) -> Iterator[types.SandboxEnvironmentSnapshot]:
574
+ """Lists Agent Engine sandbox snapshots.
575
+
576
+ Args:
577
+ name (str):
578
+ Required. The name of the agent engine to list sandbox snapshots for.
579
+ projects/{project}/locations/{location}/reasoningEngines/{resource_id}
580
+ config (ListSandboxEnvironmentSnapshotsConfig):
581
+ Optional. The configuration for the sandbox snapshots to list.
582
+
583
+ Returns:
584
+ Iterable[SandboxEnvironmentSnapshot]: An iterable of agent engine sandbox snapshots.
585
+ """
586
+ return Pager(
587
+ "sandbox_environment_snapshots",
588
+ functools.partial(self._list, name=name),
589
+ self._list(name=name, config=config),
590
+ config,
591
+ )
592
+
593
+ def get(
594
+ self,
595
+ *,
596
+ name: str,
597
+ config: Optional[types.GetSandboxEnvironmentSnapshotConfigOrDict] = None,
598
+ ) -> types.SandboxEnvironmentSnapshot:
599
+ """Gets a sandbox snapshot in the Agent Engine.
600
+ Args:
601
+ name (str):
602
+ Required. A fully-qualified resource name or ID such as
603
+ projects/{project}/locations/{location}/reasoningEngines/{resource_id}/sandboxEnvironmentSnapshots/{snapshot_id}
604
+ or a shortened name such as "reasoningEngines/{resource_id}/sandboxEnvironmentSnapshots/{snapshot_id}".
605
+ config (GetSandboxEnvironmentSnapshotConfigOrDict):
606
+ Optional. The configuration for the sandbox snapshot to get.
607
+ """
608
+ return self._get(name=name, config=config)
609
+
610
+ def delete(
611
+ self,
612
+ *,
613
+ name: str,
614
+ config: Optional[types.DeleteSandboxEnvironmentSnapshotConfigOrDict] = None,
615
+ ) -> types.DeleteSandboxEnvironmentSnapshotOperation:
616
+ """Deletes a sandbox snapshot in the Agent Engine.
617
+ Args:
618
+ name (str):
619
+ Required. The name of the sandbox snapshot to delete.
620
+ Format: projects/{project}/locations/{location}/reasoningEngines/{resource_id}/sandboxEnvironmentSnapshots/{snapshot_id}
621
+ config (DeleteSandboxEnvironmentSnapshotConfigOrDict):
622
+ Optional. Configuration for the delete operation.
623
+ """
624
+ return self._delete(name=name, config=config)
625
+
626
+
627
+ class AsyncSandboxSnapshots(_api_module.BaseModule):
628
+ """Sandbox environment snapshot commands."""
629
+
630
+ async def _create(
631
+ self,
632
+ *,
633
+ source_sandbox_environment_name: str,
634
+ config: Optional[types.CreateAgentEngineSandboxSnapshotConfigOrDict] = None,
635
+ ) -> types.AgentEngineSandboxSnapshotOperation:
636
+ """
637
+ Snapshots an existing sandbox environment.
638
+
639
+ Args:
640
+ source_sandbox_environment_name (str):
641
+ Required. The name of the sandbox environment to snapshot.
642
+ projects/{project}/locations/{location}/reasoningEngines/{resource_id}/sandboxEnvironments/{sandbox_environment_id}
643
+ config (CreateAgentEngineSandboxSnapshotConfig):
644
+ Optional. The configuration for the sandbox snapshot.
645
+
646
+ """
647
+
648
+ parameter_model = types._CreateSandboxEnvironmentSnapshotRequestParameters(
649
+ source_sandbox_environment_name=source_sandbox_environment_name,
650
+ config=config,
651
+ )
652
+
653
+ request_url_dict: Optional[dict[str, str]]
654
+ if not self._api_client.vertexai:
655
+ raise ValueError(
656
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
657
+ )
658
+ else:
659
+ request_dict = _CreateSandboxEnvironmentSnapshotRequestParameters_to_vertex(
660
+ parameter_model
661
+ )
662
+ request_url_dict = request_dict.get("_url")
663
+ if request_url_dict:
664
+ path = "{name}:snapshot".format_map(request_url_dict)
665
+ else:
666
+ path = "{name}:snapshot"
667
+
668
+ query_params = request_dict.get("_query")
669
+ if query_params:
670
+ path = f"{path}?{urlencode(query_params)}"
671
+ # TODO: remove the hack that pops config.
672
+ request_dict.pop("config", None)
673
+
674
+ http_options: Optional[types.HttpOptions] = None
675
+ if (
676
+ parameter_model.config is not None
677
+ and parameter_model.config.http_options is not None
678
+ ):
679
+ http_options = parameter_model.config.http_options
680
+
681
+ request_dict = _common.convert_to_dict(request_dict)
682
+ request_dict = _common.encode_unserializable_types(request_dict)
683
+
684
+ response = await self._api_client.async_request(
685
+ "post", path, request_dict, http_options
686
+ )
687
+
688
+ response_dict = {} if not response.body else json.loads(response.body)
689
+
690
+ return_value = types.AgentEngineSandboxSnapshotOperation._from_response(
691
+ response=response_dict,
692
+ kwargs=(
693
+ {
694
+ "config": {
695
+ "response_schema": getattr(
696
+ parameter_model.config, "response_schema", None
697
+ ),
698
+ "response_json_schema": getattr(
699
+ parameter_model.config, "response_json_schema", None
700
+ ),
701
+ "include_all_fields": getattr(
702
+ parameter_model.config, "include_all_fields", None
703
+ ),
704
+ }
705
+ }
706
+ if getattr(parameter_model, "config", None)
707
+ else {}
708
+ ),
709
+ )
710
+
711
+ self._api_client._verify_response(return_value)
712
+ return return_value
713
+
714
+ async def _delete(
715
+ self,
716
+ *,
717
+ name: str,
718
+ config: Optional[types.DeleteSandboxEnvironmentSnapshotConfigOrDict] = None,
719
+ ) -> types.DeleteSandboxEnvironmentSnapshotOperation:
720
+ """
721
+ Deletes a sandbox environment snapshot.
722
+
723
+ """
724
+
725
+ parameter_model = types._DeleteSandboxEnvironmentSnapshotRequestParameters(
726
+ name=name,
727
+ config=config,
728
+ )
729
+
730
+ request_url_dict: Optional[dict[str, str]]
731
+ if not self._api_client.vertexai:
732
+ raise ValueError(
733
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
734
+ )
735
+ else:
736
+ request_dict = _DeleteSandboxEnvironmentSnapshotRequestParameters_to_vertex(
737
+ parameter_model
738
+ )
739
+ request_url_dict = request_dict.get("_url")
740
+ if request_url_dict:
741
+ path = "{name}".format_map(request_url_dict)
742
+ else:
743
+ path = "{name}"
744
+
745
+ query_params = request_dict.get("_query")
746
+ if query_params:
747
+ path = f"{path}?{urlencode(query_params)}"
748
+ # TODO: remove the hack that pops config.
749
+ request_dict.pop("config", None)
750
+
751
+ http_options: Optional[types.HttpOptions] = None
752
+ if (
753
+ parameter_model.config is not None
754
+ and parameter_model.config.http_options is not None
755
+ ):
756
+ http_options = parameter_model.config.http_options
757
+
758
+ request_dict = _common.convert_to_dict(request_dict)
759
+ request_dict = _common.encode_unserializable_types(request_dict)
760
+
761
+ response = await self._api_client.async_request(
762
+ "delete", path, request_dict, http_options
763
+ )
764
+
765
+ response_dict = {} if not response.body else json.loads(response.body)
766
+
767
+ return_value = types.DeleteSandboxEnvironmentSnapshotOperation._from_response(
768
+ response=response_dict,
769
+ kwargs=(
770
+ {
771
+ "config": {
772
+ "response_schema": getattr(
773
+ parameter_model.config, "response_schema", None
774
+ ),
775
+ "response_json_schema": getattr(
776
+ parameter_model.config, "response_json_schema", None
777
+ ),
778
+ "include_all_fields": getattr(
779
+ parameter_model.config, "include_all_fields", None
780
+ ),
781
+ }
782
+ }
783
+ if getattr(parameter_model, "config", None)
784
+ else {}
785
+ ),
786
+ )
787
+
788
+ self._api_client._verify_response(return_value)
789
+ return return_value
790
+
791
+ async def _get(
792
+ self,
793
+ *,
794
+ name: str,
795
+ config: Optional[types.GetSandboxEnvironmentSnapshotConfigOrDict] = None,
796
+ ) -> types.SandboxEnvironmentSnapshot:
797
+ """
798
+ Gets a sandbox environment snapshot.
799
+
800
+ """
801
+
802
+ parameter_model = types._GetSandboxEnvironmentSnapshotRequestParameters(
803
+ name=name,
804
+ config=config,
805
+ )
806
+
807
+ request_url_dict: Optional[dict[str, str]]
808
+ if not self._api_client.vertexai:
809
+ raise ValueError(
810
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
811
+ )
812
+ else:
813
+ request_dict = _GetSandboxEnvironmentSnapshotRequestParameters_to_vertex(
814
+ parameter_model
815
+ )
816
+ request_url_dict = request_dict.get("_url")
817
+ if request_url_dict:
818
+ path = "{name}".format_map(request_url_dict)
819
+ else:
820
+ path = "{name}"
821
+
822
+ query_params = request_dict.get("_query")
823
+ if query_params:
824
+ path = f"{path}?{urlencode(query_params)}"
825
+ # TODO: remove the hack that pops config.
826
+ request_dict.pop("config", None)
827
+
828
+ http_options: Optional[types.HttpOptions] = None
829
+ if (
830
+ parameter_model.config is not None
831
+ and parameter_model.config.http_options is not None
832
+ ):
833
+ http_options = parameter_model.config.http_options
834
+
835
+ request_dict = _common.convert_to_dict(request_dict)
836
+ request_dict = _common.encode_unserializable_types(request_dict)
837
+
838
+ response = await self._api_client.async_request(
839
+ "get", path, request_dict, http_options
840
+ )
841
+
842
+ response_dict = {} if not response.body else json.loads(response.body)
843
+
844
+ return_value = types.SandboxEnvironmentSnapshot._from_response(
845
+ response=response_dict,
846
+ kwargs=(
847
+ {
848
+ "config": {
849
+ "response_schema": getattr(
850
+ parameter_model.config, "response_schema", None
851
+ ),
852
+ "response_json_schema": getattr(
853
+ parameter_model.config, "response_json_schema", None
854
+ ),
855
+ "include_all_fields": getattr(
856
+ parameter_model.config, "include_all_fields", None
857
+ ),
858
+ }
859
+ }
860
+ if getattr(parameter_model, "config", None)
861
+ else {}
862
+ ),
863
+ )
864
+
865
+ self._api_client._verify_response(return_value)
866
+ return return_value
867
+
868
+ async def _list(
869
+ self,
870
+ *,
871
+ name: str,
872
+ config: Optional[types.ListSandboxEnvironmentSnapshotsConfigOrDict] = None,
873
+ ) -> types.ListSandboxEnvironmentSnapshotsResponse:
874
+ """
875
+ Lists sandbox environment snapshots.
876
+
877
+ """
878
+
879
+ parameter_model = types._ListSandboxEnvironmentSnapshotsRequestParameters(
880
+ name=name,
881
+ config=config,
882
+ )
883
+
884
+ request_url_dict: Optional[dict[str, str]]
885
+ if not self._api_client.vertexai:
886
+ raise ValueError(
887
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
888
+ )
889
+ else:
890
+ request_dict = _ListSandboxEnvironmentSnapshotsRequestParameters_to_vertex(
891
+ parameter_model
892
+ )
893
+ request_url_dict = request_dict.get("_url")
894
+ if request_url_dict:
895
+ path = "{name}/sandboxEnvironmentSnapshots".format_map(request_url_dict)
896
+ else:
897
+ path = "{name}/sandboxEnvironmentSnapshots"
898
+
899
+ query_params = request_dict.get("_query")
900
+ if query_params:
901
+ path = f"{path}?{urlencode(query_params)}"
902
+ # TODO: remove the hack that pops config.
903
+ request_dict.pop("config", None)
904
+
905
+ http_options: Optional[types.HttpOptions] = None
906
+ if (
907
+ parameter_model.config is not None
908
+ and parameter_model.config.http_options is not None
909
+ ):
910
+ http_options = parameter_model.config.http_options
911
+
912
+ request_dict = _common.convert_to_dict(request_dict)
913
+ request_dict = _common.encode_unserializable_types(request_dict)
914
+
915
+ response = await self._api_client.async_request(
916
+ "get", path, request_dict, http_options
917
+ )
918
+
919
+ response_dict = {} if not response.body else json.loads(response.body)
920
+
921
+ return_value = types.ListSandboxEnvironmentSnapshotsResponse._from_response(
922
+ response=response_dict,
923
+ kwargs=(
924
+ {
925
+ "config": {
926
+ "response_schema": getattr(
927
+ parameter_model.config, "response_schema", None
928
+ ),
929
+ "response_json_schema": getattr(
930
+ parameter_model.config, "response_json_schema", None
931
+ ),
932
+ "include_all_fields": getattr(
933
+ parameter_model.config, "include_all_fields", None
934
+ ),
935
+ }
936
+ }
937
+ if getattr(parameter_model, "config", None)
938
+ else {}
939
+ ),
940
+ )
941
+
942
+ self._api_client._verify_response(return_value)
943
+ return return_value
944
+
945
+ async def get_sandbox_snapshot_operation(
946
+ self,
947
+ *,
948
+ operation_name: str,
949
+ config: Optional[types.GetAgentEngineOperationConfigOrDict] = None,
950
+ ) -> types.AgentEngineSandboxSnapshotOperation:
951
+ parameter_model = types._GetAgentEngineSandboxSnapshotOperationParameters(
952
+ operation_name=operation_name,
953
+ config=config,
954
+ )
955
+
956
+ request_url_dict: Optional[dict[str, str]]
957
+ if not self._api_client.vertexai:
958
+ raise ValueError(
959
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
960
+ )
961
+ else:
962
+ request_dict = _GetAgentEngineSandboxSnapshotOperationParameters_to_vertex(
963
+ parameter_model
964
+ )
965
+ request_url_dict = request_dict.get("_url")
966
+ if request_url_dict:
967
+ path = "{operationName}".format_map(request_url_dict)
968
+ else:
969
+ path = "{operationName}"
970
+
971
+ query_params = request_dict.get("_query")
972
+ if query_params:
973
+ path = f"{path}?{urlencode(query_params)}"
974
+ # TODO: remove the hack that pops config.
975
+ request_dict.pop("config", None)
976
+
977
+ http_options: Optional[types.HttpOptions] = None
978
+ if (
979
+ parameter_model.config is not None
980
+ and parameter_model.config.http_options is not None
981
+ ):
982
+ http_options = parameter_model.config.http_options
983
+
984
+ request_dict = _common.convert_to_dict(request_dict)
985
+ request_dict = _common.encode_unserializable_types(request_dict)
986
+
987
+ response = await self._api_client.async_request(
988
+ "get", path, request_dict, http_options
989
+ )
990
+
991
+ response_dict = {} if not response.body else json.loads(response.body)
992
+
993
+ return_value = types.AgentEngineSandboxSnapshotOperation._from_response(
994
+ response=response_dict,
995
+ kwargs=(
996
+ {
997
+ "config": {
998
+ "response_schema": getattr(
999
+ parameter_model.config, "response_schema", None
1000
+ ),
1001
+ "response_json_schema": getattr(
1002
+ parameter_model.config, "response_json_schema", None
1003
+ ),
1004
+ "include_all_fields": getattr(
1005
+ parameter_model.config, "include_all_fields", None
1006
+ ),
1007
+ }
1008
+ }
1009
+ if getattr(parameter_model, "config", None)
1010
+ else {}
1011
+ ),
1012
+ )
1013
+
1014
+ self._api_client._verify_response(return_value)
1015
+ return return_value