1414
1515from __future__ import annotations
1616
17+ import enum
1718import os
1819import subprocess
1920from typing import Optional
2021from typing import Tuple
2122
2223import click
2324
25+
26+ class Type (enum .Enum ):
27+ CONFIG = "config"
28+ CODE = "code"
29+
30+
2431_INIT_PY_TEMPLATE = """\
2532 from . import agent
2633"""
3643)
3744"""
3845
46+ _AGENT_CONFIG_TEMPLATE = """\
47+ name: root_agent
48+ description: A helpful assistant for user questions.
49+ instruction: Answer user questions to the best of your knowledge
50+ model: {model_name}
51+ """
52+
3953
4054_GOOGLE_API_MSG = """
4155Don't have API Key? Create one in AI Studio: https://aistudio.google.com/apikey
5165https://google.github.io/adk-docs/agents/models
5266"""
5367
54- _SUCCESS_MSG = """
68+ _SUCCESS_MSG_CODE = """
5569Agent created in {agent_folder}:
5670- .env
5771- __init__.py
5872- agent.py
5973"""
6074
75+ _SUCCESS_MSG_CONFIG = """
76+ Agent created in {agent_folder}:
77+ - .env
78+ - __init__.py
79+ - root_agent.yaml
80+ """
81+
6182
6283def _get_gcp_project_from_gcloud () -> str :
6384 """Uses gcloud to get default project."""
@@ -158,13 +179,15 @@ def _generate_files(
158179 google_cloud_project : Optional [str ] = None ,
159180 google_cloud_region : Optional [str ] = None ,
160181 model : Optional [str ] = None ,
182+ type : Optional [Type ] = None ,
161183):
162184 """Generates a folder name for the agent."""
163185 os .makedirs (agent_folder , exist_ok = True )
164186
165187 dotenv_file_path = os .path .join (agent_folder , ".env" )
166188 init_file_path = os .path .join (agent_folder , "__init__.py" )
167- agent_file_path = os .path .join (agent_folder , "agent.py" )
189+ agent_py_file_path = os .path .join (agent_folder , "agent.py" )
190+ agent_config_file_path = os .path .join (agent_folder , "root_agent.yaml" )
168191
169192 with open (dotenv_file_path , "w" , encoding = "utf-8" ) as f :
170193 lines = []
@@ -180,29 +203,38 @@ def _generate_files(
180203 lines .append (f"GOOGLE_CLOUD_LOCATION={ google_cloud_region } " )
181204 f .write ("\n " .join (lines ))
182205
183- with open (init_file_path , "w" , encoding = "utf-8" ) as f :
184- f .write (_INIT_PY_TEMPLATE )
185-
186- with open (agent_file_path , "w" , encoding = "utf-8" ) as f :
187- f .write (_AGENT_PY_TEMPLATE .format (model_name = model ))
188-
189- click .secho (
190- _SUCCESS_MSG .format (agent_folder = agent_folder ),
191- fg = "green" ,
192- )
206+ if type == Type .CONFIG :
207+ with open (agent_config_file_path , "w" , encoding = "utf-8" ) as f :
208+ f .write (_AGENT_CONFIG_TEMPLATE .format (model_name = model ))
209+ with open (init_file_path , "w" , encoding = "utf-8" ) as f :
210+ f .write ("" )
211+ click .secho (
212+ _SUCCESS_MSG_CONFIG .format (agent_folder = agent_folder ),
213+ fg = "green" ,
214+ )
215+ else :
216+ with open (init_file_path , "w" , encoding = "utf-8" ) as f :
217+ f .write (_INIT_PY_TEMPLATE )
218+
219+ with open (agent_py_file_path , "w" , encoding = "utf-8" ) as f :
220+ f .write (_AGENT_PY_TEMPLATE .format (model_name = model ))
221+ click .secho (
222+ _SUCCESS_MSG_CODE .format (agent_folder = agent_folder ),
223+ fg = "green" ,
224+ )
193225
194226
195227def _prompt_for_model () -> str :
196228 model_choice = click .prompt (
197229 """\
198230 Choose a model for the root agent:
199- 1. gemini-2.0 -flash-001
231+ 1. gemini-2.5 -flash
2002322. Other models (fill later)
201233Choose model""" ,
202234 type = click .Choice (["1" , "2" ]),
203235 )
204236 if model_choice == "1" :
205- return "gemini-2.0 -flash-001 "
237+ return "gemini-2.5 -flash"
206238 else :
207239 click .secho (_OTHER_MODEL_MSG , fg = "green" )
208240 return "<FILL_IN_MODEL>"
@@ -231,13 +263,30 @@ def _prompt_to_choose_backend(
231263 return google_api_key , google_cloud_project , google_cloud_region
232264
233265
266+ def _prompt_to_choose_type () -> Type :
267+ """Prompts user to choose type of agent to create."""
268+ type_choice = click .prompt (
269+ """\
270+ Choose a type for the root agent:
271+ 1. YAML config (experimental, may change without notice)
272+ 2. Code
273+ Choose type""" ,
274+ type = click .Choice (["1" , "2" ]),
275+ )
276+ if type_choice == "1" :
277+ return Type .CONFIG
278+ else :
279+ return Type .CODE
280+
281+
234282def run_cmd (
235283 agent_name : str ,
236284 * ,
237285 model : Optional [str ],
238286 google_api_key : Optional [str ],
239287 google_cloud_project : Optional [str ],
240288 google_cloud_region : Optional [str ],
289+ type : Optional [Type ],
241290):
242291 """Runs `adk create` command to create agent template.
243292
@@ -249,6 +298,7 @@ def run_cmd(
249298 VertexAI as backend.
250299 google_cloud_region: Optional[str], The Google Cloud region for using
251300 VertexAI as backend.
301+ type: Optional[Type], Whether to define agent with config file or code.
252302 """
253303 agent_folder = os .path .join (os .getcwd (), agent_name )
254304 # check folder doesn't exist or it's empty. Otherwise, throw
@@ -272,10 +322,14 @@ def run_cmd(
272322 )
273323 )
274324
325+ if not type :
326+ type = _prompt_to_choose_type ()
327+
275328 _generate_files (
276329 agent_folder ,
277330 google_api_key = google_api_key ,
278331 google_cloud_project = google_cloud_project ,
279332 google_cloud_region = google_cloud_region ,
280333 model = model ,
334+ type = type ,
281335 )
0 commit comments