1
1
import json
2
2
import shutil
3
+ import sys
3
4
import time
4
5
from datetime import datetime
5
6
from typing import Optional
7
+ import requests
6
8
import itertools
7
9
8
10
from art import text2art
19
21
from ..utils import open_json_file , term_color , is_snake_case
20
22
21
23
22
- def init_project_builder (slug_name : Optional [str ] = None , skip_wizard : bool = False ):
24
+ def init_project_builder (slug_name : Optional [str ] = None , template : Optional [ str ] = None , use_wizard : bool = False ):
23
25
if slug_name and not is_snake_case (slug_name ):
24
26
print (term_color ("Project name must be snake case" , 'red' ))
25
27
return
26
28
27
- if skip_wizard :
29
+ if template is not None and use_wizard :
30
+ print (term_color ("Template and wizard flags cannot be used together" , 'red' ))
31
+ return
32
+
33
+ template_data = None
34
+ if template is not None :
35
+ url_start = "https://"
36
+ if template [:len (url_start )] == url_start :
37
+ # template is a url
38
+ response = requests .get (template )
39
+ if response .status_code == 200 :
40
+ template_data = response .json ()
41
+ else :
42
+ print (term_color (f"Failed to fetch template data from { template } . Status code: { response .status_code } " , 'red' ))
43
+ sys .exit (1 )
44
+ else :
45
+ with importlib .resources .path ('agentstack.templates.proj_templates' , f'{ template } .json' ) as template_path :
46
+ if template_path is None :
47
+ print (term_color (f"No such template { template } found" , 'red' ))
48
+ sys .exit (1 )
49
+ template_data = open_json_file (template_path )
50
+
51
+ if template_data :
28
52
project_details = {
29
- "name" : slug_name or "new_agentstack_project" ,
30
- "version" : "0.1.0" ,
53
+ "name" : slug_name or template_data ['name' ],
54
+ "version" : "0.0.1" ,
55
+ "description" : template_data ['description' ],
56
+ "author" : "Name <Email>" ,
57
+ "license" : "MIT"
58
+ }
59
+ framework = template_data ['framework' ]
60
+ design = {
61
+ 'agents' : template_data ['agents' ],
62
+ 'tasks' : template_data ['tasks' ]
63
+ }
64
+
65
+ tools = template_data ['tools' ]
66
+
67
+ elif use_wizard :
68
+ welcome_message ()
69
+ project_details = ask_project_details (slug_name )
70
+ welcome_message ()
71
+ framework = ask_framework ()
72
+ design = ask_design ()
73
+ tools = ask_tools ()
74
+
75
+ else :
76
+ welcome_message ()
77
+ project_details = {
78
+ "name" : slug_name or "agentstack_project" ,
79
+ "version" : "0.0.1" ,
31
80
"description" : "New agentstack project" ,
32
- "author" : "<NAME >" ,
81
+ "author" : "Name <Email >" ,
33
82
"license" : "MIT"
34
83
}
35
84
@@ -41,21 +90,15 @@ def init_project_builder(slug_name: Optional[str] = None, skip_wizard: bool = Fa
41
90
}
42
91
43
92
tools = []
44
- else :
45
- welcome_message ()
46
- project_details = ask_project_details (slug_name )
47
- welcome_message ()
48
- framework = ask_framework ()
49
- design = ask_design ()
50
- tools = ask_tools ()
51
93
52
94
log .debug (
53
95
f"project_details: { project_details } "
54
96
f"framework: { framework } "
55
97
f"design: { design } "
56
98
)
57
- insert_template (project_details , framework , design )
58
- add_tools (tools , project_details ['name' ])
99
+ insert_template (project_details , framework , design , template_data )
100
+ for tool_data in tools :
101
+ generation .add_tool (tool_data ['name' ], agents = tool_data ['agents' ], path = project_details ['name' ])
59
102
60
103
61
104
def welcome_message ():
@@ -98,11 +141,9 @@ def ask_framework() -> str:
98
141
99
142
100
143
def ask_design () -> dict :
101
- # use_wizard = inquirer.confirm(
102
- # message="Would you like to use the CLI wizard to set up agents and tasks?",
103
- # )
104
-
105
- use_wizard = False
144
+ use_wizard = inquirer .confirm (
145
+ message = "Would you like to use the CLI wizard to set up agents and tasks?" ,
146
+ )
106
147
107
148
if not use_wizard :
108
149
return {
@@ -202,11 +243,9 @@ def ask_design() -> dict:
202
243
203
244
204
245
def ask_tools () -> list :
205
- # use_tools = inquirer.confirm(
206
- # message="Do you want to add agent tools now? (you can do this later with `agentstack tools add <tool_name>`)",
207
- # )
208
-
209
- use_tools = False
246
+ use_tools = inquirer .confirm (
247
+ message = "Do you want to add agent tools now? (you can do this later with `agentstack tools add <tool_name>`)" ,
248
+ )
210
249
211
250
if not use_tools :
212
251
return []
@@ -262,14 +301,16 @@ def ask_project_details(slug_name: Optional[str] = None) -> dict:
262
301
return questions
263
302
264
303
265
- def insert_template (project_details : dict , framework_name : str , design : dict ):
304
+ def insert_template (project_details : dict , framework_name : str , design : dict , template_data : Optional [ dict ] = None ):
266
305
framework = FrameworkData (framework_name .lower ())
267
306
project_metadata = ProjectMetadata (project_name = project_details ["name" ],
268
307
description = project_details ["description" ],
269
308
author_name = project_details ["author" ],
270
- version = project_details [ "version" ] ,
309
+ version = "0.0.1" ,
271
310
license = "MIT" ,
272
- year = datetime .now ().year )
311
+ year = datetime .now ().year ,
312
+ template = template_data ['name' ] if template_data else None ,
313
+ template_version = template_data ['template_version' ] if template_data else None )
273
314
274
315
project_structure = ProjectStructure ()
275
316
project_structure .agents = design ["agents" ]
@@ -321,16 +362,11 @@ def insert_template(project_details: dict, framework_name: str, design: dict):
321
362
)
322
363
323
364
324
- def add_tools (tools : list , project_name : str ):
325
- for tool in tools :
326
- generation .add_tool (tool , project_name )
327
-
328
-
329
365
def list_tools ():
330
366
# Display the tools
331
367
tools = get_all_tools ()
332
368
curr_category = None
333
-
369
+
334
370
print ("\n \n Available AgentStack Tools:" )
335
371
for category , tools in itertools .groupby (tools , lambda x : x .category ):
336
372
if curr_category != category :
0 commit comments