def prepare_loading(
        self,
        use_flag: bool,
        dynamic_sub_path: bool,
        base_path: str,
        memory: Optional[Memory],
        loaded_from_attr: str,
        item_type: Literal["experience", "example"],
    ) -> Optional[str]:
        """Prepare for loading by checking configurations and memory, and return load_from path if applicable."""
        if not use_flag:
            setattr(self, f"{item_type}s", [])
            return None

        if not os.path.exists(base_path):
            raise FileNotFoundError(
                f"The default {item_type} base path {base_path} does not exist."
                f"The original {item_type} base paths have been changed to `{item_type}s` folder."
                f"Please migrate the {item_type}s to the new base path.",
            )

        sub_path = ""
        if dynamic_sub_path:
            assert memory is not None, f"Memory should be provided when dynamic_{item_type}_sub_path is True"
            sub_paths = memory.get_shared_memory_entries(entry_type=f"{item_type}_sub_path")
            if sub_paths:
                self.tracing.set_span_attribute(f"{item_type}_sub_path", str(sub_paths))
                # todo: handle multiple sub paths
                sub_path = sub_paths[0].content
            else:
                self.logger.info(f"No {item_type} sub path found in memory.")
                setattr(self, f"{item_type}s", [])
                return None

        load_from = os.path.join(base_path, sub_path)
        if getattr(self, loaded_from_attr) is not None and getattr(self, loaded_from_attr) == load_from:
            self.logger.info(f"{item_type.capitalize()} already loaded from {load_from}.")
            return None

        setattr(self, loaded_from_attr, load_from)
        return sub_path
Prepare for loading by checking configurations and memory, and return load_from path if applicable.
taskweaver/role/role.py