{"record":{"id":"1f7d7e6a333f8d36","repo":"FoundationAgents/MetaGPT","slug":"score-list-is-empty","errorCode":null,"errorMessage":"Score list is empty.","messagePattern":"Score list is empty\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"metagpt/ext/aflow/scripts/optimizer_utils/data_utils.py","lineNumber":69,"sourceCode":"\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:\n            raise ValueError(\"Score list is empty.\")\n\n        uniform_prob = np.full(n, 1.0 / n, dtype=np.float64)\n\n        max_score = np.max(scores)\n        shifted_scores = scores - max_score\n        exp_weights = np.exp(alpha * shifted_scores)\n\n        sum_exp_weights = np.sum(exp_weights)\n        if sum_exp_weights == 0:\n            raise ValueError(\"Sum of exponential weights is 0, cannot normalize.\")\n\n        score_prob = exp_weights / sum_exp_weights\n\n        mixed_prob = lambda_ * uniform_prob + (1 - lambda_) * score_prob\n\n        total_prob = np.sum(mixed_prob)\n        if not np.isclose(total_prob, 1.0):\n            mixed_prob = mixed_prob / total_prob","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/ext/aflow/scripts/optimizer_utils/data_utils.py#L51-L87","documentation":"Raised by DataUtils._compute_probabilities when the `scores` list has length 0. The method builds a mixed uniform + softmax distribution over scores, which is undefined for an empty list. It is normally called from select_round after the empty-items check, so hitting it means _compute_probabilities was called directly (or via a path) with no scores.","triggerScenarios":"Calling _compute_probabilities(scores) with an empty list, e.g. computing probabilities over an empty list of per-round scores or an empty top_scores sample.","commonSituations":"Custom code that reuses _compute_probabilities for sampling; refactors of select_round that bypass its empty-list guard.","solutions":["Pass at least one score: ensure the upstream round/score collection produced data before calling","Guard the call site with `if not scores: ...` and handle the empty case explicitly","Reuse select_round instead of calling _compute_probabilities directly — it already validates inputs"],"exampleFix":"probs = du._compute_probabilities(scores) if scores else None","handlingStrategy":"validation","validationCode":"assert scores, \"need at least one score\"  # or: if not scores: return None","typeGuard":"def is_nonempty_score_list(scores) -> bool:\n    return isinstance(scores, (list, tuple)) and len(scores) > 0","tryCatchPattern":null,"preventionTips":["Prefer select_round over calling _compute_probabilities directly","Always check len(scores) > 0 before building probability distributions"],"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"}