diff --git a/src/google/adk/cli/cli_deploy.py b/src/google/adk/cli/cli_deploy.py index d32be35e..bd51e214 100644 --- a/src/google/adk/cli/cli_deploy.py +++ b/src/google/adk/cli/cli_deploy.py @@ -771,25 +771,27 @@ def to_agent_engine( ) agent_config['description'] = description - if not requirements_file: + requirements_txt_path = os.path.join(agent_src_path, 'requirements.txt') + if requirements_file: + if os.path.exists(requirements_txt_path): + click.echo( + f'Overwriting {requirements_txt_path} with {requirements_file}' + ) + shutil.copyfile(requirements_file, requirements_txt_path) + elif 'requirements_file' in agent_config: + if os.path.exists(requirements_txt_path): + click.echo( + f'Overwriting {requirements_txt_path} with' + f' {agent_config["requirements_file"]}' + ) + shutil.copyfile(agent_config['requirements_file'], requirements_txt_path) + else: # Attempt to read requirements from requirements.txt in the dir (if any). - requirements_txt_path = os.path.join(agent_src_path, 'requirements.txt') if not os.path.exists(requirements_txt_path): click.echo(f'Creating {requirements_txt_path}...') with open(requirements_txt_path, 'w', encoding='utf-8') as f: f.write('google-cloud-aiplatform[adk,agent_engines]') click.echo(f'Created {requirements_txt_path}') - agent_config['requirements_file'] = agent_config.get( - 'requirements', - requirements_txt_path, - ) - else: - if 'requirements_file' in agent_config: - click.echo( - 'Overriding requirements in agent engine config with ' - f'{requirements_file}' - ) - agent_config['requirements_file'] = requirements_file agent_config['requirements_file'] = f'{temp_folder}/requirements.txt' env_vars = {}