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: Add the service account option for the agent engine · googleapis/python-aiplatform@02f8bbc

File tree

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

‎tests/unit/vertexai/genai/test_agent_engines.py‎

Copy file name to clipboardExpand all lines: tests/unit/vertexai/genai/test_agent_engines.py
+94Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ def register_operations(self) -> Dict[str, List[str]]:
501501
"memory": "4Gi",
502502
}
503503
_TEST_AGENT_ENGINE_CONTAINER_CONCURRENCY = 4
504+
_TEST_AGENT_ENGINE_CUSTOM_SERVICE_ACCOUNT = "test-custom-service-account"
504505
_TEST_AGENT_ENGINE_ENCRYPTION_SPEC = {"kms_key_name": "test-kms-key"}
505506
_TEST_AGENT_ENGINE_SPEC = _genai_types.ReasoningEngineSpecDict(
506507
agent_framework=_TEST_AGENT_ENGINE_FRAMEWORK,
@@ -526,6 +527,7 @@ def register_operations(self) -> Dict[str, List[str]]:
526527
dependency_files_gcs_uri=_TEST_AGENT_ENGINE_DEPENDENCY_FILES_GCS_URI,
527528
requirements_gcs_uri=_TEST_AGENT_ENGINE_REQUIREMENTS_GCS_URI,
528529
),
530+
service_account=_TEST_AGENT_ENGINE_CUSTOM_SERVICE_ACCOUNT,
529531
)
530532
_TEST_AGENT_ENGINE_STREAM_QUERY_RESPONSE = [{"output": "hello"}, {"output": "world"}]
531533
_TEST_AGENT_ENGINE_OPERATION_SCHEMAS = []
@@ -803,6 +805,7 @@ def test_create_agent_engine_config_full(self, mock_prepare):
803805
gcs_dir_name=_TEST_GCS_DIR_NAME,
804806
extra_packages=[_TEST_AGENT_ENGINE_EXTRA_PACKAGE_PATH],
805807
env_vars=_TEST_AGENT_ENGINE_ENV_VARS_INPUT,
808+
service_account=_TEST_AGENT_ENGINE_CUSTOM_SERVICE_ACCOUNT,
806809
psc_interface_config=_TEST_AGENT_ENGINE_PSC_INTERFACE_CONFIG,
807810
min_instances=_TEST_AGENT_ENGINE_MIN_INSTANCES,
808811
max_instances=_TEST_AGENT_ENGINE_MAX_INSTANCES,
@@ -841,6 +844,10 @@ def test_create_agent_engine_config_full(self, mock_prepare):
841844
}
842845
assert config["encryption_spec"] == _TEST_AGENT_ENGINE_ENCRYPTION_SPEC
843846
assert config["spec"]["class_methods"] == [_TEST_AGENT_ENGINE_CLASS_METHOD_1]
847+
assert (
848+
config["spec"]["service_account"]
849+
== _TEST_AGENT_ENGINE_CUSTOM_SERVICE_ACCOUNT
850+
)
844851

