@@ -112,7 +112,7 @@ def _ensure_agent_engine_dependency(requirements_txt_path: str) -> None:
112112 config_path = os.path.join(os.path.dirname(__file__), "root_agent.yaml")
113113 root_agent = config_agent_utils.from_config(config_path)
114114else:
115- from .agent import {adk_app_object}
115+ from .{agent_module} import {adk_app_object}
116116
117117if {express_mode}: # Whether or not to use Express Mode
118118 vertexai.init(api_key=os.environ.get("GOOGLE_API_KEY"))
@@ -473,6 +473,7 @@ def _validate_agent_import(
473473 agent_src_path : str ,
474474 adk_app_object : str ,
475475 is_config_agent : bool ,
476+ agent_module : str = 'agent' ,
476477) -> None :
477478 """Validates that the agent module can be imported successfully.
478479
@@ -485,6 +486,8 @@ def _validate_agent_import(
485486 agent_src_path: Path to the staged agent source code.
486487 adk_app_object: The Python object name to import ('root_agent' or 'app').
487488 is_config_agent: Whether this is a config-based agent.
489+ agent_module: The Python module name containing the agent object.
490+ Defaults to 'agent'.
488491
489492 Raises:
490493 click.ClickException: If the agent module cannot be imported.
@@ -493,11 +496,12 @@ def _validate_agent_import(
493496 # Config agents are loaded from YAML, skip Python import validation
494497 return
495498
496- agent_module_path = os .path .join (agent_src_path , 'agent .py' )
499+ agent_module_path = os .path .join (agent_src_path , f' { agent_module } .py' )
497500 if not os .path .exists (agent_module_path ):
498501 raise click .ClickException (
499502 f'Agent module not found at { agent_module_path } . '
500- 'Please ensure your agent folder contains an agent.py file.'
503+ f'Please ensure your agent folder contains a { agent_module } .py file,'
504+ ' or use --agent_module to specify a different module name.'
501505 )
502506
503507 # Add the parent directory to sys.path temporarily for import resolution
@@ -818,6 +822,7 @@ def to_agent_engine(
818822 otel_to_cloud : Optional [bool ] = None ,
819823 api_key : Optional [str ] = None ,
820824 adk_app_object : Optional [str ] = None ,
825+ agent_module : Optional [str ] = None ,
821826 agent_engine_id : Optional [str ] = None ,
822827 absolutize_imports : bool = True ,
823828 project : Optional [str ] = None ,
@@ -868,6 +873,9 @@ def to_agent_engine(
868873 will be used. It will only be used if GOOGLE_GENAI_USE_VERTEXAI is true.
869874 adk_app_object (str): Optional. The Python object corresponding to the root
870875 ADK agent or app. Defaults to `root_agent` if not specified.
876+ agent_module (str): Optional. The Python module name (without .py) that
877+ contains the agent object. Defaults to `agent`. Use this when your entry
878+ point is not named `agent.py` (e.g., `core.py` or `adk_agent.py`).
871879 agent_engine_id (str): Optional. The ID of the Agent Engine instance to
872880 update. If not specified, a new Agent Engine instance will be created.
873881 absolutize_imports (bool): Optional. Default is True. Whether to absolutize
@@ -900,6 +908,7 @@ def to_agent_engine(
900908 display_name = display_name or app_name
901909 parent_folder = os .path .dirname (agent_folder )
902910 adk_app_object = adk_app_object or 'root_agent'
911+ agent_module = agent_module or 'agent'
903912 if adk_app_object not in ['root_agent' , 'app' ]:
904913 click .echo (
905914 f'Invalid adk_app_object: { adk_app_object } . Please use "root_agent"'
@@ -1105,7 +1114,9 @@ def to_agent_engine(
11051114 # Validate that the agent module can be imported before deployment.
11061115 if not skip_agent_import_validation :
11071116 click .echo ('Validating agent module...' )
1108- _validate_agent_import (agent_src_path , adk_app_object , is_config_agent )
1117+ _validate_agent_import (
1118+ agent_src_path , adk_app_object , is_config_agent , agent_module
1119+ )
11091120
11101121 adk_app_file = os .path .join (temp_folder , f'{ adk_app } .py' )
11111122 if adk_app_object == 'root_agent' :
@@ -1126,6 +1137,7 @@ def to_agent_engine(
11261137 is_config_agent = is_config_agent ,
11271138 agent_folder = f'./{ temp_folder } ' ,
11281139 adk_app_object = adk_app_object ,
1140+ agent_module = agent_module ,
11291141 adk_app_type = adk_app_type ,
11301142 express_mode = api_key is not None ,
11311143 )
0 commit comments