fix: fix agent config path handling in generated deployment script

The generated agent deployment script now uses os.path.join and os.path.dirname(__file__) to construct the path to root_agent.yaml. This prevents issues where backslashes in Windows paths could be misinterpreted as Python escape sequences within the f-string, leading to syntax error

Close #4223

Co-authored-by: George Weale <gweale@google.com>
PiperOrigin-RevId: 860236820
This commit is contained in:
George Weale
2026-01-23 13:39:32 -08:00
committed by Copybara-Service
parent 025b42c836
commit 801233902b
2 changed files with 15 additions and 1 deletions
+2 -1
View File
@@ -105,7 +105,8 @@ from vertexai.agent_engines import AdkApp
if {is_config_agent}:
from google.adk.agents import config_agent_utils
root_agent = config_agent_utils.from_config("{agent_folder}/root_agent.yaml")
config_path = os.path.join(os.path.dirname(__file__), "root_agent.yaml")
root_agent = config_agent_utils.from_config(config_path)
else:
from .agent import {adk_app_object}
@@ -226,6 +226,19 @@ def test_get_service_option_by_adk_version(
assert actual.rstrip() == expected.rstrip()
def test_agent_engine_app_template_compiles_with_windows_paths() -> None:
"""It should not emit invalid Python when paths contain `\\u` segments."""
rendered = cli_deploy._AGENT_ENGINE_APP_TEMPLATE.format(
is_config_agent=True,
agent_folder=r".\user_agent_tmp20260101_000000",
adk_app_object="root_agent",
adk_app_type="agent",
trace_to_cloud_option=False,
express_mode=False,
)
compile(rendered, "<agent_engine_app.py>", "exec")
@pytest.mark.parametrize("include_requirements", [True, False])
def test_to_agent_engine_happy_path(
monkeypatch: pytest.MonkeyPatch,