Skip to content

Commit 2315303

Browse files
yifanyangcopybara-github
authored andcommitted
fix: stop deserializing the staged agent from Cloud Storage during Agent Engine deployment
PiperOrigin-RevId: 1004920613
1 parent 9b9f2b3 commit 2315303

4 files changed

Lines changed: 13 additions & 40 deletions

File tree

‎agentplatform/_genai/_runtimes_utils.py‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,11 +1294,6 @@ def _upload_runtime(
12941294
"`from a2a import types`."
12951295
)
12961296
raise TypeError(error_msg) from e
1297-
with blob.open("rb") as f:
1298-
try:
1299-
_ = cloudpickle.load(f)
1300-
except Exception as e:
1301-
raise TypeError("agent runtime serialized to an invalid format") from e
13021297
dir_name = f"gs://{gcs_bucket.name}/{gcs_dir_name}"
13031298
logger.info(f"Wrote to {dir_name}/{_BLOB_FILENAME}")
13041299

‎tests/unit/agentplatform/genai/replays/test_create_agent_engine_a2a.py‎

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
#
1515
# pylint: disable=protected-access,bad-continuation,missing-function-docstring
1616

17-
import contextlib
1817
import os
19-
from unittest import mock
2018
from tests.unit.agentplatform.genai.replays import pytest_helper
2119
from agentplatform._genai import types
2220
from agentplatform.frameworks.a2a import default_a2a_agent
@@ -30,7 +28,7 @@
3028
from a2a.utils.constants import TransportProtocol
3129

3230

33-
def test_create_a2a_agent(client, is_replay_mode):
31+
def test_create_a2a_agent(client):
3432
my_agent = default_a2a_agent()
3533

3634
my_agent.agent_card.supported_interfaces.append(
@@ -44,30 +42,20 @@ def test_create_a2a_agent(client, is_replay_mode):
4442

4543
staging_bucket = os.environ["GCS_BUCKET"]
4644

47-
# In replay mode, GCS operations are mocked and blob.open("rb") returns a mock
48-
# that fails when cloudpickle.load expects bytes. We mock _upload_runtime
49-
# to skip this verification step, which is not needed when replaying API calls.
50-
upload_patch = (
51-
mock.patch("agentplatform._genai._runtimes_utils._upload_runtime")
52-
if is_replay_mode
53-
else contextlib.nullcontext()
45+
runtime = client.runtimes.create(
46+
agent=my_agent,
47+
config={
48+
"staging_bucket": staging_bucket,
49+
"display_name": "test-a2a-agent",
50+
"http_options": {"api_version": "v1beta1"},
51+
"requirements": [
52+
"google-cloud-aiplatform[agent_engines]",
53+
"a2a-sdk",
54+
"sse-starlette",
55+
],
56+
},
5457
)
5558

56-
with upload_patch:
57-
runtime = client.runtimes.create(
58-
agent=my_agent,
59-
config={
60-
"staging_bucket": staging_bucket,
61-
"display_name": "test-a2a-agent",
62-
"http_options": {"api_version": "v1beta1"},
63-
"requirements": [
64-
"google-cloud-aiplatform[agent_engines]",
65-
"a2a-sdk",
66-
"sse-starlette",
67-
],
68-
},
69-
)
70-
7159

7260
assert isinstance(runtime, types.Runtime)
7361
assert runtime.api_resource.display_name == "test-a2a-agent"

‎vertexai/_genai/_agent_engines_utils.py‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,11 +1281,6 @@ def _upload_agent_engine(
12811281
"`from a2a import types`."
12821282
)
12831283
raise TypeError(error_msg) from e
1284-
with blob.open("rb") as f:
1285-
try:
1286-
_ = cloudpickle.load(f)
1287-
except Exception as e:
1288-
raise TypeError("Agent engine serialized to an invalid format") from e
12891284
dir_name = f"gs://{gcs_bucket.name}/{gcs_dir_name}"
12901285
logger.info(f"Wrote to {dir_name}/{_BLOB_FILENAME}")
12911286

‎vertexai/agent_engines/_agent_engines.py‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,11 +1302,6 @@ def _upload_agent_engine(
13021302
"`from a2a import types as a2a_types`."
13031303
)
13041304
raise TypeError(error_msg) from e
1305-
with blob.open("rb") as f:
1306-
try:
1307-
_ = cloudpickle.load(f)
1308-
except Exception as e:
1309-
raise TypeError("Agent engine serialized to an invalid format") from e
13101305
dir_name = f"gs://{gcs_bucket.name}/{gcs_dir_name}"
13111306
logger.info(f"Wrote to {dir_name}/{_BLOB_FILENAME}")
13121307

0 commit comments

Comments
 (0)