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@407eb67

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
+77Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ def register_operations(self) -> Dict[str, List[str]]:
484484
"version": "TEST_SECRET_VERSION_1",
485485
},
486486
}
487+
_TEST_AGENT_ENGINE_CUSTOM_SERVICE_ACCOUNT = "test-custom-service-account"
487488
_TEST_AGENT_ENGINE_SPEC = _genai_types.ReasoningEngineSpecDict(
488489
agent_framework=_TEST_AGENT_ENGINE_FRAMEWORK,
489490
class_methods=[_TEST_AGENT_ENGINE_CLASS_METHOD_1],
@@ -508,6 +509,7 @@ def register_operations(self) -> Dict[str, List[str]]:
508509
dependency_files_gcs_uri=_TEST_AGENT_ENGINE_DEPENDENCY_FILES_GCS_URI,
509510
requirements_gcs_uri=_TEST_AGENT_ENGINE_REQUIREMENTS_GCS_URI,
510511
),
512+
service_account=_TEST_AGENT_ENGINE_CUSTOM_SERVICE_ACCOUNT,
511513
)
512514
_TEST_AGENT_ENGINE_STREAM_QUERY_RESPONSE = [{"output": "hello"}, {"output": "world"}]
513515
_TEST_AGENT_ENGINE_OPERATION_SCHEMAS = []
@@ -1255,6 +1257,7 @@ def test_create_agent_engine_with_env_vars_dict(
12551257
gcs_dir_name=None,
12561258
extra_packages=[_TEST_AGENT_ENGINE_EXTRA_PACKAGE_PATH],
12571259
env_vars=_TEST_AGENT_ENGINE_ENV_VARS_INPUT,
1260+
service_account=None,
12581261
context_spec=None,
12591262
)
12601263
request_mock.assert_called_with(
@@ -1276,6 +1279,80 @@ def test_create_agent_engine_with_env_vars_dict(
12761279
None,
12771280
)
12781281

1282+
@mock.patch.object(agent_engines.AgentEngines, "_create_config")
1283+
@mock.patch.object(agent_engines.AgentEngines, "_await_operation")
1284+
def test_create_agent_engine_with_custom_service_account(
1285+
self,
1286+
mock_await_operation,
1287+
mock_create_config,
1288+
):
1289+
mock_create_config.return_value = {
1290+
"display_name": _TEST_AGENT_ENGINE_DISPLAY_NAME,
1291+
"description": _TEST_AGENT_ENGINE_DESCRIPTION,
1292+
"spec": {
1293+
"package_spec": {
1294+
"python_version": _TEST_PYTHON_VERSION,
1295+
"pickle_object_gcs_uri": _TEST_AGENT_ENGINE_GCS_URI,
1296+
"requirements_gcs_uri": _TEST_AGENT_ENGINE_REQUIREMENTS_GCS_URI,
1297+
},
1298+
"class_methods": [_TEST_AGENT_ENGINE_CLASS_METHOD_1],
1299+
"service_account": _TEST_AGENT_ENGINE_CUSTOM_SERVICE_ACCOUNT,
1300+
"agent_framework": _TEST_AGENT_ENGINE_FRAMEWORK,
1301+
},
1302+
}
1303+
mock_await_operation.return_value = _genai_types.AgentEngineOperation(
1304+
response=_genai_types.ReasoningEngine(
1305+
name=_TEST_AGENT_ENGINE_RESOURCE_NAME,
1306+
spec=_TEST_AGENT_ENGINE_SPEC,
1307+
)
1308+
)
1309+
with mock.patch.object(
1310+
self.client.agent_engines._api_client, "request"
1311+
) as request_mock:
1312+
request_mock.return_value = genai_types.HttpResponse(body="")
1313+
self.client.agent_engines.create(
1314+
agent_engine=self.test_agent,
1315+
config=_genai_types.AgentEngineConfig(
1316+
display_name=_TEST_AGENT_ENGINE_DISPLAY_NAME,
1317+
requirements=_TEST_AGENT_ENGINE_REQUIREMENTS,
1318+
extra_packages=[_TEST_AGENT_ENGINE_EXTRA_PACKAGE_PATH],
1319+
staging_bucket=_TEST_STAGING_BUCKET,
1320+
service_account=_TEST_AGENT_ENGINE_CUSTOM_SERVICE_ACCOUNT,
1321+
),
1322+
)
1323+
mock_create_config.assert_called_with(
1324+
mode="create",
1325+
agent_engine=self.test_agent,
1326+
staging_bucket=_TEST_STAGING_BUCKET,
1327+
requirements=_TEST_AGENT_ENGINE_REQUIREMENTS,
1328+
display_name=_TEST_AGENT_ENGINE_DISPLAY_NAME,
1329+
description=None,
1330+
gcs_dir_name=None,
1331+
extra_packages=[_TEST_AGENT_ENGINE_EXTRA_PACKAGE_PATH],
1332+
env_vars=None,
1333+
service_account=_TEST_AGENT_ENGINE_CUSTOM_SERVICE_ACCOUNT,
1334+
context_spec=None,
1335+
)
1336+
request_mock.assert_called_with(
1337+
"post",
1338+
"reasoningEngines",
1339+
{
1340+
"displayName": _TEST_AGENT_ENGINE_DISPLAY_NAME,
1341+
"description": _TEST_AGENT_ENGINE_DESCRIPTION,
1342+
"spec": {
1343+
"agentFramework": _TEST_AGENT_ENGINE_FRAMEWORK,
1344+
"classMethods": [_TEST_AGENT_ENGINE_CLASS_METHOD_1],
1345+
"packageSpec": {
1346+
"pickle_object_gcs_uri": _TEST_AGENT_ENGINE_GCS_URI,
1347+
"python_version": _TEST_PYTHON_VERSION,
1348+
"requirements_gcs_uri": _TEST_AGENT_ENGINE_REQUIREMENTS_GCS_URI,
1349+
},
1350+
"serviceAccount": _TEST_AGENT_ENGINE_CUSTOM_SERVICE_ACCOUNT,
1351+
},
1352+
},
1353+
None,
1354+
)
1355+
12791356
@pytest.mark.usefixtures("caplog")
12801357
@mock.patch.object(_agent_engines_utils, "_prepare")
12811358
@mock.patch.object(agent_engines.AgentEngines, "_await_operation")
Collapse file

‎vertexai/_genai/agent_engines.py‎

Copy file name to clipboardExpand all lines: vertexai/_genai/agent_engines.py
+28Lines changed: 28 additions & 0 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

@@ -861,6 +868,13 @@ def _ReasoningEngine_from_vertex(
861868
if getv(from_object, ["displayName"]) is not None:
862869
setv(to_object, ["display_name"], getv(from_object, ["displayName"]))
863870

871+
if getv(from_object, ["encryptionSpec"]) is not None:
872+
setv(
873+
to_object,
874+
["encryption_spec"],
875+
getv(from_object, ["encryptionSpec"]),
876+
)
877+
864878
if getv(from_object, ["etag"]) is not None:
865879
setv(to_object, ["etag"], getv(from_object, ["etag"]))
866880

@@ -970,12 +984,18 @@ def _Session_from_vertex(
970984
if getv(from_object, ["displayName"]) is not None:
971985
setv(to_object, ["display_name"], getv(from_object, ["displayName"]))
972986

987+
if getv(from_object, ["expireTime"]) is not None:
988+
setv(to_object, ["expire_time"], getv(from_object, ["expireTime"]))
989+
973990
if getv(from_object, ["name"]) is not None:
974991
setv(to_object, ["name"], getv(from_object, ["name"]))
975992

976993
if getv(from_object, ["sessionState"]) is not None:
977994
setv(to_object, ["session_state"], getv(from_object, ["sessionState"]))
978995

996+
if getv(from_object, ["ttl"]) is not None:
997+
setv(to_object, ["ttl"], getv(from_object, ["ttl"]))
998+
979999
if getv(from_object, ["updateTime"]) is not None:
9801000
setv(to_object, ["update_time"], getv(from_object, ["updateTime"]))
9811001

@@ -2721,6 +2741,7 @@ def create(
27212741
gcs_dir_name=config.gcs_dir_name,
27222742
extra_packages=config.extra_packages,
27232743
env_vars=config.env_vars,
2744+
service_account=config.service_account,
27242745
context_spec=context_spec,
27252746
)
27262747
operation = self._create(config=api_config)
@@ -2768,6 +2789,7 @@ def _create_config(
27682789
gcs_dir_name: Optional[str] = None,
27692790
extra_packages: Optional[Sequence[str]] = None,
27702791
env_vars: Optional[dict[str, Union[str, Any]]] = None,
2792+
service_account: Optional[str] = None,
27712793
context_spec: Optional[types.ReasoningEngineContextSpecDict] = None,
27722794
) -> types.UpdateAgentEngineConfigDict:
27732795
import sys
@@ -2860,6 +2882,9 @@ def _create_config(
28602882
) = self._generate_deployment_spec_or_raise(env_vars=env_vars)
28612883
update_masks.extend(deployment_update_masks)
28622884
agent_engine_spec["deployment_spec"] = deployment_spec
2885+
if service_account is not None:
2886+
agent_engine_spec["service_account"] = service_account
2887+
update_masks.append("spec.service_account")
28632888
class_methods = _agent_engines_utils._generate_class_methods_spec_or_raise(
28642889
agent_engine=agent_engine,
28652890
operations=_agent_engines_utils._get_registered_operations(
@@ -3072,6 +3097,7 @@ def update(
30723097
gcs_dir_name=config.gcs_dir_name,
30733098
extra_packages=config.extra_packages,
30743099
env_vars=config.env_vars,
3100+
service_account=config.service_account,
30753101
context_spec=context_spec,
30763102
)
30773103
operation = self._update(name=name, config=api_config)
@@ -3128,6 +3154,8 @@ def _stream_query(
31283154
):
31293155
yield response
31303156

3157+
# TODO: b/436704146 - Replace with generated methods
3158+
# TODO: b/437129724 - Add replay test for async stream query
31313159
async def _async_stream_query(
31323160
self,
31333161
*,
Collapse file

‎vertexai/_genai/types.py‎

Copy file name to clipboardExpand all lines: vertexai/_genai/types.py
+52-4Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ class AcceleratorType(_common.CaseInSensitiveEnum):
170170
"""Nvidia H200 141Gb GPU."""
171171
NVIDIA_B200 = "NVIDIA_B200"
172172
"""Nvidia B200 GPU."""
173+
NVIDIA_GB200 = "NVIDIA_GB200"
174+
"""Nvidia GB200 GPU."""
173175
TPU_V2 = "TPU_V2"
174176
"""TPU v2."""
175177
TPU_V3 = "TPU_V3"
@@ -2406,6 +2408,10 @@ class VideoMetadata(_common.BaseModel):
24062408
end_offset: Optional[str] = Field(
24072409
default=None, description="""Optional. The end offset of the video."""
24082410
)
2411+
fps: Optional[float] = Field(
2412+
default=None,
2413+
description="""Optional. The frame rate of the video sent to the model. If not specified, the default value will be 1.0. The fps range is (0.0, 24.0].""",
2414+
)
24092415
start_offset: Optional[str] = Field(
24102416
default=None, description="""Optional. The start offset of the video."""
24112417
)
@@ -2417,6 +2423,9 @@ class VideoMetadataDict(TypedDict, total=False):
24172423
end_offset: Optional[str]
24182424
"""Optional. The end offset of the video."""
24192425

2426+
fps: Optional[float]
2427+
"""Optional. The frame rate of the video sent to the model. If not specified, the default value will be 1.0. The fps range is (0.0, 24.0]."""
2428+
24202429
start_offset: Optional[str]
24212430
"""Optional. The start offset of the video."""
24222431

@@ -3518,6 +3527,10 @@ class ReasoningEngineSpec(_common.BaseModel):
35183527
default=None,
35193528
description="""Optional. User provided package spec of the ReasoningEngine. Ignored when users directly specify a deployment image through `deployment_spec.first_party_image_override`, but keeping the field_behavior to avoid introducing breaking changes.""",
35203529
)
3530+
service_account: Optional[str] = Field(
3531+
default=None,
3532+
description="""Optional. The service account that the Reasoning Engine artifact runs as. It should have "roles/storage.objectViewer" for reading the user project's Cloud Storage and "roles/aiplatform.user" for using Vertex extensions. If not specified, the Vertex AI Reasoning Engine Service Agent in the project will be used.""",
3533+
)
35213534

35223535

35233536
class ReasoningEngineSpecDict(TypedDict, total=False):
@@ -3535,6 +3548,9 @@ class ReasoningEngineSpecDict(TypedDict, total=False):
35353548
package_spec: Optional[ReasoningEngineSpecPackageSpecDict]
35363549
"""Optional. User provided package spec of the ReasoningEngine. Ignored when users directly specify a deployment image through `deployment_spec.first_party_image_override`, but keeping the field_behavior to avoid introducing breaking changes."""
35373550

3551+
service_account: Optional[str]
3552+
"""Optional. The service account that the Reasoning Engine artifact runs as. It should have "roles/storage.objectViewer" for reading the user project's Cloud Storage and "roles/aiplatform.user" for using Vertex extensions. If not specified, the Vertex AI Reasoning Engine Service Agent in the project will be used."""
3553+
35383554

35393555
ReasoningEngineSpecOrDict = Union[ReasoningEngineSpec, ReasoningEngineSpecDict]
35403556

@@ -3544,7 +3560,7 @@ class ReasoningEngineContextSpecMemoryBankConfigGenerationConfig(_common.BaseMod
35443560

35453561
model: Optional[str] = Field(
35463562
default=None,
3547-
description="""Required. The model used to generate memories. Format: `projects/{project}/locations/{location}/publishers/google/models/{model}` or `projects/{project}/locations/{location}/endpoints/{endpoint}`.""",
3563+
description="""Required. The model used to generate memories. Format: `projects/{project}/locations/{location}/publishers/google/models/{model}`.""",
35483564
)
35493565

35503566

@@ -3554,7 +3570,7 @@ class ReasoningEngineContextSpecMemoryBankConfigGenerationConfigDict(
35543570
"""Configuration for how to generate memories."""
35553571

35563572
model: Optional[str]
3557-
"""Required. The model used to generate memories. Format: `projects/{project}/locations/{location}/publishers/google/models/{model}` or `projects/{project}/locations/{location}/endpoints/{endpoint}`."""
3573+
"""Required. The model used to generate memories. Format: `projects/{project}/locations/{location}/publishers/google/models/{model}`."""
35583574

35593575

35603576
ReasoningEngineContextSpecMemoryBankConfigGenerationConfigOrDict = Union[
@@ -3570,7 +3586,7 @@ class ReasoningEngineContextSpecMemoryBankConfigSimilaritySearchConfig(
35703586

35713587
embedding_model: Optional[str] = Field(
35723588
default=None,
3573-
description="""Required. The model used to generate embeddings to lookup similar memories. Format: `projects/{project}/locations/{location}/publishers/google/models/{model}` or `projects/{project}/locations/{location}/endpoints/{endpoint}`.""",
3589+
description="""Required. The model used to generate embeddings to lookup similar memories. Format: `projects/{project}/locations/{location}/publishers/google/models/{model}`.""",
35743590
)
35753591

35763592

@@ -3580,7 +3596,7 @@ class ReasoningEngineContextSpecMemoryBankConfigSimilaritySearchConfigDict(
35803596
"""Configuration for how to perform similarity search on memories."""
35813597

35823598
embedding_model: Optional[str]
3583-
"""Required. The model used to generate embeddings to lookup similar memories. Format: `projects/{project}/locations/{location}/publishers/google/models/{model}` or `projects/{project}/locations/{location}/endpoints/{endpoint}`."""
3599+
"""Required. The model used to generate embeddings to lookup similar memories. Format: `projects/{project}/locations/{location}/publishers/google/models/{model}`."""
35843600

35853601

35863602
ReasoningEngineContextSpecMemoryBankConfigSimilaritySearchConfigOrDict = Union[
@@ -3739,6 +3755,10 @@ class ReasoningEngine(_common.BaseModel):
37393755
default=None,
37403756
description="""Required. The display name of the ReasoningEngine.""",
37413757
)
3758+
encryption_spec: Optional[EncryptionSpec] = Field(
3759+
default=None,
3760+
description="""Customer-managed encryption key spec for a ReasoningEngine. If set, this ReasoningEngine and all sub-resources of this ReasoningEngine will be secured by this key.""",
3761+
)
37423762
etag: Optional[str] = Field(
37433763
default=None,
37443764
description="""Optional. Used to perform consistent read-modify-write updates. If not set, a blind "overwrite" update happens.""",
@@ -3772,6 +3792,9 @@ class ReasoningEngineDict(TypedDict, total=False):
37723792
display_name: Optional[str]
37733793
"""Required. The display name of the ReasoningEngine."""
37743794

3795+
encryption_spec: Optional[EncryptionSpecDict]
3796+
"""Customer-managed encryption key spec for a ReasoningEngine. If set, this ReasoningEngine and all sub-resources of this ReasoningEngine will be secured by this key."""
3797+
37753798
etag: Optional[str]
37763799
"""Optional. Used to perform consistent read-modify-write updates. If not set, a blind "overwrite" update happens."""
37773800

@@ -4117,6 +4140,10 @@ class Session(_common.BaseModel):
41174140
default=None,
41184141
description="""Optional. The display name of the session.""",
41194142
)
4143+
expire_time: Optional[datetime.datetime] = Field(
4144+
default=None,
4145+
description="""Optional. Timestamp of when this session is considered expired. This is *always* provided on output, regardless of what was sent on input.""",
4146+
)
41204147
name: Optional[str] = Field(
41214148
default=None,
41224149
description="""Identifier. The resource name of the session. Format: 'projects/{project}/locations/{location}/reasoningEngines/{reasoning_engine}/sessions/{session}'.""",
@@ -4125,6 +4152,10 @@ class Session(_common.BaseModel):
41254152
default=None,
41264153
description="""Optional. Session specific memory which stores key conversation points.""",
41274154
)
4155+
ttl: Optional[str] = Field(
4156+
default=None,
4157+
description="""Optional. Input only. The TTL for this session.""",
4158+
)
41284159
update_time: Optional[datetime.datetime] = Field(
41294160
default=None,
41304161
description="""Output only. Timestamp when the session was updated.""",
@@ -4144,12 +4175,18 @@ class SessionDict(TypedDict, total=False):
41444175
display_name: Optional[str]
41454176
"""Optional. The display name of the session."""
41464177

4178+
expire_time: Optional[datetime.datetime]
4179+
"""Optional. Timestamp of when this session is considered expired. This is *always* provided on output, regardless of what was sent on input."""
4180+
41474181
name: Optional[str]
41484182
"""Identifier. The resource name of the session. Format: 'projects/{project}/locations/{location}/reasoningEngines/{reasoning_engine}/sessions/{session}'."""
41494183

41504184
session_state: Optional[dict[str, Any]]
41514185
"""Optional. Session specific memory which stores key conversation points."""
41524186

4187+
ttl: Optional[str]
4188+
"""Optional. Input only. The TTL for this session."""
4189+
41534190
update_time: Optional[datetime.datetime]
41544191
"""Output only. Timestamp when the session was updated."""
41554192

@@ -7523,6 +7560,12 @@ class AgentEngineConfig(_common.BaseModel):
75237560
If it is a dictionary, the keys are the environment variable names, and
75247561
the values are the corresponding values.""",
75257562
)
7563+
service_account: Optional[str] = Field(
7564+
default=None,
7565+
description="""The service account to be used for the Agent Engine.
7566+
7567+
If not specified, the default Reasoning Engine P6SA service agent will be used.""",
7568+
)
75267569
context_spec: Optional[ReasoningEngineContextSpec] = Field(
75277570
default=None,
75287571
description="""The context spec to be used for the Agent Engine.""",
@@ -7570,6 +7613,11 @@ class AgentEngineConfigDict(TypedDict, total=False):
75707613
If it is a dictionary, the keys are the environment variable names, and
75717614
the values are the corresponding values."""
75727615

7616+
service_account: Optional[str]
7617+
"""The service account to be used for the Agent Engine.
7618+
7619+
If not specified, the default Reasoning Engine P6SA service agent will be used."""
7620+
75737621
context_spec: Optional[ReasoningEngineContextSpecDict]
75747622
"""The context spec to be used for the Agent Engine."""
75757623

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.