def load_agent(self, name: str): try: plugin = importlib.import_module( f'clai.server.plugins.{name}.{name}', package=name) for _, class_member in inspect.getmembers(plugin, inspect.isclass): if issubclass(class_member, Agent) and (class_member is not Agent): member = class_member() if not member: member = ClaiIdentity() self.__plugins[name] = member member.init_agent() member.ready = True logger.info(f"{name} is ready") # pylint: disable=broad-except except Exception as ex: logger.info(f'load agent exception: {ex}')
def get_instances(self, user_name: str, agent_to_select: str = None) -> List[Agent]: select_plugins_by_user = self.__get_selected_by_user(user_name) if select_plugins_by_user is None: self.init_plugin_config(user_name) select_plugins_by_user = self.__get_selected_by_user(user_name) if agent_to_select: agent_descriptor_selected = self.get_agent_descriptor( agent_to_select) if agent_descriptor_selected is None: return [ClaiIdentity()] select_plugins_by_user = list( filter( lambda value: value.name == agent_descriptor_selected. pkg_name, select_plugins_by_user)) if agent_to_select: agent_descriptor_selected = self.get_agent_descriptor( agent_to_select) if agent_descriptor_selected is None: return [ClaiIdentity()] select_plugins_by_user = list( filter( lambda value: value.name == agent_descriptor_selected. pkg_name, select_plugins_by_user)) agents = [] for select_plugin_by_user in select_plugins_by_user: if select_plugin_by_user.name in self.__plugins: agent = self.__plugins[select_plugin_by_user.name] if agent.ready: agents.append(agent) if not agents: agents.append(ClaiIdentity()) return agents