845852
@mock.patch.object(_agent_engines_utils, "_prepare")
846853
def test_update_agent_engine_config_full(self, mock_prepare):
@@ -854,6 +861,7 @@ def test_update_agent_engine_config_full(self, mock_prepare):
854861
gcs_dir_name=_TEST_GCS_DIR_NAME,
855862
extra_packages=[_TEST_AGENT_ENGINE_EXTRA_PACKAGE_PATH],
856863
env_vars=_TEST_AGENT_ENGINE_ENV_VARS_INPUT,
864+
service_account=_TEST_AGENT_ENGINE_CUSTOM_SERVICE_ACCOUNT,
857865
)
858866
assert config["display_name"] == _TEST_AGENT_ENGINE_DISPLAY_NAME
859867
assert config["description"] == _TEST_AGENT_ENGINE_DESCRIPTION
@@ -880,6 +888,10 @@ def test_update_agent_engine_config_full(self, mock_prepare):
880888
],
881889
}
882890
assert config["spec"]["class_methods"] == [_TEST_AGENT_ENGINE_CLASS_METHOD_1]
891+
assert (
892+
config["spec"]["service_account"]
893+
== _TEST_AGENT_ENGINE_CUSTOM_SERVICE_ACCOUNT
894+
)
883895
assert config["update_mask"] == ",".join(
884896
[
885897
"display_name",
@@ -889,6 +901,7 @@ def test_update_agent_engine_config_full(self, mock_prepare):
889901
"spec.package_spec.requirements_gcs_uri",
890902
"spec.deployment_spec.env",
891903
"spec.deployment_spec.secret_env",
904+
"spec.service_account",
892905
"spec.class_methods",
893906
"spec.agent_framework",
894907
]
@@ -1289,6 +1302,86 @@ def test_create_agent_engine_with_env_vars_dict(
12891302
gcs_dir_name=None,
12901303
extra_packages=[_TEST_AGENT_ENGINE_EXTRA_PACKAGE_PATH],
12911304
env_vars=_TEST_AGENT_ENGINE_ENV_VARS_INPUT,
1305+
service_account=None,
1306+
context_spec=None,
1307+
psc_interface_config=None,
1308+
min_instances=None,
1309+
max_instances=None,
1310+
resource_limits=None,
1311+
container_concurrency=None,
1312+
encryption_spec=None,
1313+
)
1314+
request_mock.assert_called_with(
1315+
"post",
1316+
"reasoningEngines",
1317+
{
1318+
"displayName": _TEST_AGENT_ENGINE_DISPLAY_NAME,
1319+
"description": _TEST_AGENT_ENGINE_DESCRIPTION,
1320+
"spec": {
1321+
"agentFramework": _TEST_AGENT_ENGINE_FRAMEWORK,
1322+
"classMethods": [_TEST_AGENT_ENGINE_CLASS_METHOD_1],
1323+
"packageSpec": {
1324+
"pickle_object_gcs_uri": _TEST_AGENT_ENGINE_GCS_URI,
1325+
"python_version": _TEST_PYTHON_VERSION,
1326+
"requirements_gcs_uri": _TEST_AGENT_ENGINE_REQUIREMENTS_GCS_URI,
1327+
},
1328+
},
1329+
},
1330+
None,
1331+
)
1332+
1333+
@mock.patch.object(agent_engines.AgentEngines, "_create_config")
1334+
@mock.patch.object(_agent_engines_utils, "_await_operation")
1335+
def test_create_agent_engine_with_custom_service_account(
1336+
self,
1337+
mock_await_operation,
1338+
mock_create_config,
1339+
):
1340+
mock_create_config.return_value = {
1341+
"display_name": _TEST_AGENT_ENGINE_DISPLAY_NAME,
1342+
"description": _TEST_AGENT_ENGINE_DESCRIPTION,
1343+
"spec": {
1344+
"package_spec": {
1345+
"python_version": _TEST_PYTHON_VERSION,
1346+
"pickle_object_gcs_uri": _TEST_AGENT_ENGINE_GCS_URI,
1347+
"requirements_gcs_uri": _TEST_AGENT_ENGINE_REQUIREMENTS_GCS_URI,
1348+
},
1349+
"class_methods": [_TEST_AGENT_ENGINE_CLASS_METHOD_1],
1350+
"service_account": _TEST_AGENT_ENGINE_CUSTOM_SERVICE_ACCOUNT,
1351+
"agent_framework": _TEST_AGENT_ENGINE_FRAMEWORK,
1352+
},
1353+
}
1354+
mock_await_operation.return_value = _genai_types.AgentEngineOperation(
1355+
response=_genai_types.ReasoningEngine(
1356+
name=_TEST_AGENT_ENGINE_RESOURCE_NAME,
1357+
spec=_TEST_AGENT_ENGINE_SPEC,
1358+
)
1359+
)
1360+
with mock.patch.object(
1361+
self.client.agent_engines._api_client, "request"
1362+
) as request_mock:
1363+
request_mock.return_value = genai_types.HttpResponse(body="")
1364+
self.client.agent_engines.create(
1365+
agent=self.test_agent,
1366+
config=_genai_types.AgentEngineConfig(
1367+
display_name=_TEST_AGENT_ENGINE_DISPLAY_NAME,
1368+
requirements=_TEST_AGENT_ENGINE_REQUIREMENTS,
1369+
extra_packages=[_TEST_AGENT_ENGINE_EXTRA_PACKAGE_PATH],
1370+
staging_bucket=_TEST_STAGING_BUCKET,
1371+
service_account=_TEST_AGENT_ENGINE_CUSTOM_SERVICE_ACCOUNT,
1372+
),
1373+
)
1374+
mock_create_config.assert_called_with(
1375+
mode="create",
1376+
agent=self.test_agent,
1377+
staging_bucket=_TEST_STAGING_BUCKET,
1378+
requirements=_TEST_AGENT_ENGINE_REQUIREMENTS,
1379+
display_name=_TEST_AGENT_ENGINE_DISPLAY_NAME,
1380+
description=None,
1381+
gcs_dir_name=None,
1382+
extra_packages=[_TEST_AGENT_ENGINE_EXTRA_PACKAGE_PATH],
1383+
env_vars=None,
1384+
service_account=_TEST_AGENT_ENGINE_CUSTOM_SERVICE_ACCOUNT,
12921385
context_spec=None,
12931386
psc_interface_config=None,
12941387
min_instances=None,
@@ -1311,6 +1404,7 @@ def test_create_agent_engine_with_env_vars_dict(
13111404
"python_version": _TEST_PYTHON_VERSION,
13121405
"requirements_gcs_uri": _TEST_AGENT_ENGINE_REQUIREMENTS_GCS_URI,
13131406
},
1407+
"serviceAccount": _TEST_AGENT_ENGINE_CUSTOM_SERVICE_ACCOUNT,
13141408
},
13151409
},
13161410
None,
Collapse file

