3232)
3333from event_utils import track_event_if_configured
3434from app_config import config
35+ from kernel_tools .hr_tools import HrTools
36+ from kernel_tools .generic_tools import GenericTools
37+ from kernel_tools .marketing_tools import MarketingTools
38+ from kernel_tools .procurement_tools import ProcurementTools
39+ from kernel_tools .product_tools import ProductTools
40+ from kernel_tools .tech_support_tools import TechSupportTools
3541
3642
3743class PlannerAgent (BaseAgent ):
@@ -50,7 +56,6 @@ def __init__(
5056 system_message : Optional [str ] = None ,
5157 agent_name : str = AgentType .PLANNER .value ,
5258 available_agents : List [str ] = None ,
53- agent_tools_list : List [str ] = None ,
5459 agent_instances : Optional [Dict [str , BaseAgent ]] = None ,
5560 client = None ,
5661 definition = None ,
@@ -97,7 +102,15 @@ def __init__(
97102 AgentType .TECH_SUPPORT .value ,
98103 AgentType .GENERIC .value ,
99104 ]
100- self ._agent_tools_list = agent_tools_list or []
105+ self ._agent_tools_list = {
106+ AgentType .HR : HrTools .generate_tools_json_doc (),
107+ AgentType .MARKETING : MarketingTools .generate_tools_json_doc (),
108+ AgentType .PRODUCT : ProductTools .generate_tools_json_doc (),
109+ AgentType .PROCUREMENT : ProcurementTools .generate_tools_json_doc (),
110+ AgentType .TECH_SUPPORT : TechSupportTools .generate_tools_json_doc (),
111+ AgentType .GENERIC : GenericTools .generate_tools_json_doc (),
112+ }
113+
101114 self ._agent_instances = agent_instances or {}
102115
103116 @staticmethod
@@ -311,8 +324,6 @@ async def _create_structured_plan(
311324 kernel_args = KernelArguments (** args )
312325 # kernel_args["input"] = f"TASK: {input_task.description}\n\n{instruction}"
313326
314- logging .info (f"Kernel arguments: { kernel_args } " )
315-
316327 # Get the schema for our expected response format
317328
318329 # Ensure we're using the right pattern for Azure AI agents with semantic kernel
@@ -522,177 +533,9 @@ def _generate_args(self, objective: str) -> any:
522533 # Create list of available tools in JSON-like format
523534 tools_list = []
524535
525- # Check if we have agent instances to extract tools from
526- if hasattr (self , "_agent_instances" ) and self ._agent_instances :
527- # Process each agent to get their tools
528- for agent_name , agent in self ._agent_instances .items ():
529- # First try to get tools directly from the agent's corresponding tool class
530- tools_dict = None
531-
532- # Try to access plugins property which returns the get_all_kernel_functions result
533- if hasattr (agent , "plugins" ):
534- try :
535- # Access plugins as a property, not a method
536- tools_dict = agent .plugins
537- logging .info (
538- f"Got tools dictionary from { agent_name } 's plugins property"
539- )
540-
541- # Check if tools_dict is a list or a dictionary
542- if isinstance (tools_dict , list ):
543- # Convert list to dictionary if needed
544- tools_dict_converted = {}
545- for i , func in enumerate (tools_dict ):
546- func_name = getattr (func , "__name__" , f"function_{ i } " )
547- tools_dict_converted [func_name ] = func
548- tools_dict = tools_dict_converted
549- logging .info (
550- f"Converted tools list to dictionary for { agent_name } "
551- )
552-
553- except Exception as e :
554- logging .warning (
555- f"Error accessing plugins property for { agent_name } : { e } "
556- )
557-
558- # Process tools from tools_dict if available
559- if tools_dict :
560- for func_name , func in tools_dict .items ():
561- # Check if the function has necessary attributes
562- if hasattr (func , "__name__" ) and hasattr (func , "__doc__" ):
563- description = func .__doc__ or f"Function { func_name } "
564-
565- # Create tool entry
566- tool_entry = {
567- "agent" : agent_name ,
568- "function" : func_name ,
569- "description" : description ,
570- "arguments" : "{}" , # Default empty dict
571- }
572-
573- tools_list .append (tool_entry )
574-
575- # Fall back to the previous approach if no tools_dict found
576- elif hasattr (agent , "_tools" ) and agent ._tools :
577- # Add each tool from this agent
578- for tool in agent ._tools :
579- if hasattr (tool , "name" ) and hasattr (tool , "description" ):
580- # Extract function parameters/arguments
581- args_dict = {}
582- if hasattr (tool , "parameters" ):
583- # Check if we have kernel_arguments that need to be processed
584- has_kernel_args = any (
585- param .name == "kernel_arguments"
586- for param in tool .parameters
587- )
588- has_kwargs = any (
589- param .name == "kwargs" for param in tool .parameters
590- )
591-
592- # Process regular parameters first
593- for param in tool .parameters :
594- # Skip kernel_arguments and kwargs as we'll handle them specially
595- if param .name in ["kernel_arguments" , "kwargs" ]:
596- continue
597-
598- param_type = "string" # Default type
599- if hasattr (param , "type" ):
600- param_type = param .type
601-
602- args_dict [param .name ] = {
603- "description" : (
604- param .description
605- if param .description
606- else param .name
607- ),
608- "title" : param .name .replace ("_" , " " ).title (),
609- "type" : param_type ,
610- }
611-
612- # If we have a kernel_arguments parameter, introspect it to extract its values
613- # This is a special case handling for kernel_arguments to include its fields in the arguments
614- if has_kernel_args :
615- # Check if we have kernel_parameter_descriptions
616- if hasattr (tool , "kernel_parameter_descriptions" ):
617- # Extract parameter descriptions from the kernel
618- for (
619- key ,
620- description ,
621- ) in tool .kernel_parameter_descriptions .items ():
622- if (
623- key not in args_dict
624- ): # Only add if not already added
625- args_dict [key ] = {
626- "description" : (
627- description
628- if description
629- else key
630- ),
631- "title" : key .replace (
632- "_" , " "
633- ).title (),
634- "type" : "string" , # Default to string type
635- }
636- # Fall back to function's description if no specific descriptions
637- elif hasattr (tool , "description" ) and not args_dict :
638- # Add a generic parameter with the function's description
639- args_dict ["input" ] = {
640- "description" : f"Input for { tool .name } : { tool .description } " ,
641- "title" : "Input" ,
642- "type" : "string" ,
643- }
644-
645- # If after all processing, arguments are still empty, add a dummy input parameter
646- if not args_dict :
647- args_dict ["input" ] = {
648- "description" : f"Input for { tool .name } " ,
649- "title" : "Input" ,
650- "type" : "string" ,
651- }
652-
653- # Create tool entry
654- tool_entry = {
655- "agent" : agent_name ,
656- "function" : tool .name ,
657- "description" : tool .description ,
658- "arguments" : str (args_dict ),
659- }
660-
661- tools_list .append (tool_entry )
662-
663- logging .info (f"Generated { len (tools_list )} tools from agent instances" )
664-
665- # If we couldn't extract tools from agent instances, create a simplified format
666- if not tools_list :
667- logging .warning (
668- "No tool details extracted from agent instances, creating simplified format"
669- )
670- if self ._agent_tools_list :
671- # Create dummy entries from the existing tool list strings
672- for tool_str in self ._agent_tools_list :
673- if ":" in tool_str :
674- parts = tool_str .split (":" )
675- if len (parts ) >= 2 :
676- agent_part = parts [0 ].strip ()
677- function_part = parts [1 ].strip ()
678-
679- # Extract agent name if format is "Agent: AgentName"
680- agent_name = agent_part .replace ("Agent" , "" ).strip ()
681- if not agent_name :
682- agent_name = AgentType .GENERIC .value
683-
684- tools_list .append (
685- {
686- "agent" : agent_name ,
687- "function" : function_part ,
688- "description" : f"Function { function_part } from { agent_name } " ,
689- "arguments" : "{}" ,
690- }
691- )
692-
693- # Convert the tools list to a string representation
694- logging .info (f"Tools list: { len (tools_list )} " )
695- logging
536+ for agent_name , tools in self ._agent_tools_list .items ():
537+ if agent_name in self ._available_agents :
538+ tools_list .append (tools )
696539
697540 tools_str = str (tools_list )
698541
0 commit comments