import importlib import logging from pathlib import Path def load_bots(bots_path: Path): bots = {} for file in bots_path.glob("*.py"): if file.name.startswith("_"): continue # Skip files that are clearly tools, not bot profiles if file.name.endswith("_tool.py"): logging.info(f"Skipping tool file in bots directory: {file.name}") continue module_name = f"bots.{file.stem}" try: module = importlib.import_module(module_name) # Check if BOT_IDENTIFIER exists if not hasattr(module, "BOT_IDENTIFIER"): logging.warning(f"Bot {file.name} missing BOT_IDENTIFIER, skipping") continue identifier = module.BOT_IDENTIFIER bots[identifier] = module logging.info(f"Loaded bot profile: {identifier}") except Exception: logging.error(f"Failed to load bot {file.name}", exc_info=True) return bots