@@ -95,7 +95,7 @@ def __init__(
9595 super ().__init__ (
9696 kernel = kernel ,
9797 deployment_name = None , # Set as needed
98- plugins = None , # Use the loaded plugins,
98+ plugins = tools , # Use the loaded plugins,
9999 endpoint = None , # Set as needed
100100 api_version = None , # Set as needed
101101 token = None , # Set as needed
@@ -119,9 +119,6 @@ def __init__(
119119 # Required properties for AgentGroupChat compatibility
120120 self .name = agent_name # This is crucial for AgentGroupChat to identify agents
121121
122- # Register the handler functions
123- self ._register_functions ()
124-
125122 # @property
126123 # def plugins(self) -> Optional[dict[str, Callable]]:
127124 # """Get the plugins for this agent.
@@ -140,37 +137,17 @@ async def async_init(self):
140137
141138 This method must be called after creating the agent to complete initialization.
142139 """
140+ logging .info (f"Initializing agent: { self ._agent_name } " )
143141 # Create Azure AI Agent or fallback
144142 self ._agent = await config .create_azure_ai_agent (
145143 kernel = self ._kernel ,
146144 agent_name = self ._agent_name ,
147145 instructions = self ._system_message ,
146+ tools = self ._tools ,
148147 )
149148 # Tools are registered with the kernel via get_tools_from_config
150149 return self
151150
152- def _register_functions (self ):
153- """Register this agent's functions with the kernel."""
154- # Use the kernel function decorator approach instead of from_native_method
155- # which isn't available in SK 1.28.0
156- function_name = "handle_action_request"
157-
158- # Define the function using the kernel function decorator
159- @kernel_function (
160- description = "Handle an action request from another agent or the system" ,
161- name = function_name ,
162- )
163- async def handle_action_request_wrapper (* args , ** kwargs ):
164- # Forward to the instance method
165- return await self .handle_action_request (* args , ** kwargs )
166-
167- # Wrap the decorated function into a KernelFunction and register under this agent's plugin
168- kernel_func = KernelFunction .from_method (handle_action_request_wrapper )
169- # Use agent name as plugin for handler
170- self ._kernel .add_function (self ._agent_name , kernel_func )
171-
172- # Required method for AgentGroupChat compatibility
173-
174151 async def handle_action_request (self , action_request : ActionRequest ) -> str :
175152 """Handle an action request from another agent or the system.
176153
@@ -213,9 +190,7 @@ async def handle_action_request(self, action_request: ActionRequest) -> str:
213190
214191 # Call the agent to handle the action
215192 async_generator = self ._agent .invoke (
216- # messages=f"{json.dumps(self._chat_history)}\n\n
217193 messages = f"{ action_request .action } \n \n Please perform this action"
218- # messages=action_request.action
219194 )
220195
221196 response_content = ""
@@ -312,73 +287,11 @@ async def handle_action_request(self, action_request: ActionRequest) -> str:
312287
313288 return response .json ()
314289
315- async def invoke_tool (self , tool_name : str , arguments : Dict [str , Any ]) -> str :
316- """Invoke a specific tool by name with the provided arguments.
317-
318- Args:
319- tool_name: The name of the tool to invoke
320- arguments: A dictionary of arguments to pass to the tool
321-
322- Returns:
323- The result of the tool invocation as a string
324-
325- Raises:
326- ValueError: If the tool is not found
327- """
328- # Find the tool by name in the agent's tools list
329- tool = next ((t for t in self ._tools if t .name == tool_name ), None )
330-
331- if not tool :
332- # Try looking up the tool in the kernel's plugins
333- plugin_name = f"{ self ._agent_name .lower ().replace ('agent' , '' )} _plugin"
334- try :
335- tool = self ._kernel .get_function (plugin_name , tool_name )
336- except Exception :
337- raise ValueError (
338- f"Tool '{ tool_name } ' not found in agent tools or kernel plugins"
339- )
340-
341- if not tool :
342- raise ValueError (f"Tool '{ tool_name } ' not found" )
343-
344- try :
345- # Create kernel arguments from the dictionary
346- kernel_args = KernelArguments ()
347- for key , value in arguments .items ():
348- kernel_args [key ] = value
349-
350- # Invoke the tool
351- logging .info (f"Invoking tool '{ tool_name } ' with arguments: { arguments } " )
352-
353- # Use invoke_with_args_dict directly instead of relying on KernelArguments
354- if hasattr (tool , "invoke_with_args_dict" ) and callable (
355- tool .invoke_with_args_dict
356- ):
357- result = await tool .invoke_with_args_dict (arguments )
358- else :
359- # Fall back to standard invoke method
360- result = await tool .invoke (kernel_args )
361-
362- # Log telemetry if configured
363- track_event_if_configured (
364- "AgentToolInvocation" ,
365- {
366- "agent_name" : self ._agent_name ,
367- "tool_name" : tool_name ,
368- "session_id" : self ._session_id ,
369- "user_id" : self ._user_id ,
370- },
371- )
372-
373- return str (result )
374- except Exception as e :
375- logging .error (f"Error invoking tool '{ tool_name } ': { str (e )} " )
376- raise
377-
378290 @staticmethod
379291 def create_dynamic_function (
380292 name : str ,
381293 response_template : str ,
294+ description : Optional [str ] = None ,
382295 formatting_instr : str = DEFAULT_FORMATTING_INSTRUCTIONS ,
383296 ) -> Callable [..., Awaitable [str ]]:
384297 """Create a dynamic function for agent tools based on the name and template.
@@ -409,7 +322,10 @@ async def dynamic_function(**kwargs) -> str:
409322 dynamic_function .__name__ = name
410323
411324 # Create a wrapped kernel function that matches the expected signature
412- @kernel_function (description = f"Dynamic function: { name } " , name = name )
325+ logging .info (f"Creating dynamic function: { name } { len (name )} " )
326+ logging .info (f"Description: { description } { len (description )} " )
327+
328+ @kernel_function (description = f"Dynamic function { name } " , name = name )
413329 async def kernel_wrapper (
414330 kernel_arguments : KernelArguments = None , ** kwargs
415331 ) -> str :
0 commit comments