Skip to content

Commit ef03bef

Browse files
shawn-yang-googlecopybara-github
authored andcommitted
chore: Support specifying python_version in Agent Engine creation and update.
PiperOrigin-RevId: 831015034
1 parent 3a99664 commit ef03bef

File tree

3 files changed

+64
-4
lines changed

3 files changed

+64
-4
lines changed

tests/unit/vertexai/genai/test_agent_engines.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ def register_operations(self) -> Dict[str, List[str]]:
458458
)
459459
_TEST_AGENT_ENGINE_QUERY_SCHEMA[_TEST_MODE_KEY_IN_SCHEMA] = _TEST_STANDARD_API_MODE
460460
_TEST_PYTHON_VERSION = f"{sys.version_info.major}.{sys.version_info.minor}"
461+
_TEST_PYTHON_VERSION_OVERRIDE = "3.11"
461462
_TEST_AGENT_ENGINE_FRAMEWORK = _agent_engines_utils._DEFAULT_AGENT_FRAMEWORK
462463
_TEST_AGENT_ENGINE_CLASS_METHOD_1 = {
463464
"description": "Runs the engine.",
@@ -969,12 +970,13 @@ def test_create_agent_engine_config_full(self, mock_prepare):
969970
resource_limits=_TEST_AGENT_ENGINE_RESOURCE_LIMITS,
970971
container_concurrency=_TEST_AGENT_ENGINE_CONTAINER_CONCURRENCY,
971972
encryption_spec=_TEST_AGENT_ENGINE_ENCRYPTION_SPEC,
973+
python_version=_TEST_PYTHON_VERSION_OVERRIDE,
972974
)
973975
assert config["display_name"] == _TEST_AGENT_ENGINE_DISPLAY_NAME
974976
assert config["description"] == _TEST_AGENT_ENGINE_DESCRIPTION
975977
assert config["spec"]["agent_framework"] == "custom"
976978
assert config["spec"]["package_spec"] == {
977-
"python_version": _TEST_PYTHON_VERSION,
979+
"python_version": _TEST_PYTHON_VERSION_OVERRIDE,
978980
"pickle_object_gcs_uri": _TEST_AGENT_ENGINE_GCS_URI,
979981
"dependency_files_gcs_uri": _TEST_AGENT_ENGINE_DEPENDENCY_FILES_GCS_URI,
980982
"requirements_gcs_uri": _TEST_AGENT_ENGINE_REQUIREMENTS_GCS_URI,
@@ -1037,14 +1039,15 @@ def test_create_agent_engine_config_with_source_packages(
10371039
class_methods=_TEST_AGENT_ENGINE_CLASS_METHODS,
10381040
agent_framework=_TEST_AGENT_FRAMEWORK,
10391041
identity_type=_TEST_AGENT_ENGINE_IDENTITY_TYPE_SERVICE_ACCOUNT,
1042+
python_version=_TEST_PYTHON_VERSION_OVERRIDE,
10401043
)
10411044
assert config["display_name"] == _TEST_AGENT_ENGINE_DISPLAY_NAME
10421045
assert config["description"] == _TEST_AGENT_ENGINE_DESCRIPTION
10431046
assert config["spec"]["agent_framework"] == _TEST_AGENT_FRAMEWORK
10441047
assert config["spec"]["source_code_spec"] == {
10451048
"inline_source": {"source_archive": "test_tarball"},
10461049
"python_spec": {
1047-
"version": _TEST_PYTHON_VERSION,
1050+
"version": _TEST_PYTHON_VERSION_OVERRIDE,
10481051
"entrypoint_module": "main",
10491052
"entrypoint_object": "app",
10501053
"requirements_file": requirements_file_path,
@@ -1073,12 +1076,13 @@ def test_update_agent_engine_config_full(self, mock_prepare):
10731076
env_vars=_TEST_AGENT_ENGINE_ENV_VARS_INPUT,
10741077
service_account=_TEST_AGENT_ENGINE_CUSTOM_SERVICE_ACCOUNT,
10751078
identity_type=_TEST_AGENT_ENGINE_IDENTITY_TYPE_SERVICE_ACCOUNT,
1079+
python_version=_TEST_PYTHON_VERSION_OVERRIDE,
10761080
)
10771081
assert config["display_name"] == _TEST_AGENT_ENGINE_DISPLAY_NAME
10781082
assert config["description"] == _TEST_AGENT_ENGINE_DESCRIPTION
10791083
assert config["spec"]["agent_framework"] == "custom"
10801084
assert config["spec"]["package_spec"] == {
1081-
"python_version": _TEST_PYTHON_VERSION,
1085+
"python_version": _TEST_PYTHON_VERSION_OVERRIDE,
10821086
"pickle_object_gcs_uri": _TEST_AGENT_ENGINE_GCS_URI,
10831087
"dependency_files_gcs_uri": _TEST_AGENT_ENGINE_DEPENDENCY_FILES_GCS_URI,
10841088
"requirements_gcs_uri": _TEST_AGENT_ENGINE_REQUIREMENTS_GCS_URI,
@@ -1593,6 +1597,7 @@ def test_create_agent_engine_with_env_vars_dict(
15931597
entrypoint_object=None,
15941598
requirements_file=None,
15951599
agent_framework=None,
1600+
python_version=None,
15961601
)
15971602
request_mock.assert_called_with(
15981603
"post",
@@ -1685,6 +1690,7 @@ def test_create_agent_engine_with_custom_service_account(
16851690
entrypoint_object=None,
16861691
requirements_file=None,
16871692
agent_framework=None,
1693+
python_version=None,
16881694
)
16891695
request_mock.assert_called_with(
16901696
"post",
@@ -1776,6 +1782,7 @@ def test_create_agent_engine_with_experimental_mode(
17761782
entrypoint_object=None,
17771783
requirements_file=None,
17781784
agent_framework=None,
1785+
python_version=None,
17791786
)
17801787
request_mock.assert_called_with(
17811788
"post",
@@ -1930,6 +1937,7 @@ def test_create_agent_engine_with_class_methods(
19301937
entrypoint_object=None,
19311938
requirements_file=None,
19321939
agent_framework=None,
1940+
python_version=None,
19331941
)
19341942
request_mock.assert_called_with(
19351943
"post",
@@ -2016,6 +2024,7 @@ def test_create_agent_engine_with_agent_framework(
20162024
requirements_file=None,
20172025
agent_framework=_TEST_AGENT_FRAMEWORK,
20182026
identity_type=None,
2027+
python_version=None,
20192028
)
20202029
request_mock.assert_called_with(
20212030
"post",

vertexai/_genai/agent_engines.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ def _CreateAgentEngineConfig_to_vertex(
9797
if getv(from_object, ["agent_framework"]) is not None:
9898
setv(parent_object, ["agentFramework"], getv(from_object, ["agent_framework"]))
9999

100+
if getv(from_object, ["python_version"]) is not None:
101+
setv(parent_object, ["pythonVersion"], getv(from_object, ["python_version"]))
102+
100103
return to_object
101104

102105

@@ -291,6 +294,9 @@ def _UpdateAgentEngineConfig_to_vertex(
291294
if getv(from_object, ["agent_framework"]) is not None:
292295
setv(parent_object, ["agentFramework"], getv(from_object, ["agent_framework"]))
293296

297+
if getv(from_object, ["python_version"]) is not None:
298+
setv(parent_object, ["pythonVersion"], getv(from_object, ["python_version"]))
299+
294300
if getv(from_object, ["update_mask"]) is not None:
295301
setv(
296302
parent_object, ["_query", "updateMask"], getv(from_object, ["update_mask"])
@@ -931,6 +937,7 @@ def create(
931937
entrypoint_object=config.entrypoint_object,
932938
requirements_file=config.requirements_file,
933939
agent_framework=config.agent_framework,
940+
python_version=config.python_version,
934941
)
935942
operation = self._create(config=api_config)
936943
# TODO: Use a more specific link.
@@ -996,6 +1003,7 @@ def _create_config(
9961003
entrypoint_object: Optional[str] = None,
9971004
requirements_file: Optional[str] = None,
9981005
agent_framework: Optional[str] = None,
1006+
python_version: Optional[str] = None,
9991007
) -> types.UpdateAgentEngineConfigDict:
10001008
import sys
10011009

@@ -1027,7 +1035,10 @@ def _create_config(
10271035
if agent_framework == "google-adk":
10281036
env_vars = _agent_engines_utils._add_telemetry_enablement_env(env_vars)
10291037

1030-
sys_version = f"{sys.version_info.major}.{sys.version_info.minor}"
1038+
if python_version:
1039+
sys_version = python_version
1040+
else:
1041+
sys_version = f"{sys.version_info.major}.{sys.version_info.minor}"
10311042
agent_engine_spec = None
10321043
if agent is not None:
10331044
if source_packages is not None:
@@ -1453,6 +1464,7 @@ def update(
14531464
entrypoint_object=config.entrypoint_object,
14541465
requirements_file=config.requirements_file,
14551466
agent_framework=config.agent_framework,
1467+
python_version=config.python_version,
14561468
)
14571469
operation = self._update(name=name, config=api_config)
14581470
logger.info(

vertexai/_genai/types/common.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5457,6 +5457,13 @@ class CreateAgentEngineConfig(_common.BaseModel):
54575457
- If `source_packages` is specified, the agent framework will
54585458
default to "custom".""",
54595459
)
5460+
python_version: Optional[Literal["3.9", "3.10", "3.11", "3.12", "3.13"]] = Field(
5461+
default=None,
5462+
description="""The Python version to be used for the Agent Engine.
5463+
If not specified, it will use the current Python version of the environment.
5464+
Supported versions: "3.9", "3.10", "3.11", "3.12", "3.13".
5465+
""",
5466+
)
54605467

54615468

54625469
class CreateAgentEngineConfigDict(TypedDict, total=False):
@@ -5567,6 +5574,12 @@ class CreateAgentEngineConfigDict(TypedDict, total=False):
55675574
- If `source_packages` is specified, the agent framework will
55685575
default to "custom"."""
55695576

5577+
python_version: Optional[Literal["3.9", "3.10", "3.11", "3.12", "3.13"]]
5578+
"""The Python version to be used for the Agent Engine.
5579+
If not specified, it will use the current Python version of the environment.
5580+
Supported versions: "3.9", "3.10", "3.11", "3.12", "3.13".
5581+
"""
5582+
55705583

55715584
CreateAgentEngineConfigOrDict = Union[
55725585
CreateAgentEngineConfig, CreateAgentEngineConfigDict
@@ -6183,6 +6196,13 @@ class UpdateAgentEngineConfig(_common.BaseModel):
61836196
- If `source_packages` is specified, the agent framework will
61846197
default to "custom".""",
61856198
)
6199+
python_version: Optional[Literal["3.9", "3.10", "3.11", "3.12", "3.13"]] = Field(
6200+
default=None,
6201+
description="""The Python version to be used for the Agent Engine.
6202+
If not specified, it will use the current Python version of the environment.
6203+
Supported versions: "3.9", "3.10", "3.11", "3.12", "3.13".
6204+
""",
6205+
)
61866206
update_mask: Optional[str] = Field(
61876207
default=None,
61886208
description="""The update mask to apply. For the `FieldMask` definition, see
@@ -6298,6 +6318,12 @@ class UpdateAgentEngineConfigDict(TypedDict, total=False):
62986318
- If `source_packages` is specified, the agent framework will
62996319
default to "custom"."""
63006320

6321+
python_version: Optional[Literal["3.9", "3.10", "3.11", "3.12", "3.13"]]
6322+
"""The Python version to be used for the Agent Engine.
6323+
If not specified, it will use the current Python version of the environment.
6324+
Supported versions: "3.9", "3.10", "3.11", "3.12", "3.13".
6325+
"""
6326+
63016327
update_mask: Optional[str]
63026328
"""The update mask to apply. For the `FieldMask` definition, see
63036329
https://protobuf.dev/reference/protobuf/google.protobuf/#field-mask."""
@@ -13037,6 +13063,13 @@ class AgentEngineConfig(_common.BaseModel):
1303713063
- If `source_packages` is specified, the agent framework will
1303813064
default to "custom".""",
1303913065
)
13066+
python_version: Optional[Literal["3.9", "3.10", "3.11", "3.12", "3.13"]] = Field(
13067+
default=None,
13068+
description="""The Python version to be used for the Agent Engine.
13069+
If not specified, it will use the current Python version of the environment.
13070+
Supported versions: "3.9", "3.10", "3.11", "3.12", "3.13".
13071+
""",
13072+
)
1304013073

1304113074

1304213075
class AgentEngineConfigDict(TypedDict, total=False):
@@ -13179,6 +13212,12 @@ class AgentEngineConfigDict(TypedDict, total=False):
1317913212
- If `source_packages` is specified, the agent framework will
1318013213
default to "custom"."""
1318113214

13215+
python_version: Optional[Literal["3.9", "3.10", "3.11", "3.12", "3.13"]]
13216+
"""The Python version to be used for the Agent Engine.
13217+
If not specified, it will use the current Python version of the environment.
13218+
Supported versions: "3.9", "3.10", "3.11", "3.12", "3.13".
13219+
"""
13220+
1318213221

1318313222
AgentEngineConfigOrDict = Union[AgentEngineConfig, AgentEngineConfigDict]
1318413223

0 commit comments

Comments
 (0)