@@ -148,12 +148,10 @@ def get_message_tool(self) -> FunctionTool:
148148 """
149149 return FunctionTool (self .send_message_to_user )
150150
151- def register_toolkits (
152- self , toolkit : BaseToolkit , tool_names : Optional [List [str ]] = None
153- ) -> BaseToolkit :
154- r"""Add messaging capabilities to toolkit methods.
151+ def register_toolkits (self , toolkit : BaseToolkit ) -> BaseToolkit :
152+ r"""Add messaging capabilities to all toolkit methods.
155153
156- This method modifies a toolkit so that specified tools can send
154+ This method modifies a toolkit so that all its tools can send
157155 status messages to users while executing their primary function.
158156 The tools will accept optional messaging parameters:
159157 - message_title: Title of the status message
@@ -162,20 +160,18 @@ def register_toolkits(
162160
163161 Args:
164162 toolkit: The toolkit to add messaging capabilities to
165- tool_names: List of specific tool names to modify.
166- If None, messaging is added to all tools.
167163
168164 Returns:
169- The toolkit with messaging capabilities added
165+ The same toolkit instance with messaging capabilities added to
166+ all methods.
170167 """
171168 original_tools = toolkit .get_tools ()
172169 enhanced_methods = {}
173170 for tool in original_tools :
174171 method_name = tool .func .__name__
175- if tool_names is None or method_name in tool_names :
176- enhanced_func = self ._add_messaging_to_tool (tool .func )
177- enhanced_methods [method_name ] = enhanced_func
178- setattr (toolkit , method_name , enhanced_func )
172+ enhanced_func = self ._add_messaging_to_tool (tool .func )
173+ enhanced_methods [method_name ] = enhanced_func
174+ setattr (toolkit , method_name , enhanced_func )
179175 original_get_tools_method = toolkit .get_tools
180176
181177 def enhanced_get_tools () -> List [FunctionTool ]:
@@ -201,7 +197,7 @@ def enhanced_get_tools() -> List[FunctionTool]:
201197 def enhanced_clone_for_new_session (new_session_id = None ):
202198 cloned_toolkit = original_clone_method (new_session_id )
203199 return message_integration_instance .register_toolkits (
204- cloned_toolkit , tool_names
200+ cloned_toolkit
205201 )
206202
207203 toolkit .clone_for_new_session = enhanced_clone_for_new_session
@@ -300,6 +296,12 @@ def _add_messaging_to_tool(self, func: Callable) -> Callable:
300296 This internal method modifies the function signature and docstring
301297 to include optional messaging parameters that trigger status updates.
302298 """
299+ if getattr (func , "__message_integration_enhanced__" , False ):
300+ logger .debug (
301+ f"Function { func .__name__ } already enhanced, skipping"
302+ )
303+ return func
304+
303305 # Get the original signature
304306 original_sig = inspect .signature (func )
305307
0 commit comments