From cfb44c45e341e3f0da98af3b73ab809c97405fbb Mon Sep 17 00:00:00 2001 From: A Vertex SDK engineer Date: Tue, 22 Sep 2026 18:29:28 -0700 Subject: [PATCH] fix: Keep AdkApp subclass, plugins and credential_service_builder in clone() PiperOrigin-RevId: 986375881 --- .../test_reasoning_engine_templates_adk.py | 25 +++++++++++++++++++ .../reasoning_engines/templates/adk.py | 6 ++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/tests/unit/vertex_adk/test_reasoning_engine_templates_adk.py b/tests/unit/vertex_adk/test_reasoning_engine_templates_adk.py index a1eac3ce62..7911eb7dde 100644 --- a/tests/unit/vertex_adk/test_reasoning_engine_templates_adk.py +++ b/tests/unit/vertex_adk/test_reasoning_engine_templates_adk.py @@ -418,6 +418,31 @@ def test_clone(self): app_clone.set_up() assert app_clone._tmpl_attrs.get("runner") is not None + def test_clone_preserves_subclass(self): + class CustomAdkApp(reasoning_engines.AdkApp): + pass + + app = CustomAdkApp( + agent=Agent(name=_TEST_AGENT_NAME, model=_TEST_MODEL), + ) + assert isinstance(app.clone(), CustomAdkApp) + + def test_clone_preserves_plugins_and_credential_service_builder(self): + def credential_service_builder(): + return None + + app = reasoning_engines.AdkApp( + agent=Agent(name=_TEST_AGENT_NAME, model=_TEST_MODEL), + plugins=["test_plugin"], + credential_service_builder=credential_service_builder, + ) + app_clone = app.clone() + assert app_clone._tmpl_attrs.get("plugins") == ["test_plugin"] + assert ( + app_clone._tmpl_attrs.get("credential_service_builder") + is credential_service_builder + ) + def test_register_operations(self): app = reasoning_engines.AdkApp( agent=Agent(name=_TEST_AGENT_NAME, model=_TEST_MODEL), diff --git a/vertexai/preview/reasoning_engines/templates/adk.py b/vertexai/preview/reasoning_engines/templates/adk.py index 5e76221601..fadaffa8a1 100644 --- a/vertexai/preview/reasoning_engines/templates/adk.py +++ b/vertexai/preview/reasoning_engines/templates/adk.py @@ -846,12 +846,16 @@ def clone(self): """Returns a clone of the ADK application.""" import copy - return AdkApp( + return self.__class__( agent=copy.deepcopy(self._tmpl_attrs.get("agent")), + plugins=copy.deepcopy(self._tmpl_attrs.get("plugins")), enable_tracing=self._tmpl_attrs.get("enable_tracing"), session_service_builder=self._tmpl_attrs.get("session_service_builder"), artifact_service_builder=self._tmpl_attrs.get("artifact_service_builder"), memory_service_builder=self._tmpl_attrs.get("memory_service_builder"), + credential_service_builder=self._tmpl_attrs.get( + "credential_service_builder" + ), env_vars=self._tmpl_attrs.get("env_vars"), )