def _discover_user_tools(self):
        """Scan the user tools directory for custom tools."""
        # Add user_tools directory to Python path if needed
        if self.user_tools_path not in sys.path:
            sys.path.append(os.path.dirname(self.user_tools_path))

        user_tools_pkg_name = os.path.basename(self.user_tools_path)

        # Check all Python files in user_tools directory
        for filename in os.listdir(self.user_tools_path):
            if (
                not filename.endswith(".py")
                or filename.startswith("_")
                or filename.startswith(".")
            ):
                continue

            module_name = filename[:-3]  # Remove .py extension

            try:
                # Import the module
                module = importlib.import_module(
                    f"{user_tools_pkg_name}.{module_name}"
                )

                # Find all tool classes in the module
                for name, obj in inspect.getmembers(module, inspect.isclass):
                    if (
                        issubclass(obj, Tool)
                        and obj.__module__ == module.__name__
                        and obj != Tool
                    ):
                        try:
                            tool_instance = obj()
                            self._user_tools[tool_instance.name] = obj
                            logger.debug(
                                f"Loaded user tool: {tool_instance.name}"
                            )
                        except Exception as e:
                            logger.error(
                                f"Error instantiating user tool {name}: {e}"
                            )
            except Exception as e:
                logger.error(
                    f"Error loading user tool module {module_name}: {e}"
                )
Scan the user tools directory for custom tools.
py/core/base/agent/tools/registry.py