@@ -58,22 +58,26 @@ def generate_project(self, project: Project) -> str:
5858 # Extend config_list with settings['models'] if available
5959 user_settings = self .supabase .fetch_general_settings ()
6060 if user_settings and "general" in user_settings and 'models' in user_settings ["general" ]:
61- config_list .extend (user_settings ["general" ]["models" ])
61+ config_list .extend ([model for model in user_settings ["general" ]["models" ] if model ["enabled" ] == True ])
62+
63+ print ('config_list 1' , config_list )
6264
6365 # Extend config_list with OAI_CONFIG_LIST
6466 config_list .extend (autogen .config_list_from_json (
6567 env_or_file = "OAI_CONFIG_LIST" ,
6668 ))
6769
70+ print ('config_list 2' , config_list )
71+
6872 # Apply filters if any
69- if user_settings and 'filters' in user_settings :
70- config_list = autogen .filter_config (
71- config_list ,
72- filter_dict = {
73- "model" : user_settings ['filters' ].get ('name' , '' ).split (',' ),
74- "tags" : user_settings ['filters' ].get ('tags' , '' ).split (',' ),
75- }
76- )
73+ # if user_settings and 'filters' in user_settings:
74+ # config_list = autogen.filter_config(
75+ # config_list,
76+ # filter_dict={
77+ # "model": user_settings['filters'].get('name', '').split(','),
78+ # "tags": user_settings['filters'].get('tags', '').split(','),
79+ # }
80+ # )
7781
7882 # Check cache first
7983 cache_key = self ._get_cache_key (project )
@@ -182,7 +186,7 @@ def generate_project(self, project: Project) -> str:
182186
183187 # Generate tool assignments
184188 tool_dict = self .build_tool_dict (project )
185- tool_assignments = self .generate_tool_assignments (flow .edges , tool_dict )
189+ tool_assignments = self .generate_tool_assignments (flow .edges , tool_dict , flow . nodes )
186190 print (tool_assignments )
187191 tool_dict = {
188192 tool_id : tool
@@ -290,10 +294,11 @@ def build_tool_dict(self, project: Project):
290294 tools = self .supabase .fetch_tools (tool_ids )
291295 return {tool ["id" ]: tool for tool in tools }
292296
293- def generate_tool_assignments (self , edges , tool_dict ):
297+ def generate_tool_assignments (self , edges , tool_dict , nodes ):
294298 # Prepare the tool assignments
295299 tool_assignments = {}
296300
301+ # First, process the regular tool assignments from edges
297302 for edge in edges :
298303 if edge .get ("data" ) is not None and edge ["data" ].get ("tools" ) is not None :
299304 # Iterate over edge.data.tools.llm and append node.id to the respective tool_id in llm
@@ -310,7 +315,40 @@ def generate_tool_assignments(self, edges, tool_dict):
310315 )
311316 )
312317
313- # Now tool_assignments contains the desired structure
318+ # Now process WebSurferAgent tools
319+ for edge in edges :
320+ target_node = next (
321+ (node for node in nodes if node ["id" ] == edge ["target" ]),
322+ None
323+ )
324+ if target_node and target_node .get ("data" , {}).get ("class_type" ) == "WebSurferAgent" :
325+ # Get the source node (usually a UserProxyAgent) for execution
326+ source_node = next (
327+ (node for node in nodes if node ["id" ] == edge ["source" ]),
328+ None
329+ )
330+ if source_node :
331+ # Get the web tool type from the node's data
332+ web_tool = target_node .get ("data" , {}).get ("web_tool" , "browser_use" )
333+
334+ # Add the tool registration to the generated code
335+ # We don't need to create a mock function or add to tool_dict
336+ # Instead, we'll handle this in the template by registering websurfer.tools
337+ tool_id = f"websurfer_{ target_node ['id' ]} "
338+ if tool_id not in tool_assignments :
339+ tool_assignments [tool_id ] = {
340+ "execution" : [],
341+ "llm" : [],
342+ "is_websurfer" : True , # Flag to indicate this is a WebSurferAgent tool
343+ "web_tool" : web_tool , # Store the web tool type
344+ "websurfer_node_id" : target_node ["id" ] # Store the WebSurferAgent node ID
345+ }
346+
347+ if source_node ["id" ] not in tool_assignments [tool_id ]["execution" ]:
348+ tool_assignments [tool_id ]["execution" ].append (source_node ["id" ])
349+ if target_node ["id" ] not in tool_assignments [tool_id ]["llm" ]:
350+ tool_assignments [tool_id ]["llm" ].append (target_node ["id" ])
351+
314352 return tool_assignments
315353
316354 def generate_rag_assignments (self , edges ):
@@ -324,35 +362,32 @@ def generate_rag_assignments(self, edges):
324362
325363 return rag_assignments
326364
327- def generate_tool_envs (self , project : Project , tool_dict : dict ):
365+ def generate_tool_envs (self , project : Project , tool_dict : dict ) -> dict :
328366 """Generate tool environment files for the provided project.
329367
330368 Args:
331369 project (Project): The project metadata.
370+ tool_dict (dict): Dictionary of tools with their metadata.
332371
333372 Returns:
334373 dict: A dictionary containing the tool IDs as keys and the environment file contents as values.
335374 """
336- for tool in tool_dict .values ():
337- meta = self .extract_tool_meta (tool ["code" ])
338- tool_dict [tool ["id" ]]["func_name" ] = meta ["func_name" ]
339- tool_assignments = self .generate_tool_assignments (project .flow .edges , tool_dict )
340-
375+ # Fetch tool settings from Supabase
341376 tool_settings = self .supabase .fetch_tool_settings ()
342377
343- # Clean unused tools from tool_settings that not included in tool_assignments
378+ # Filter tool_settings to only include tools in tool_dict
344379 tool_settings = {
345380 int (tool_id ): settings
346381 for tool_id , settings in tool_settings .items ()
347- if int (tool_id ) in tool_assignments
382+ if int (tool_id ) in tool_dict
348383 }
349384
385+ # Render the template for each tool
350386 template = self .env .get_template ("tool_env.j2" )
351- tool_envs = {}
352- for tool_id , tool_settings in tool_settings .items ():
353- tool_envs [tool_id ] = template .render (tool_settings = tool_settings )
354-
355- print ("tool_envs" , tool_envs )
387+ tool_envs = {
388+ tool_id : template .render (tool_settings = tool_settings [tool_id ])
389+ for tool_id in tool_settings
390+ }
356391
357392 return tool_envs
358393
0 commit comments