@@ -80,46 +80,46 @@ def remove_import_for_tool(self, tool: ToolConfig, framework: str):
8080
8181def add_tool (tool_name : str , agents : Optional [list [str ]] = []):
8282 agentstack_config = ConfigFile ()
83+ tool = ToolConfig .from_tool_name (tool_name )
8384
8485 if tool_name in agentstack_config .tools :
85- print (term_color (f'Tool { tool_name } is already installed' , 'red' ))
86- sys .exit (1 )
86+ print (term_color (f'Tool { tool_name } is already installed' , 'blue' ))
87+ else : # handle install
88+ tool_file_path = tool .get_impl_file_path (agentstack_config .framework )
8789
88- tool = ToolConfig . from_tool_name ( tool_name )
89- tool_file_path = tool . get_impl_file_path ( agentstack_config . framework )
90+ if tool . packages :
91+ packaging . install ( ' ' . join ( tool . packages ) )
9092
91- if tool . packages :
92- packaging . install ( ' ' . join ( tool .packages ) )
93+ # Move tool from package to project
94+ shutil . copy ( tool_file_path , conf . PATH / f'src/tools/ { tool .module_name } .py' )
9395
94- # Move tool from package to project
95- shutil .copy (tool_file_path , conf .PATH / f'src/tools/{ tool .module_name } .py' )
96+ try : # Edit the user's project tool init file to include the tool
97+ with ToolsInitFile (conf .PATH / TOOLS_INIT_FILENAME ) as tools_init :
98+ tools_init .add_import_for_tool (tool , agentstack_config .framework )
99+ except ValidationError as e :
100+ print (term_color (f"Error adding tool:\n { e } " , 'red' ))
96101
97- try : # Edit the user's project tool init file to include the tool
98- with ToolsInitFile (conf .PATH / TOOLS_INIT_FILENAME ) as tools_init :
99- tools_init .add_import_for_tool (tool , agentstack_config .framework )
100- except ValidationError as e :
101- print (term_color (f"Error adding tool:\n { e } " , 'red' ))
102+ if tool .env : # add environment variables which don't exist
103+ with EnvFile () as env :
104+ for var , value in tool .env .items ():
105+ env .append_if_new (var , value )
106+ with EnvFile (".env.example" ) as env :
107+ for var , value in tool .env .items ():
108+ env .append_if_new (var , value )
109+
110+ if tool .post_install :
111+ os .system (tool .post_install )
112+
113+ with agentstack_config as config :
114+ config .tools .append (tool .name )
102115
103116 # Edit the framework entrypoint file to include the tool in the agent definition
104117 if not agents : # If no agents are specified, add the tool to all agents
105118 agents = frameworks .get_agent_names ()
106119 for agent_name in agents :
120+ print (f'Adding tool { tool .name } to agent { agent_name } ' )
107121 frameworks .add_tool (tool , agent_name )
108122
109- if tool .env : # add environment variables which don't exist
110- with EnvFile () as env :
111- for var , value in tool .env .items ():
112- env .append_if_new (var , value )
113- with EnvFile (".env.example" ) as env :
114- for var , value in tool .env .items ():
115- env .append_if_new (var , value )
116-
117- if tool .post_install :
118- os .system (tool .post_install )
119-
120- with agentstack_config as config :
121- config .tools .append (tool .name )
122-
123123 print (term_color (f'🔨 Tool { tool .name } added to agentstack project successfully' , 'green' ))
124124 if tool .cta :
125125 print (term_color (f'🪩 { tool .cta } ' , 'blue' ))
0 commit comments