GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: Support for CMEK, runtime controls, and PSC-I · googleapis/python-aiplatform@f31502d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • tests/unit/vertexai/genai/replays
    • test_create_agent_engine.py
  • vertexai/_genai
    • _agent_engines_utils.py
    • agent_engines.py
    • types.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎tests/unit/vertexai/genai/replays/test_create_agent_engine.py‎

Copy file name to clipboardExpand all lines: tests/unit/vertexai/genai/replays/test_create_agent_engine.py
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,25 @@ def test_create_config_lightweight(client):
3838
}
3939

4040

41+
def test_create_config(client):
42+
agent_display_name = "test-display-name"
43+
agent_description = "my agent"
44+
45+
if not os.environ.get("GCS_BUCKET"):
46+
raise ValueError("GCS_BUCKET environment variable is not set.")
47+
48+
config = client.agent_engines._create_config(
49+
mode="create",
50+
staging_bucket=os.environ["GCS_BUCKET"],
51+
display_name=agent_display_name,
52+
description=agent_description,
53+
)
54+
assert config == {
55+
"display_name": agent_display_name,
56+
"description": agent_description,
57+
}
58+
59+
4160
def test_create_with_context_spec(client):
4261
project = "test-project"
4362
location = "us-central1"
Collapse file

‎vertexai/_genai/_agent_engines_utils.py‎

Copy file name to clipboardExpand all lines: vertexai/_genai/_agent_engines_utils.py
+71Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,3 +1445,74 @@ def _yield_parsed_json(http_response: google_genai_types.HttpResponse) -> Iterat
14451445
except Exception as e:
14461446
logger.warning(f"failed to parse json: {line}. Exception: {e}")
14471447
yield line
1448+
1449+
1450+
def _validate_resource_limits_or_raise(resource_limits: dict[str, str]) -> None:
1451+
"""Validates the resource limits.
1452+
1453+
Checks that the resource limits are a dict with 'cpu' and 'memory' keys.
1454+
Checks that the 'cpu' value is one of 1, 2, 4, 6, 8.
1455+
Checks that the 'memory' value is a string ending with 'Gi'.
1456+
Checks that the memory size is smaller than 32Gi.
1457+
Checks that the memory size requires at least the specified number of CPUs.
1458+
1459+
Args:
1460+
resource_limits: The resource limits to be validated.
1461+
1462+
Raises:
1463+
TypeError: If the resource limits are not a dict.
1464+
KeyError: If the resource limits do not contain 'cpu' and 'memory' keys.
1465+
ValueError: If the 'cpu' value is not one of 1, 2, 4, 6, 8.
1466+
ValueError: If the 'memory' value is not a string ending with 'Gi'.
1467+
ValueError: If the memory size is too large.
1468+
ValueError: If the memory size requires more CPUs than the specified
1469+
'cpu' value.
1470+
"""
1471+
if not isinstance(resource_limits, dict):
1472+
raise TypeError(f"resource_limits must be a dict. Got {type(resource_limits)}")
1473+
if "cpu" not in resource_limits or "memory" not in resource_limits:
1474+
raise KeyError("resource_limits must contain 'cpu' and 'memory' keys.")
1475+
1476+
cpu = int(resource_limits["cpu"])
1477+
memory_str = resource_limits["memory"]
1478+
1479+
if cpu not in [1, 2, 4, 6, 8]:
1480+
raise ValueError(
1481+
"resource_limits['cpu'] must be one of 1, 2, 4, 6, 8. Got" f" {cpu}"
1482+
)
1483+
1484+
if not isinstance(memory_str, str) or not memory_str.endswith("Gi"):
1485+
raise ValueError(
1486+
"resource_limits['memory'] must be a string ending with 'Gi'."
1487+
f" Got {memory_str}"
1488+
)
1489+
1490+
try:
1491+
memory_gb = int(memory_str[:-2])
1492+
except ValueError:
1493+
raise ValueError(
1494+
f"Invalid memory value: {memory_str}. Must be an integer"
1495+
" followed by 'Gi'."
1496+
)
1497+
1498+
# https://cloud.google.com/run/docs/configuring/memory-limits
1499+
if memory_gb > 32:
1500+
raise ValueError(
1501+
f"Memory size of {memory_str} is too large. Must be smaller than 32Gi."
1502+
)
1503+
if memory_gb > 24:
1504+
min_cpu = 8
1505+
elif memory_gb > 16:
1506+
min_cpu = 6
1507+
elif memory_gb > 8:
1508+
min_cpu = 4
1509+
elif memory_gb > 4:
1510+
min_cpu = 2
1511+
else:
1512+
min_cpu = 1
1513+
1514+
if cpu < min_cpu:
1515+
raise ValueError(
1516+
f"Memory size of {memory_str} requires at least {min_cpu} CPUs."
1517+
f" Got {cpu}"
1518+
)
Collapse file

‎vertexai/_genai/agent_engines.py‎

