Skip to content

Commit 0dd3ccd

Browse files
yeesiancopybara-github
authored andcommitted
chore: Add logging when deleting agent engine resource
PiperOrigin-RevId: 816278193
1 parent b72df1c commit 0dd3ccd

File tree

3 files changed

+69
-6
lines changed

3 files changed

+69
-6
lines changed

tests/unit/vertexai/genai/replays/test_delete_agent_engine.py

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

17+
import logging
1718
import pytest
1819

1920

2021
from tests.unit.vertexai.genai.replays import pytest_helper
2122
from vertexai._genai import types
2223

2324

24-
def test_agent_engine_delete(client):
25+
def test_agent_engine_delete(client, caplog):
26+
caplog.set_level(logging.INFO)
2527
agent_engine = client.agent_engines.create()
2628
operation = client.agent_engines.delete(name=agent_engine.api_resource.name)
2729
assert isinstance(operation, types.DeleteAgentEngineOperation)
30+
assert "Deleting AgentEngine resource" in caplog.text
31+
assert f"Started AgentEngine delete operation: {operation.name}" in caplog.text
2832

2933

3034
pytestmark = pytest_helper.setup(
@@ -38,10 +42,13 @@ def test_agent_engine_delete(client):
3842

3943

4044
@pytest.mark.asyncio
41-
async def test_agent_engine_delete_async(client):
45+
async def test_agent_engine_delete_async(client, caplog):
46+
caplog.set_level(logging.INFO)
4247
# TODO(b/431785750): use async methods for create() when available
4348
agent_engine = client.agent_engines.create()
4449
operation = await client.aio.agent_engines.delete(
4550
name=agent_engine.api_resource.name
4651
)
4752
assert isinstance(operation, types.DeleteAgentEngineOperation)
53+
assert "Deleting AgentEngine resource" in caplog.text
54+
assert f"Started AgentEngine delete operation: {operation.name}" in caplog.text

tests/unit/vertexai/genai/test_agent_engines.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,7 +2271,7 @@ def teardown_method(self):
22712271

22722272
def test_delete_agent_engine(self):
22732273
with mock.patch.object(
2274-
self.client.agent_engines._api_client, "async_request"
2274+
self.client.aio.agent_engines._api_client, "async_request"
22752275
) as request_mock:
22762276
request_mock.return_value = genai_types.HttpResponse(body="")
22772277
asyncio.run(
@@ -2288,7 +2288,7 @@ def test_delete_agent_engine(self):
22882288

22892289
def test_delete_agent_engine_force(self):
22902290
with mock.patch.object(
2291-
self.client.agent_engines._api_client, "async_request"
2291+
self.client.aio.agent_engines._api_client, "async_request"
22922292
) as request_mock:
22932293
request_mock.return_value = genai_types.HttpResponse(body="")
22942294
asyncio.run(

vertexai/_genai/agent_engines.py

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def _create(
318318
self._api_client._verify_response(return_value)
319319
return return_value
320320

321-
def delete(
321+
def _delete(
322322
self,
323323
*,
324324
name: str,
@@ -725,6 +725,34 @@ def get(
725725
self._register_api_methods(agent_engine=agent_engine)
726726
return agent_engine
727727

728+
def delete(
729+
self,
730+
*,
731+
name: str,
732+
force: Optional[bool] = None,
733+
config: Optional[types.DeleteAgentEngineConfigOrDict] = None,
734+
) -> types.DeleteAgentEngineOperation:
735+
"""
736+
Delete an Agent Engine resource.
737+
738+
Args:
739+
name (str):
740+
Required. The name of the Agent Engine to be deleted. Format:
741+
`projects/{project}/locations/{location}/reasoningEngines/{resource_id}`
742+
or `reasoningEngines/{resource_id}`.
743+
force (bool):
744+
Optional. If set to True, child resources will also be deleted.
745+
Otherwise, the request will fail with FAILED_PRECONDITION error when
746+
the Agent Engine has undeleted child resources. Defaults to False.
747+
config (DeleteAgentEngineConfig):
748+
Optional. Additional configurations for deleting the Agent Engine.
749+
750+
"""
751+
logger.info(f"Deleting AgentEngine resource: {name}")
752+
operation = self._delete(name=name, force=force, config=config)
753+
logger.info(f"Started AgentEngine delete operation: {operation.name}")
754+
return operation
755+
728756
def create(
729757
self,
730758
*,
@@ -1659,7 +1687,7 @@ async def _create(
16591687
self._api_client._verify_response(return_value)
16601688
return return_value
16611689

1662-
async def delete(
1690+
async def _delete(
16631691
self,
16641692
*,
16651693
name: str,
@@ -1994,6 +2022,34 @@ async def _update(
19942022
_memories = None
19952023
_sessions = None
19962024

2025+
async def delete(
2026+
self,
2027+
*,
2028+
name: str,
2029+
force: Optional[bool] = None,
2030+
config: Optional[types.DeleteAgentEngineConfigOrDict] = None,
2031+
) -> types.DeleteAgentEngineOperation:
2032+
"""
2033+
Delete an Agent Engine resource.
2034+
2035+
Args:
2036+
name (str):
2037+
Required. The name of the Agent Engine to be deleted. Format:
2038+
`projects/{project}/locations/{location}/reasoningEngines/{resource_id}`
2039+
or `reasoningEngines/{resource_id}`.
2040+
force (bool):
2041+
Optional. If set to True, child resources will also be deleted.
2042+
Otherwise, the request will fail with FAILED_PRECONDITION error when
2043+
the Agent Engine has undeleted child resources. Defaults to False.
2044+
config (DeleteAgentEngineConfig):
2045+
Optional. Additional configurations for deleting the Agent Engine.
2046+
2047+
"""
2048+
logger.info(f"Deleting AgentEngine resource: {name}")
2049+
operation = await self._delete(name=name, force=force, config=config)
2050+
logger.info(f"Started AgentEngine delete operation: {operation.name}")
2051+
return operation
2052+
19972053
@property
19982054
def memories(self):
19992055
if self._memories is None:

0 commit comments

Comments
 (0)