66from semantic_kernel import Kernel
77from semantic_kernel .functions import KernelFunction
88from semantic_kernel .agents .azure_ai .azure_ai_agent import AzureAIAgent
9+ import inspect
910
1011from models .agent_types import AgentType
1112from kernel_agents .agent_base import BaseAgent
1718from kernel_agents .human_agent import HumanAgent
1819from kernel_agents .marketing_agent import MarketingAgent
1920from kernel_agents .generic_agent import GenericAgent
20- from kernel_agents .planner_agent import PlannerAgent
2121from kernel_agents .tech_support_agent import TechSupportAgent
2222from kernel_agents .procurement_agent import ProcurementAgent
2323from kernel_agents .product_agent import ProductAgent
@@ -41,7 +41,6 @@ class AgentFactory:
4141 AgentType .TECH_SUPPORT : TechSupportAgent ,
4242 AgentType .GENERIC : GenericAgent ,
4343 AgentType .HUMAN : HumanAgent ,
44- AgentType .PLANNER : PlannerAgent ,
4544 AgentType .GROUP_CHAT_MANAGER : GroupChatManager ,
4645 }
4746
@@ -54,7 +53,6 @@ class AgentFactory:
5453 AgentType .TECH_SUPPORT : "tech_support" ,
5554 AgentType .GENERIC : "generic" ,
5655 AgentType .HUMAN : "human" ,
57- AgentType .PLANNER : "planner" ,
5856 AgentType .GROUP_CHAT_MANAGER : "group_chat_manager" ,
5957 }
6058
@@ -67,7 +65,6 @@ class AgentFactory:
6765 AgentType .TECH_SUPPORT : "You are a technical support expert helping with technical issues." ,
6866 AgentType .GENERIC : "You are a helpful assistant ready to help with various tasks." ,
6967 AgentType .HUMAN : "You are representing a human user in the conversation." ,
70- AgentType .PLANNER : "You are a planner agent responsible for creating and managing plans." ,
7168 AgentType .GROUP_CHAT_MANAGER : "You are a group chat manager coordinating the conversation between different agents." ,
7269 }
7370
@@ -128,7 +125,7 @@ async def create_agent(
128125 # Check if we already have an agent in the cache
129126 if session_id in cls ._agent_cache and agent_type in cls ._agent_cache [session_id ]:
130127 return cls ._agent_cache [session_id ][agent_type ]
131-
128+
132129 # Get the agent class
133130 agent_class = cls ._agent_classes .get (agent_type )
134131 if not agent_class :
@@ -177,27 +174,31 @@ async def create_agent(
177174
178175 # Create the agent instance using the project-based pattern
179176 try :
180- agent = agent_class (
181- agent_name = agent_type_str ,
182- kernel = kernel ,
183- session_id = session_id ,
184- user_id = user_id ,
185- memory_store = memory_store ,
186- tools = tools ,
187- system_message = system_message ,
188- client = client ,
189- definition = definition ,
177+ # Filter kwargs to only those accepted by the agent's __init__
178+ agent_init_params = inspect .signature (agent_class .__init__ ).parameters
179+ valid_keys = set (agent_init_params .keys ()) - {"self" }
180+ filtered_kwargs = {k : v for k , v in {
181+ "agent_name" : agent_type_str ,
182+ "kernel" : kernel ,
183+ "session_id" : session_id ,
184+ "user_id" : user_id ,
185+ "memory_store" : memory_store ,
186+ "tools" : tools ,
187+ "system_message" : system_message ,
188+ "client" : client ,
189+ "definition" : definition ,
190190 ** kwargs
191- )
191+ }.items () if k in valid_keys }
192+ agent = agent_class (** filtered_kwargs )
192193 logger .debug (f"[DEBUG] Agent object after instantiation: { agent } " )
193- # Initialize the agent asynchronously
194- init_result = await agent .async_init ()
195- logger .debug (f"[DEBUG] Result of agent.async_init(): { init_result } " )
194+ # Initialize the agent asynchronously if it has async_init
195+ if hasattr (agent , 'async_init' ) and inspect .iscoroutinefunction (agent .async_init ):
196+ init_result = await agent .async_init ()
197+ logger .debug (f"[DEBUG] Result of agent.async_init(): { init_result } " )
196198 # Register tools with Azure AI Agent for LLM function calls
197- if hasattr (agent ._agent , 'add_function' ) and tools :
199+ if hasattr (agent , '_agent' ) and hasattr ( agent ._agent , 'add_function' ) and tools :
198200 for fn in tools :
199201 agent ._agent .add_function (fn )
200-
201202 except Exception as e :
202203 logger .error (
203204 f"Error creating agent of type { agent_type } with parameters: { e } "
0 commit comments