‎vertexai/_genai/agent_engines.py‎

Copy file name to clipboardExpand all lines: vertexai/_genai/agent_engines.py
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,7 @@ def create(
10911091
gcs_dir_name=config.gcs_dir_name,
10921092
extra_packages=config.extra_packages,
10931093
env_vars=config.env_vars,
1094+
service_account=config.service_account,
10941095
context_spec=context_spec,
10951096
psc_interface_config=config.psc_interface_config,
10961097
min_instances=config.min_instances,
@@ -1147,6 +1148,7 @@ def _create_config(
11471148
gcs_dir_name: Optional[str] = None,
11481149
extra_packages: Optional[Sequence[str]] = None,
11491150
env_vars: Optional[dict[str, Union[str, Any]]] = None,
1151+
service_account: Optional[str] = None,
11501152
context_spec: Optional[types.ReasoningEngineContextSpecDict] = None,
11511153
psc_interface_config: Optional[types.PscInterfaceConfigDict] = None,
11521154
min_instances: Optional[int] = None,
@@ -1261,6 +1263,9 @@ def _create_config(
12611263
)
12621264
update_masks.extend(deployment_update_masks)
12631265
agent_engine_spec["deployment_spec"] = deployment_spec
1266+
if service_account is not None:
1267+
agent_engine_spec["service_account"] = service_account
1268+
update_masks.append("spec.service_account")
12641269
class_methods = _agent_engines_utils._generate_class_methods_spec_or_raise(
12651270
agent=agent,
12661271
operations=_agent_engines_utils._get_registered_operations(agent=agent),
@@ -1492,6 +1497,7 @@ def update(
14921497
gcs_dir_name=config.gcs_dir_name,
14931498
extra_packages=config.extra_packages,
14941499
env_vars=config.env_vars,
1500+
service_account=config.service_account,
14951501
context_spec=context_spec,
14961502
psc_interface_config=config.psc_interface_config,
14971503
min_instances=config.min_instances,
Collapse file

‎vertexai/_genai/types.py‎

Copy file name to clipboardExpand all lines: vertexai/_genai/types.py
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8773,6 +8773,12 @@ class AgentEngineConfig(_common.BaseModel):
87738773
If it is a dictionary, the keys are the environment variable names, and
87748774
the values are the corresponding values.""",
87758775
)
8776+
service_account: Optional[str] = Field(
8777+
default=None,
8778+
description="""The service account to be used for the Agent Engine.
8779+
8780+
If not specified, the default Reasoning Engine P6SA service agent will be used.""",
8781+
)
87768782
context_spec: Optional[ReasoningEngineContextSpec] = Field(
87778783
default=None,
87788784
description="""The context spec to be used for the Agent Engine.""",
@@ -8855,6 +8861,11 @@ class AgentEngineConfigDict(TypedDict, total=False):
88558861
If it is a dictionary, the keys are the environment variable names, and
88568862
the values are the corresponding values."""
88578863

8864+
service_account: Optional[str]
8865+
"""The service account to be used for the Agent Engine.
8866+
8867+
If not specified, the default Reasoning Engine P6SA service agent will be used."""
8868+
88588869
context_spec: Optional[ReasoningEngineContextSpecDict]
88598870
"""The context spec to be used for the Agent Engine."""
88608871

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.