{"record":{"id":"140b617f1ab8aa92","repo":"FoundationAgents/MetaGPT","slug":"item-list-is-empty","errorCode":null,"errorMessage":"Item list is empty.","messagePattern":"Item list is empty\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"metagpt/ext/aflow/scripts/optimizer_utils/data_utils.py","lineNumber":50,"sourceCode":"\n        first_round = next((item for item in self.top_scores if item[\"round\"] == 1), None)\n        if first_round:\n            unique_top_scores.append(first_round)\n            unique_rounds.add(1)\n\n        for item in self.top_scores:\n            if item[\"round\"] not in unique_rounds:\n                unique_top_scores.append(item)\n                unique_rounds.add(item[\"round\"])\n\n                if len(unique_top_scores) >= sample:\n                    break\n\n        return unique_top_scores\n\n    def select_round(self, items):\n        if not items:\n            raise ValueError(\"Item list is empty.\")\n\n        sorted_items = sorted(items, key=lambda x: x[\"score\"], reverse=True)\n        scores = [item[\"score\"] * 100 for item in sorted_items]\n\n        probabilities = self._compute_probabilities(scores)\n        logger.info(f\"\\nMixed probability distribution: {probabilities}\")\n        logger.info(f\"\\nSorted rounds: {sorted_items}\")\n\n        selected_index = np.random.choice(len(sorted_items), p=probabilities)\n        logger.info(f\"\\nSelected index: {selected_index}, Selected item: {sorted_items[selected_index]}\")\n\n        return sorted_items[selected_index]\n\n    def _compute_probabilities(self, scores, alpha=0.2, lambda_=0.3):\n        scores = np.array(scores, dtype=np.float64)\n        n = len(scores)\n\n        if n == 0:","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/ext/aflow/scripts/optimizer_utils/data_utils.py#L32-L68","documentation":"Raised by DataUtils.select_round when the `items` argument is an empty list. select_round sorts rounds by score and samples one via a mixed probability distribution, so it cannot operate without at least one candidate. In the AFlow optimizer this means there was no historical round data to sample experience from.","triggerScenarios":"Calling select_round(items) with items == [] — typically the result of filtering top_scores/experience data by round or score and matching nothing, or running the optimizer on a fresh experience directory with no scored rounds yet.","commonSituations":"First AFlow optimization run where no experience has been recorded; experience JSON filtered by a round that does not exist; a corrupted or empty scored results file.","solutions":["Check that prior optimization rounds have been scored and persisted before selecting a round to reuse","Verify the experience/results directory passed to DataUtils actually contains scored entries","Guard the caller: skip selection (e.g. fall back to the default graph) when the filtered item list is empty"],"exampleFix":"// before\nround = data_utils.select_round(items)\n\n// after\nif not items:\n    round = None  # or use default graph / run a fresh round\nelse:\n    round = data_utils.select_round(items)","handlingStrategy":"validation","validationCode":"if not items:\n    raise/return early before calling select_round","typeGuard":"def has_selectable_rounds(items: list[dict]) -> bool:\n    return isinstance(items, list) and len(items) > 0 and all(\"score\" in i and \"round\" in i for i in items)","tryCatchPattern":"try:\n    round_ = du.select_round(items)\nexcept ValueError as e:\n    logger.warning(f\"no rounds to select: {e}\")\n    round_ = None","preventionTips":["Ensure at least one optimization round is scored and persisted before sampling experience","Filter experience data defensively and check emptiness before selection"],"tags":["aflow","optimizer","validation","empty-input"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}