Copy file name to clipboardExpand all lines: vertexai/_genai/agent_engines.py
+129-2Lines changed: 129 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ def _ReasoningEngineSpec_to_vertex(
6060
if getv(from_object, ["package_spec"]) is not None:
6161
setv(to_object, ["packageSpec"], getv(from_object, ["package_spec"]))
6262

63+
if getv(from_object, ["service_account"]) is not None:
64+
setv(
65+
to_object,
66+
["serviceAccount"],
67+
getv(from_object, ["service_account"]),
68+
)
69+
6370
return to_object
6471

6572

@@ -78,6 +85,28 @@ def _ReasoningEngineContextSpec_to_vertex(
7885
return to_object
7986

8087

88+
def _PscInterfaceConfig_to_vertex(
89+
from_object: Union[dict[str, Any], object],
90+
parent_object: Optional[dict[str, Any]] = None,
91+
) -> dict[str, Any]:
92+
to_object: dict[str, Any] = {}
93+
if getv(from_object, ["dns_peering_configs"]) is not None:
94+
setv(
95+
to_object,
96+
["dnsPeeringConfigs"],
97+
getv(from_object, ["dns_peering_configs"]),
98+
)
99+
100+
if getv(from_object, ["network_attachment"]) is not None:
101+
setv(
102+
to_object,
103+
["networkAttachment"],
104+
getv(from_object, ["network_attachment"]),
105+
)
106+
107+
return to_object
108+
109+
81110
def _CreateAgentEngineConfig_to_vertex(
82111
from_object: Union[dict[str, Any], object],
83112
parent_object: Optional[dict[str, Any]] = None,
@@ -106,6 +135,15 @@ def _CreateAgentEngineConfig_to_vertex(
106135
),
107136
)
108137

138+
if getv(from_object, ["psc_interface_config"]) is not None:
139+
setv(
140+
parent_object,
141+
["pscInterfaceConfig"],
142+
_PscInterfaceConfig_to_vertex(
143+
getv(from_object, ["psc_interface_config"]), to_object
144+
),
145+
)
146+
109147
return to_object
110148

111149

@@ -717,6 +755,15 @@ def _UpdateAgentEngineConfig_to_vertex(
717755
),
718756
)
719757

758+
if getv(from_object, ["psc_interface_config"]) is not None:
759+
setv(
760+
parent_object,
761+
["pscInterfaceConfig"],
762+
_PscInterfaceConfig_to_vertex(
763+
getv(from_object, ["psc_interface_config"]), to_object
764+
),
765+
)
766+
720767
if getv(from_object, ["update_mask"]) is not None:
721768
setv(
722769
parent_object,
@@ -861,6 +908,13 @@ def _ReasoningEngine_from_vertex(
861908
if getv(from_object, ["displayName"]) is not None:
862909
setv(to_object, ["display_name"], getv(from_object, ["displayName"]))
863910

911+
if getv(from_object, ["encryptionSpec"]) is not None:
912+
setv(
913+
to_object,
914+
["encryption_spec"],
915+
getv(from_object, ["encryptionSpec"]),
916+
)
917+
864918
if getv(from_object, ["etag"]) is not None:
865919
setv(to_object, ["etag"], getv(from_object, ["etag"]))
866920

@@ -970,12 +1024,18 @@ def _Session_from_vertex(
9701024
if getv(from_object, ["displayName"]) is not None:
9711025
setv(to_object, ["display_name"], getv(from_object, ["displayName"]))
9721026

1027+
if getv(from_object, ["expireTime"]) is not None:
1028+
setv(to_object, ["expire_time"], getv(from_object, ["expireTime"]))
1029+
9731030
if getv(from_object, ["name"]) is not None:
9741031
setv(to_object, ["name"], getv(from_object, ["name"]))
9751032

9761033
if getv(from_object, ["sessionState"]) is not None:
9771034
setv(to_object, ["session_state"], getv(from_object, ["sessionState"]))
9781035

1036+
if getv(from_object, ["ttl"]) is not None:
1037+
setv(to_object, ["ttl"], getv(from_object, ["ttl"]))
1038+
9791039
if getv(from_object, ["updateTime"]) is not None:
9801040
setv(to_object, ["update_time"], getv(from_object, ["updateTime"]))
9811041

@@ -2722,6 +2782,11 @@ def create(
27222782
extra_packages=config.extra_packages,
27232783
env_vars=config.env_vars,
27242784
context_spec=context_spec,
2785+
psc_interface_config=config.psc_interface_config,
2786+
min_instances=config.min_instances,
2787+
max_instances=config.max_instances,
2788+
resource_limits=config.resource_limits,
2789+
container_concurrency=config.container_concurrency,
27252790
)
27262791
operation = self._create(config=api_config)
27272792
# TODO: Use a more specific link.
@@ -2769,6 +2834,11 @@ def _create_config(
27692834
extra_packages: Optional[Sequence[str]] = None,
27702835
env_vars: Optional[dict[str, Union[str, Any]]] = None,
27712836
context_spec: Optional[types.ReasoningEngineContextSpecDict] = None,
2837+
psc_interface_config: Optional[types.PscInterfaceConfigDict] = None,
2838+
min_instances: Optional[int] = None,
2839+
max_instances: Optional[int] = None,
2840+
resource_limits: Optional[dict[str, str]] = None,
2841+
container_concurrency: Optional[int] = None,
27722842
) -> types.UpdateAgentEngineConfigDict:
27732843
import sys
27742844

@@ -2853,11 +2923,25 @@ def _create_config(
28532923
agent_engine_spec: types.ReasoningEngineSpecDict = {
28542924
"package_spec": package_spec,
28552925
}
2856-
if env_vars is not None:
2926+
if (
2927+
env_vars is not None
2928+
or psc_interface_config is not None
2929+
or min_instances is not None
2930+
or max_instances is not None
2931+
or resource_limits is not None
2932+
or container_concurrency is not None
2933+
):
28572934
(
28582935
deployment_spec,
28592936
deployment_update_masks,
2860-
) = self._generate_deployment_spec_or_raise(env_vars=env_vars)
2937+
) = self._generate_deployment_spec_or_raise(
2938+
env_vars=env_vars,
2939+
psc_interface_config=psc_interface_config,
2940+
min_instances=min_instances,
2941+
max_instances=max_instances,
2942+
resource_limits=resource_limits,
2943+
container_concurrency=container_concurrency,
2944+
)
28612945
update_masks.extend(deployment_update_masks)
28622946
agent_engine_spec["deployment_spec"] = deployment_spec
28632947
class_methods = _agent_engines_utils._generate_class_methods_spec_or_raise(
@@ -2884,6 +2968,11 @@ def _generate_deployment_spec_or_raise(
28842968
self,
28852969
*,
28862970
env_vars: Optional[dict[str, Union[str, Any]]] = None,
2971+
psc_interface_config: Optional[types.PscInterfaceConfigDict] = None,
2972+
min_instances: Optional[int] = None,
2973+
max_instances: Optional[int] = None,
2974+
resource_limits: Optional[dict[str, str]] = None,
2975+
container_concurrency: Optional[int] = None,
28872976
) -> Tuple[dict[str, Any], Sequence[str]]:
28882977
deployment_spec: dict[str, Any] = {}
28892978
update_masks = []
@@ -2901,6 +2990,37 @@ def _generate_deployment_spec_or_raise(
29012990
update_masks.append("spec.deployment_spec.env")
29022991
if deployment_spec.get("secret_env"):
29032992
update_masks.append("spec.deployment_spec.secret_env")
2993+
if psc_interface_config:
2994+
deployment_spec["psc_interface_config"] = psc_interface_config
2995+
update_masks.append("spec.deployment_spec.psc_interface_config")
2996+
if min_instances is not None:
2997+
if not 0 <= min_instances <= 10:
2998+
raise ValueError(
2999+
"min_instances must be between 0 and 10. Got" f" {min_instances}"
3000+
)
3001+
deployment_spec["min_instances"] = min_instances
3002+
update_masks.append("spec.deployment_spec.min_instances")
3003+
if max_instances is not None:
3004+
if psc_interface_config and not 1 <= max_instances <= 100:
3005+
raise ValueError(
3006+
"max_instances must be between 1 and 100 when PSC-I is"
3007+
f" enabled. Got {max_instances}"
3008+
)
3009+
elif not psc_interface_config and not 1 <= max_instances <= 1000:
3010+
raise ValueError(
3011+
"max_instances must be between 1 and 1000. Got" f" {max_instances}"
3012+
)
3013+
deployment_spec["max_instances"] = max_instances
3014+
update_masks.append("spec.deployment_spec.max_instances")
3015+
if resource_limits:
3016+
_agent_engines_utils._validate_resource_limits_or_raise(
3017+
resource_limits=resource_limits
3018+
)
3019+
deployment_spec["resource_limits"] = resource_limits
3020+
update_masks.append("spec.deployment_spec.resource_limits")
3021+
if container_concurrency:
3022+
deployment_spec["container_concurrency"] = container_concurrency
3023+
update_masks.append("spec.deployment_spec.container_concurrency")
29043024
return deployment_spec, update_masks
29053025

29063026
def _update_deployment_spec_with_env_vars_dict_or_raise(
@@ -3073,6 +3193,11 @@ def update(
30733193
extra_packages=config.extra_packages,
30743194
env_vars=config.env_vars,
30753195
context_spec=context_spec,
3196+
psc_interface_config=config.psc_interface_config,
3197+
min_instances=config.min_instances,
3198+
max_instances=config.max_instances,
3199+
resource_limits=config.resource_limits,
3200+
container_concurrency=config.container_concurrency,
30763201
)
30773202
operation = self._update(name=name, config=api_config)
30783203
logger.info(
@@ -3128,6 +3253,8 @@ def _stream_query(
31283253
):
31293254
yield response
31303255

3256+
# TODO: b/436704146 - Replace with generated methods
3257+
# TODO: b/437129724 - Add replay test for async stream query
31313258
async def _async_stream_query(
31323259
self,
31333260
*,

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.