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,1088 @@
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.sandboxtemplates")
34
+
35
+ logger.setLevel(logging.INFO)
36
+
37
+
38
+ def _CreateSandboxEnvironmentTemplateConfig_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, ["custom_container_environment"]) is not None:
45
+ setv(
46
+ parent_object,
47
+ ["customContainerEnvironment"],
48
+ getv(from_object, ["custom_container_environment"]),
49
+ )
50
+
51
+ if getv(from_object, ["default_container_environment"]) is not None:
52
+ setv(
53
+ parent_object,
54
+ ["defaultContainerEnvironment"],
55
+ getv(from_object, ["default_container_environment"]),
56
+ )
57
+
58
+ if getv(from_object, ["egress_control_config"]) is not None:
59
+ setv(
60
+ parent_object,
61
+ ["egressControlConfig"],
62
+ getv(from_object, ["egress_control_config"]),
63
+ )
64
+
65
+ return to_object
66
+
67
+
68
+ def _CreateSandboxEnvironmentTemplateRequestParameters_to_vertex(
69
+ from_object: Union[dict[str, Any], object],
70
+ parent_object: Optional[dict[str, Any]] = None,
71
+ ) -> dict[str, Any]:
72
+ to_object: dict[str, Any] = {}
73
+ if getv(from_object, ["name"]) is not None:
74
+ setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
75
+
76
+ if getv(from_object, ["config"]) is not None:
77
+ _CreateSandboxEnvironmentTemplateConfig_to_vertex(
78
+ getv(from_object, ["config"]), to_object
79
+ )
80
+
81
+ if getv(from_object, ["display_name"]) is not None:
82
+ setv(to_object, ["displayName"], getv(from_object, ["display_name"]))
83
+
84
+ return to_object
85
+
86
+
87
+ def _DeleteSandboxEnvironmentTemplateRequestParameters_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, ["name"]) is not None:
93
+ setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
94
+
95
+ return to_object
96
+
97
+
98
+ def _GetSandboxEnvironmentTemplateOperationParameters_to_vertex(
99
+ from_object: Union[dict[str, Any], object],
100
+ parent_object: Optional[dict[str, Any]] = None,
101
+ ) -> dict[str, Any]:
102
+ to_object: dict[str, Any] = {}
103
+ if getv(from_object, ["operation_name"]) is not None:
104
+ setv(
105
+ to_object, ["_url", "operationName"], getv(from_object, ["operation_name"])
106
+ )
107
+
108
+ return to_object
109
+
110
+
111
+ def _GetSandboxEnvironmentTemplateRequestParameters_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
+ if getv(from_object, ["name"]) is not None:
117
+ setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
118
+
119
+ return to_object
120
+
121
+
122
+ def _ListSandboxEnvironmentTemplatesConfig_to_vertex(
123
+ from_object: Union[dict[str, Any], object],
124
+ parent_object: Optional[dict[str, Any]] = None,
125
+ ) -> dict[str, Any]:
126
+ to_object: dict[str, Any] = {}
127
+
128
+ if getv(from_object, ["page_size"]) is not None:
129
+ setv(parent_object, ["_query", "pageSize"], getv(from_object, ["page_size"]))
130
+
131
+ if getv(from_object, ["page_token"]) is not None:
132
+ setv(parent_object, ["_query", "pageToken"], getv(from_object, ["page_token"]))
133
+
134
+ if getv(from_object, ["filter"]) is not None:
135
+ setv(parent_object, ["_query", "filter"], getv(from_object, ["filter"]))
136
+
137
+ return to_object
138
+
139
+
140
+ def _ListSandboxEnvironmentTemplatesRequestParameters_to_vertex(
141
+ from_object: Union[dict[str, Any], object],
142
+ parent_object: Optional[dict[str, Any]] = None,
143
+ ) -> dict[str, Any]:
144
+ to_object: dict[str, Any] = {}
145
+ if getv(from_object, ["name"]) is not None:
146
+ setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
147
+
148
+ if getv(from_object, ["config"]) is not None:
149
+ _ListSandboxEnvironmentTemplatesConfig_to_vertex(
150
+ getv(from_object, ["config"]), to_object
151
+ )
152
+
153
+ return to_object
154
+
155
+
156
+ class SandboxTemplates(_api_module.BaseModule):
157
+ """Sandbox environment templates commands."""
158
+
159
+ def _create(
160
+ self,
161
+ *,
162
+ name: str,
163
+ config: Optional[types.CreateSandboxEnvironmentTemplateConfigOrDict] = None,
164
+ display_name: str,
165
+ ) -> types.SandboxEnvironmentTemplateOperation:
166
+ """
167
+ Creates a new sandbox template in the Agent Engine.
168
+
169
+ Args:
170
+ name (str):
171
+ Required. The name of the agent engine to create the template under.
172
+ Format: projects/{project}/locations/{location}/reasoningEngines/{resource_id}
173
+ display_name (str):
174
+ Required. The display name of the sandbox template.
175
+ config (CreateSandboxEnvironmentTemplateConfig):
176
+ Optional. The configuration for the sandbox template.
177
+
178
+ """
179
+
180
+ parameter_model = types._CreateSandboxEnvironmentTemplateRequestParameters(
181
+ name=name,
182
+ config=config,
183
+ display_name=display_name,
184
+ )
185
+
186
+ request_url_dict: Optional[dict[str, str]]
187
+ if not self._api_client.vertexai:
188
+ raise ValueError(
189
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
190
+ )
191
+ else:
192
+ request_dict = _CreateSandboxEnvironmentTemplateRequestParameters_to_vertex(
193
+ parameter_model
194
+ )
195
+ request_url_dict = request_dict.get("_url")
196
+ if request_url_dict:
197
+ path = "{name}/sandboxEnvironmentTemplates".format_map(request_url_dict)
198
+ else:
199
+ path = "{name}/sandboxEnvironmentTemplates"
200
+
201
+ query_params = request_dict.get("_query")
202
+ if query_params:
203
+ path = f"{path}?{urlencode(query_params)}"
204
+ # TODO: remove the hack that pops config.
205
+ request_dict.pop("config", None)
206
+
207
+ http_options: Optional[types.HttpOptions] = None
208
+ if (
209
+ parameter_model.config is not None
210
+ and parameter_model.config.http_options is not None
211
+ ):
212
+ http_options = parameter_model.config.http_options
213
+
214
+ request_dict = _common.convert_to_dict(request_dict)
215
+ request_dict = _common.encode_unserializable_types(request_dict)
216
+
217
+ response = self._api_client.request("post", path, request_dict, http_options)
218
+
219
+ response_dict = {} if not response.body else json.loads(response.body)
220
+
221
+ return_value = types.SandboxEnvironmentTemplateOperation._from_response(
222
+ response=response_dict,
223
+ kwargs=(
224
+ {
225
+ "config": {
226
+ "response_schema": getattr(
227
+ parameter_model.config, "response_schema", None
228
+ ),
229
+ "response_json_schema": getattr(
230
+ parameter_model.config, "response_json_schema", None
231
+ ),
232
+ "include_all_fields": getattr(
233
+ parameter_model.config, "include_all_fields", None
234
+ ),
235
+ }
236
+ }
237
+ if getattr(parameter_model, "config", None)
238
+ else {}
239
+ ),
240
+ )
241
+
242
+ self._api_client._verify_response(return_value)
243
+ return return_value
244
+
245
+ def _delete(
246
+ self,
247
+ *,
248
+ name: str,
249
+ config: Optional[types.DeleteSandboxEnvironmentTemplateConfigOrDict] = None,
250
+ ) -> types.DeleteSandboxEnvironmentTemplateOperation:
251
+ """
252
+ Delete an Agent Engine sandbox template.
253
+
254
+ Args:
255
+ name (str):
256
+ Required. The name of the sandbox template to delete.
257
+ Format: projects/{project}/locations/{location}/reasoningEngines/{resource_id}/sandboxTemplates/{sandbox_template}
258
+ config (DeleteSandboxEnvironmentTemplateConfig):
259
+ Optional. Configuration for the delete operation.
260
+
261
+ """
262
+
263
+ parameter_model = types._DeleteSandboxEnvironmentTemplateRequestParameters(
264
+ name=name,
265
+ config=config,
266
+ )
267
+
268
+ request_url_dict: Optional[dict[str, str]]
269
+ if not self._api_client.vertexai:
270
+ raise ValueError(
271
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
272
+ )
273
+ else:
274
+ request_dict = _DeleteSandboxEnvironmentTemplateRequestParameters_to_vertex(
275
+ parameter_model
276
+ )
277
+ request_url_dict = request_dict.get("_url")
278
+ if request_url_dict:
279
+ path = "{name}".format_map(request_url_dict)
280
+ else:
281
+ path = "{name}"
282
+
283
+ query_params = request_dict.get("_query")
284
+ if query_params:
285
+ path = f"{path}?{urlencode(query_params)}"
286
+ # TODO: remove the hack that pops config.
287
+ request_dict.pop("config", None)
288
+
289
+ http_options: Optional[types.HttpOptions] = None
290
+ if (
291
+ parameter_model.config is not None
292
+ and parameter_model.config.http_options is not None
293
+ ):
294
+ http_options = parameter_model.config.http_options
295
+
296
+ request_dict = _common.convert_to_dict(request_dict)
297
+ request_dict = _common.encode_unserializable_types(request_dict)
298
+
299
+ response = self._api_client.request("delete", path, request_dict, http_options)
300
+
301
+ response_dict = {} if not response.body else json.loads(response.body)
302
+
303
+ return_value = types.DeleteSandboxEnvironmentTemplateOperation._from_response(
304
+ response=response_dict,
305
+ kwargs=(
306
+ {
307
+ "config": {
308
+ "response_schema": getattr(
309
+ parameter_model.config, "response_schema", None
310
+ ),
311
+ "response_json_schema": getattr(
312
+ parameter_model.config, "response_json_schema", None
313
+ ),
314
+ "include_all_fields": getattr(
315
+ parameter_model.config, "include_all_fields", None
316
+ ),
317
+ }
318
+ }
319
+ if getattr(parameter_model, "config", None)
320
+ else {}
321
+ ),
322
+ )
323
+
324
+ self._api_client._verify_response(return_value)
325
+ return return_value
326
+
327
+ def _get(
328
+ self,
329
+ *,
330
+ name: str,
331
+ config: Optional[types.GetSandboxEnvironmentTemplateConfigOrDict] = None,
332
+ ) -> types.SandboxEnvironmentTemplate:
333
+ """
334
+ Gets an agent engine sandbox template.
335
+
336
+ Args:
337
+ name (str): The resource name of the SandboxEnvironmentTemplate.
338
+ Format:
339
+ `projects/{project}/locations/{location}/reasoningEngines/{resource_id}/sandboxEnvironmentTemplates/{sandbox_environment_template}`
340
+ config (GetSandboxEnvironmentTemplateConfig): Configuration for the
341
+ request.
342
+
343
+ Returns:
344
+ shared.SandboxEnvironmentTemplate: The retrieved sandbox environment
345
+ template.
346
+
347
+ """
348
+
349
+ parameter_model = types._GetSandboxEnvironmentTemplateRequestParameters(
350
+ name=name,
351
+ config=config,
352
+ )
353
+
354
+ request_url_dict: Optional[dict[str, str]]
355
+ if not self._api_client.vertexai:
356
+ raise ValueError(
357
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
358
+ )
359
+ else:
360
+ request_dict = _GetSandboxEnvironmentTemplateRequestParameters_to_vertex(
361
+ parameter_model
362
+ )
363
+ request_url_dict = request_dict.get("_url")
364
+ if request_url_dict:
365
+ path = "{name}".format_map(request_url_dict)
366
+ else:
367
+ path = "{name}"
368
+
369
+ query_params = request_dict.get("_query")
370
+ if query_params:
371
+ path = f"{path}?{urlencode(query_params)}"
372
+ # TODO: remove the hack that pops config.
373
+ request_dict.pop("config", None)
374
+
375
+ http_options: Optional[types.HttpOptions] = None
376
+ if (
377
+ parameter_model.config is not None
378
+ and parameter_model.config.http_options is not None
379
+ ):
380
+ http_options = parameter_model.config.http_options
381
+
382
+ request_dict = _common.convert_to_dict(request_dict)
383
+ request_dict = _common.encode_unserializable_types(request_dict)
384
+
385
+ response = self._api_client.request("get", path, request_dict, http_options)
386
+
387
+ response_dict = {} if not response.body else json.loads(response.body)
388
+
389
+ return_value = types.SandboxEnvironmentTemplate._from_response(
390
+ response=response_dict,
391
+ kwargs=(
392
+ {
393
+ "config": {
394
+ "response_schema": getattr(
395
+ parameter_model.config, "response_schema", None
396
+ ),
397
+ "response_json_schema": getattr(
398
+ parameter_model.config, "response_json_schema", None
399
+ ),
400
+ "include_all_fields": getattr(
401
+ parameter_model.config, "include_all_fields", None
402
+ ),
403
+ }
404
+ }
405
+ if getattr(parameter_model, "config", None)
406
+ else {}
407
+ ),
408
+ )
409
+
410
+ self._api_client._verify_response(return_value)
411
+ return return_value
412
+
413
+ def _list(
414
+ self,
415
+ *,
416
+ name: str,
417
+ config: Optional[types.ListSandboxEnvironmentTemplatesConfigOrDict] = None,
418
+ ) -> types.ListSandboxEnvironmentTemplatesResponse:
419
+ """
420
+ Lists Agent Engine sandbox templates.
421
+
422
+ Args:
423
+ name (str): Name of the agent engine. Format: projects/{project}/locations/{location}/reasoningEngines/{resource_id}
424
+ config (ListSandboxEnvironmentTemplatesConfig): Configuration for listing sandbox templates.
425
+
426
+ Returns:
427
+ ListSandboxEnvironmentTemplatesResponse: A list of sandbox templates.
428
+
429
+ """
430
+
431
+ parameter_model = types._ListSandboxEnvironmentTemplatesRequestParameters(
432
+ name=name,
433
+ config=config,
434
+ )
435
+
436
+ request_url_dict: Optional[dict[str, str]]
437
+ if not self._api_client.vertexai:
438
+ raise ValueError(
439
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
440
+ )
441
+ else:
442
+ request_dict = _ListSandboxEnvironmentTemplatesRequestParameters_to_vertex(
443
+ parameter_model
444
+ )
445
+ request_url_dict = request_dict.get("_url")
446
+ if request_url_dict:
447
+ path = "{name}/sandboxEnvironmentTemplates".format_map(request_url_dict)
448
+ else:
449
+ path = "{name}/sandboxEnvironmentTemplates"
450
+
451
+ query_params = request_dict.get("_query")
452
+ if query_params:
453
+ path = f"{path}?{urlencode(query_params)}"
454
+ # TODO: remove the hack that pops config.
455
+ request_dict.pop("config", None)
456
+
457
+ http_options: Optional[types.HttpOptions] = None
458
+ if (
459
+ parameter_model.config is not None
460
+ and parameter_model.config.http_options is not None
461
+ ):
462
+ http_options = parameter_model.config.http_options
463
+
464
+ request_dict = _common.convert_to_dict(request_dict)
465
+ request_dict = _common.encode_unserializable_types(request_dict)
466
+
467
+ response = self._api_client.request("get", path, request_dict, http_options)
468
+
469
+ response_dict = {} if not response.body else json.loads(response.body)
470
+
471
+ return_value = types.ListSandboxEnvironmentTemplatesResponse._from_response(
472
+ response=response_dict,
473
+ kwargs=(
474
+ {
475
+ "config": {
476
+ "response_schema": getattr(
477
+ parameter_model.config, "response_schema", None
478
+ ),
479
+ "response_json_schema": getattr(
480
+ parameter_model.config, "response_json_schema", None
481
+ ),
482
+ "include_all_fields": getattr(
483
+ parameter_model.config, "include_all_fields", None
484
+ ),
485
+ }
486
+ }
487
+ if getattr(parameter_model, "config", None)
488
+ else {}
489
+ ),
490
+ )
491
+
492
+ self._api_client._verify_response(return_value)
493
+ return return_value
494
+
495
+ def get_sandbox_environment_template_operation(
496
+ self,
497
+ *,
498
+ operation_name: str,
499
+ config: Optional[types.GetAgentEngineOperationConfigOrDict] = None,
500
+ ) -> types.SandboxEnvironmentTemplateOperation:
501
+ parameter_model = types._GetSandboxEnvironmentTemplateOperationParameters(
502
+ operation_name=operation_name,
503
+ config=config,
504
+ )
505
+
506
+ request_url_dict: Optional[dict[str, str]]
507
+ if not self._api_client.vertexai:
508
+ raise ValueError(
509
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
510
+ )
511
+ else:
512
+ request_dict = _GetSandboxEnvironmentTemplateOperationParameters_to_vertex(
513
+ parameter_model
514
+ )
515
+ request_url_dict = request_dict.get("_url")
516
+ if request_url_dict:
517
+ path = "{operationName}".format_map(request_url_dict)
518
+ else:
519
+ path = "{operationName}"
520
+
521
+ query_params = request_dict.get("_query")
522
+ if query_params:
523
+ path = f"{path}?{urlencode(query_params)}"
524
+ # TODO: remove the hack that pops config.
525
+ request_dict.pop("config", None)
526
+
527
+ http_options: Optional[types.HttpOptions] = None
528
+ if (
529
+ parameter_model.config is not None
530
+ and parameter_model.config.http_options is not None
531
+ ):
532
+ http_options = parameter_model.config.http_options
533
+
534
+ request_dict = _common.convert_to_dict(request_dict)
535
+ request_dict = _common.encode_unserializable_types(request_dict)
536
+
537
+ response = self._api_client.request("get", path, request_dict, http_options)
538
+
539
+ response_dict = {} if not response.body else json.loads(response.body)
540
+
541
+ return_value = types.SandboxEnvironmentTemplateOperation._from_response(
542
+ response=response_dict,
543
+ kwargs=(
544
+ {
545
+ "config": {
546
+ "response_schema": getattr(
547
+ parameter_model.config, "response_schema", None
548
+ ),
549
+ "response_json_schema": getattr(
550
+ parameter_model.config, "response_json_schema", None
551
+ ),
552
+ "include_all_fields": getattr(
553
+ parameter_model.config, "include_all_fields", None
554
+ ),
555
+ }
556
+ }
557
+ if getattr(parameter_model, "config", None)
558
+ else {}
559
+ ),
560
+ )
561
+
562
+ self._api_client._verify_response(return_value)
563
+ return return_value
564
+
565
+ def create(
566
+ self,
567
+ *,
568
+ name: str,
569
+ display_name: str,
570
+ config: Optional[types.CreateSandboxEnvironmentTemplateConfigOrDict] = None,
571
+ poll_interval_seconds: float = 0.1,
572
+ ) -> types.SandboxEnvironmentTemplateOperation:
573
+ """Creates a new sandbox template in the Agent Engine.
574
+
575
+ Args:
576
+ name (str):
577
+ Required. The name of the agent engine to create sandbox template for.
578
+ projects/{project}/locations/{location}/reasoningEngines/{resource_id}
579
+ display_name (str):
580
+ Required. The display name of the sandbox template.
581
+ config (CreateSandboxEnvironmentTemplateConfig):
582
+ Optional. The configuration for the sandbox template.
583
+ polling_interval (int):
584
+ Optional. Seconds to wait between polling for operation status. Defaults to 5.
585
+
586
+ Returns:
587
+ SandboxEnvironmentTemplateOperation: The operation for creating the sandbox template.
588
+ """
589
+ operation = self._create(
590
+ name=name,
591
+ display_name=display_name,
592
+ config=config,
593
+ )
594
+ if config is None:
595
+ config = types.CreateSandboxEnvironmentTemplateConfig()
596
+ elif isinstance(config, dict):
597
+ config = types.CreateSandboxEnvironmentTemplateConfig.model_validate(config)
598
+ if config.wait_for_completion:
599
+ if not operation.done:
600
+ operation = _agent_engines_utils._await_operation(
601
+ operation_name=operation.name,
602
+ get_operation_fn=self.get_sandbox_environment_template_operation,
603
+ poll_interval_seconds=poll_interval_seconds,
604
+ )
605
+ # We need to make a call to get the sandbox template because the operation
606
+ # response might not contain the relevant fields.
607
+ if not operation.response:
608
+ raise ValueError("Error retrieving sandbox template.")
609
+ operation.response = self.get(name=operation.response.name)
610
+ return operation
611
+
612
+ def list(
613
+ self,
614
+ *,
615
+ name: str,
616
+ config: Optional[types.ListSandboxEnvironmentTemplatesConfigOrDict] = None,
617
+ ) -> Iterator[types.SandboxEnvironmentTemplate]:
618
+ """Lists Agent Engine sandbox templates.
619
+
620
+ Args:
621
+ name (str):
622
+ Required. The name of the agent engine to list sandbox templates for.
623
+ projects/{project}/locations/{location}/reasoningEngines/{resource_id}
624
+ config (ListSandboxEnvironmentTemplatesConfig):
625
+ Optional. The configuration for the sandbox templates to list.
626
+
627
+ Returns:
628
+ Iterable[SandboxEnvironmentTemplate]: An iterable of agent engine sandbox templates.
629
+ """
630
+ return Pager(
631
+ "sandbox_environment_templates",
632
+ functools.partial(self._list, name=name),
633
+ self._list(name=name, config=config),
634
+ config,
635
+ )
636
+
637
+ def get(
638
+ self,
639
+ *,
640
+ name: str,
641
+ config: Optional[types.GetSandboxEnvironmentTemplateConfigOrDict] = None,
642
+ ) -> types.SandboxEnvironmentTemplate:
643
+ """Gets a sandbox template in the Agent Engine.
644
+ Args:
645
+ name (str):
646
+ Required. A fully-qualified resource name or ID such as
647
+ projects/{project}/locations/{location}/reasoningEngines/{resource_id}/sandboxEnvironmentTemplates/{sandbox_template_id}
648
+ or a shortened name such as "reasoningEngines/{resource_id}/sandboxEnvironmentTemplates/{sandbox_template_id}".
649
+ config (GetSandboxEnvironmentTemplateConfigOrDict):
650
+ Optional. The configuration for the sandbox template to get.
651
+ """
652
+ return self._get(name=name, config=config)
653
+
654
+ def delete(
655
+ self,
656
+ *,
657
+ name: str,
658
+ config: Optional[types.DeleteSandboxEnvironmentTemplateConfigOrDict] = None,
659
+ ) -> types.DeleteSandboxEnvironmentTemplateOperation:
660
+ """Deletes a sandbox template in the Agent Engine.
661
+ Args:
662
+ name (str):
663
+ Required. The name of the sandbox template to delete.
664
+ Format: projects/{project}/locations/{location}/reasoningEngines/{resource_id}/sandboxEnvironmentTemplates/{sandbox_template_id}
665
+ config (DeleteSandboxEnvironmentTemplateConfig):
666
+ Optional. Configuration for the delete operation.
667
+ """
668
+ return self._delete(name=name, config=config)
669
+
670
+
671
+ class AsyncSandboxTemplates(_api_module.BaseModule):
672
+ """Sandbox environment templates commands."""
673
+
674
+ async def _create(
675
+ self,
676
+ *,
677
+ name: str,
678
+ config: Optional[types.CreateSandboxEnvironmentTemplateConfigOrDict] = None,
679
+ display_name: str,
680
+ ) -> types.SandboxEnvironmentTemplateOperation:
681
+ """
682
+ Creates a new sandbox template in the Agent Engine.
683
+
684
+ Args:
685
+ name (str):
686
+ Required. The name of the agent engine to create the template under.
687
+ Format: projects/{project}/locations/{location}/reasoningEngines/{resource_id}
688
+ display_name (str):
689
+ Required. The display name of the sandbox template.
690
+ config (CreateSandboxEnvironmentTemplateConfig):
691
+ Optional. The configuration for the sandbox template.
692
+
693
+ """
694
+
695
+ parameter_model = types._CreateSandboxEnvironmentTemplateRequestParameters(
696
+ name=name,
697
+ config=config,
698
+ display_name=display_name,
699
+ )
700
+
701
+ request_url_dict: Optional[dict[str, str]]
702
+ if not self._api_client.vertexai:
703
+ raise ValueError(
704
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
705
+ )
706
+ else:
707
+ request_dict = _CreateSandboxEnvironmentTemplateRequestParameters_to_vertex(
708
+ parameter_model
709
+ )
710
+ request_url_dict = request_dict.get("_url")
711
+ if request_url_dict:
712
+ path = "{name}/sandboxEnvironmentTemplates".format_map(request_url_dict)
713
+ else:
714
+ path = "{name}/sandboxEnvironmentTemplates"
715
+
716
+ query_params = request_dict.get("_query")
717
+ if query_params:
718
+ path = f"{path}?{urlencode(query_params)}"
719
+ # TODO: remove the hack that pops config.
720
+ request_dict.pop("config", None)
721
+
722
+ http_options: Optional[types.HttpOptions] = None
723
+ if (
724
+ parameter_model.config is not None
725
+ and parameter_model.config.http_options is not None
726
+ ):
727
+ http_options = parameter_model.config.http_options
728
+
729
+ request_dict = _common.convert_to_dict(request_dict)
730
+ request_dict = _common.encode_unserializable_types(request_dict)
731
+
732
+ response = await self._api_client.async_request(
733
+ "post", path, request_dict, http_options
734
+ )
735
+
736
+ response_dict = {} if not response.body else json.loads(response.body)
737
+
738
+ return_value = types.SandboxEnvironmentTemplateOperation._from_response(
739
+ response=response_dict,
740
+ kwargs=(
741
+ {
742
+ "config": {
743
+ "response_schema": getattr(
744
+ parameter_model.config, "response_schema", None
745
+ ),
746
+ "response_json_schema": getattr(
747
+ parameter_model.config, "response_json_schema", None
748
+ ),
749
+ "include_all_fields": getattr(
750
+ parameter_model.config, "include_all_fields", None
751
+ ),
752
+ }
753
+ }
754
+ if getattr(parameter_model, "config", None)
755
+ else {}
756
+ ),
757
+ )
758
+
759
+ self._api_client._verify_response(return_value)
760
+ return return_value
761
+
762
+ async def _delete(
763
+ self,
764
+ *,
765
+ name: str,
766
+ config: Optional[types.DeleteSandboxEnvironmentTemplateConfigOrDict] = None,
767
+ ) -> types.DeleteSandboxEnvironmentTemplateOperation:
768
+ """
769
+ Delete an Agent Engine sandbox template.
770
+
771
+ Args:
772
+ name (str):
773
+ Required. The name of the sandbox template to delete.
774
+ Format: projects/{project}/locations/{location}/reasoningEngines/{resource_id}/sandboxTemplates/{sandbox_template}
775
+ config (DeleteSandboxEnvironmentTemplateConfig):
776
+ Optional. Configuration for the delete operation.
777
+
778
+ """
779
+
780
+ parameter_model = types._DeleteSandboxEnvironmentTemplateRequestParameters(
781
+ name=name,
782
+ config=config,
783
+ )
784
+
785
+ request_url_dict: Optional[dict[str, str]]
786
+ if not self._api_client.vertexai:
787
+ raise ValueError(
788
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
789
+ )
790
+ else:
791
+ request_dict = _DeleteSandboxEnvironmentTemplateRequestParameters_to_vertex(
792
+ parameter_model
793
+ )
794
+ request_url_dict = request_dict.get("_url")
795
+ if request_url_dict:
796
+ path = "{name}".format_map(request_url_dict)
797
+ else:
798
+ path = "{name}"
799
+
800
+ query_params = request_dict.get("_query")
801
+ if query_params:
802
+ path = f"{path}?{urlencode(query_params)}"
803
+ # TODO: remove the hack that pops config.
804
+ request_dict.pop("config", None)
805
+
806
+ http_options: Optional[types.HttpOptions] = None
807
+ if (
808
+ parameter_model.config is not None
809
+ and parameter_model.config.http_options is not None
810
+ ):
811
+ http_options = parameter_model.config.http_options
812
+
813
+ request_dict = _common.convert_to_dict(request_dict)
814
+ request_dict = _common.encode_unserializable_types(request_dict)
815
+
816
+ response = await self._api_client.async_request(
817
+ "delete", path, request_dict, http_options
818
+ )
819
+
820
+ response_dict = {} if not response.body else json.loads(response.body)
821
+
822
+ return_value = types.DeleteSandboxEnvironmentTemplateOperation._from_response(
823
+ response=response_dict,
824
+ kwargs=(
825
+ {
826
+ "config": {
827
+ "response_schema": getattr(
828
+ parameter_model.config, "response_schema", None
829
+ ),
830
+ "response_json_schema": getattr(
831
+ parameter_model.config, "response_json_schema", None
832
+ ),
833
+ "include_all_fields": getattr(
834
+ parameter_model.config, "include_all_fields", None
835
+ ),
836
+ }
837
+ }
838
+ if getattr(parameter_model, "config", None)
839
+ else {}
840
+ ),
841
+ )
842
+
843
+ self._api_client._verify_response(return_value)
844
+ return return_value
845
+
846
+ async def _get(
847
+ self,
848
+ *,
849
+ name: str,
850
+ config: Optional[types.GetSandboxEnvironmentTemplateConfigOrDict] = None,
851
+ ) -> types.SandboxEnvironmentTemplate:
852
+ """
853
+ Gets an agent engine sandbox template.
854
+
855
+ Args:
856
+ name (str): The resource name of the SandboxEnvironmentTemplate.
857
+ Format:
858
+ `projects/{project}/locations/{location}/reasoningEngines/{resource_id}/sandboxEnvironmentTemplates/{sandbox_environment_template}`
859
+ config (GetSandboxEnvironmentTemplateConfig): Configuration for the
860
+ request.
861
+
862
+ Returns:
863
+ shared.SandboxEnvironmentTemplate: The retrieved sandbox environment
864
+ template.
865
+
866
+ """
867
+
868
+ parameter_model = types._GetSandboxEnvironmentTemplateRequestParameters(
869
+ name=name,
870
+ config=config,
871
+ )
872
+
873
+ request_url_dict: Optional[dict[str, str]]
874
+ if not self._api_client.vertexai:
875
+ raise ValueError(
876
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
877
+ )
878
+ else:
879
+ request_dict = _GetSandboxEnvironmentTemplateRequestParameters_to_vertex(
880
+ parameter_model
881
+ )
882
+ request_url_dict = request_dict.get("_url")
883
+ if request_url_dict:
884
+ path = "{name}".format_map(request_url_dict)
885
+ else:
886
+ path = "{name}"
887
+
888
+ query_params = request_dict.get("_query")
889
+ if query_params:
890
+ path = f"{path}?{urlencode(query_params)}"
891
+ # TODO: remove the hack that pops config.
892
+ request_dict.pop("config", None)
893
+
894
+ http_options: Optional[types.HttpOptions] = None
895
+ if (
896
+ parameter_model.config is not None
897
+ and parameter_model.config.http_options is not None
898
+ ):
899
+ http_options = parameter_model.config.http_options
900
+
901
+ request_dict = _common.convert_to_dict(request_dict)
902
+ request_dict = _common.encode_unserializable_types(request_dict)
903
+
904
+ response = await self._api_client.async_request(
905
+ "get", path, request_dict, http_options
906
+ )
907
+
908
+ response_dict = {} if not response.body else json.loads(response.body)
909
+
910
+ return_value = types.SandboxEnvironmentTemplate._from_response(
911
+ response=response_dict,
912
+ kwargs=(
913
+ {
914
+ "config": {
915
+ "response_schema": getattr(
916
+ parameter_model.config, "response_schema", None
917
+ ),
918
+ "response_json_schema": getattr(
919
+ parameter_model.config, "response_json_schema", None
920
+ ),
921
+ "include_all_fields": getattr(
922
+ parameter_model.config, "include_all_fields", None
923
+ ),
924
+ }
925
+ }
926
+ if getattr(parameter_model, "config", None)
927
+ else {}
928
+ ),
929
+ )
930
+
931
+ self._api_client._verify_response(return_value)
932
+ return return_value
933
+
934
+ async def _list(
935
+ self,
936
+ *,
937
+ name: str,
938
+ config: Optional[types.ListSandboxEnvironmentTemplatesConfigOrDict] = None,
939
+ ) -> types.ListSandboxEnvironmentTemplatesResponse:
940
+ """
941
+ Lists Agent Engine sandbox templates.
942
+
943
+ Args:
944
+ name (str): Name of the agent engine. Format: projects/{project}/locations/{location}/reasoningEngines/{resource_id}
945
+ config (ListSandboxEnvironmentTemplatesConfig): Configuration for listing sandbox templates.
946
+
947
+ Returns:
948
+ ListSandboxEnvironmentTemplatesResponse: A list of sandbox templates.
949
+
950
+ """
951
+
952
+ parameter_model = types._ListSandboxEnvironmentTemplatesRequestParameters(
953
+ name=name,
954
+ config=config,
955
+ )
956
+
957
+ request_url_dict: Optional[dict[str, str]]
958
+ if not self._api_client.vertexai:
959
+ raise ValueError(
960
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
961
+ )
962
+ else:
963
+ request_dict = _ListSandboxEnvironmentTemplatesRequestParameters_to_vertex(
964
+ parameter_model
965
+ )
966
+ request_url_dict = request_dict.get("_url")
967
+ if request_url_dict:
968
+ path = "{name}/sandboxEnvironmentTemplates".format_map(request_url_dict)
969
+ else:
970
+ path = "{name}/sandboxEnvironmentTemplates"
971
+
972
+ query_params = request_dict.get("_query")
973
+ if query_params:
974
+ path = f"{path}?{urlencode(query_params)}"
975
+ # TODO: remove the hack that pops config.
976
+ request_dict.pop("config", None)
977
+
978
+ http_options: Optional[types.HttpOptions] = None
979
+ if (
980
+ parameter_model.config is not None
981
+ and parameter_model.config.http_options is not None
982
+ ):
983
+ http_options = parameter_model.config.http_options
984
+
985
+ request_dict = _common.convert_to_dict(request_dict)
986
+ request_dict = _common.encode_unserializable_types(request_dict)
987
+
988
+ response = await self._api_client.async_request(
989
+ "get", path, request_dict, http_options
990
+ )
991
+
992
+ response_dict = {} if not response.body else json.loads(response.body)
993
+
994
+ return_value = types.ListSandboxEnvironmentTemplatesResponse._from_response(
995
+ response=response_dict,
996
+ kwargs=(
997
+ {
998
+ "config": {
999
+ "response_schema": getattr(
1000
+ parameter_model.config, "response_schema", None
1001
+ ),
1002
+ "response_json_schema": getattr(
1003
+ parameter_model.config, "response_json_schema", None
1004
+ ),
1005
+ "include_all_fields": getattr(
1006
+ parameter_model.config, "include_all_fields", None
1007
+ ),
1008
+ }
1009
+ }
1010
+ if getattr(parameter_model, "config", None)
1011
+ else {}
1012
+ ),
1013
+ )
1014
+
1015
+ self._api_client._verify_response(return_value)
1016
+ return return_value
1017
+
1018
+ async def get_sandbox_environment_template_operation(
1019
+ self,
1020
+ *,
1021
+ operation_name: str,
1022
+ config: Optional[types.GetAgentEngineOperationConfigOrDict] = None,
1023
+ ) -> types.SandboxEnvironmentTemplateOperation:
1024
+ parameter_model = types._GetSandboxEnvironmentTemplateOperationParameters(
1025
+ operation_name=operation_name,
1026
+ config=config,
1027
+ )
1028
+
1029
+ request_url_dict: Optional[dict[str, str]]
1030
+ if not self._api_client.vertexai:
1031
+ raise ValueError(
1032
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
1033
+ )
1034
+ else:
1035
+ request_dict = _GetSandboxEnvironmentTemplateOperationParameters_to_vertex(
1036
+ parameter_model
1037
+ )
1038
+ request_url_dict = request_dict.get("_url")
1039
+ if request_url_dict:
1040
+ path = "{operationName}".format_map(request_url_dict)
1041
+ else:
1042
+ path = "{operationName}"
1043
+
1044
+ query_params = request_dict.get("_query")
1045
+ if query_params:
1046
+ path = f"{path}?{urlencode(query_params)}"
1047
+ # TODO: remove the hack that pops config.
1048
+ request_dict.pop("config", None)
1049
+
1050
+ http_options: Optional[types.HttpOptions] = None
1051
+ if (
1052
+ parameter_model.config is not None
1053
+ and parameter_model.config.http_options is not None
1054
+ ):
1055
+ http_options = parameter_model.config.http_options
1056
+
1057
+ request_dict = _common.convert_to_dict(request_dict)
1058
+ request_dict = _common.encode_unserializable_types(request_dict)
1059
+
1060
+ response = await self._api_client.async_request(
1061
+ "get", path, request_dict, http_options
1062
+ )
1063
+
1064
+ response_dict = {} if not response.body else json.loads(response.body)
1065
+
1066
+ return_value = types.SandboxEnvironmentTemplateOperation._from_response(
1067
+ response=response_dict,
1068
+ kwargs=(
1069
+ {
1070
+ "config": {
1071
+ "response_schema": getattr(
1072
+ parameter_model.config, "response_schema", None
1073
+ ),
1074
+ "response_json_schema": getattr(
1075
+ parameter_model.config, "response_json_schema", None
1076
+ ),
1077
+ "include_all_fields": getattr(
1078
+ parameter_model.config, "include_all_fields", None
1079
+ ),
1080
+ }
1081
+ }
1082
+ if getattr(parameter_model, "config", None)
1083
+ else {}
1084
+ ),
1085
+ )
1086
+
1087
+ self._api_client._verify_response(return_value)
1088
+ return return_value