FoundationAgents/MetaGPT · error · ValueError
Score list is empty.
Error message
Score list is empty.
What it means
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.
Source
Thrown at metagpt/ext/aflow/scripts/optimizer_utils/data_utils.py:69
sorted_items = sorted(items, key=lambda x: x["score"], reverse=True)
scores = [item["score"] * 100 for item in sorted_items]
probabilities = self._compute_probabilities(scores)
logger.info(f"\nMixed probability distribution: {probabilities}")
logger.info(f"\nSorted rounds: {sorted_items}")
selected_index = np.random.choice(len(sorted_items), p=probabilities)
logger.info(f"\nSelected index: {selected_index}, Selected item: {sorted_items[selected_index]}")
return sorted_items[selected_index]
def _compute_probabilities(self, scores, alpha=0.2, lambda_=0.3):
scores = np.array(scores, dtype=np.float64)
n = len(scores)
if n == 0:
raise ValueError("Score list is empty.")
uniform_prob = np.full(n, 1.0 / n, dtype=np.float64)
max_score = np.max(scores)
shifted_scores = scores - max_score
exp_weights = np.exp(alpha * shifted_scores)
sum_exp_weights = np.sum(exp_weights)
if sum_exp_weights == 0:
raise ValueError("Sum of exponential weights is 0, cannot normalize.")
score_prob = exp_weights / sum_exp_weights
mixed_prob = lambda_ * uniform_prob + (1 - lambda_) * score_prob
total_prob = np.sum(mixed_prob)
if not np.isclose(total_prob, 1.0):
mixed_prob = mixed_prob / total_probView on GitHub (pinned to 11cdf466d0)
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
Example fix
probs = du._compute_probabilities(scores) if scores else None
Defensive patterns
Strategy: validation
Validate before calling
assert scores, "need at least one score" # or: if not scores: return None
Type guard
def is_nonempty_score_list(scores) -> bool:
return isinstance(scores, (list, tuple)) and len(scores) > 0 Prevention
- Prefer select_round over calling _compute_probabilities directly
- Always check len(scores) > 0 before building probability distributions
When it happens
Trigger: 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.
Common situations: Custom code that reuses _compute_probabilities for sampling; refactors of select_round that bypass its empty-list guard.
Related errors
- Item list is empty.
- Unsupported dataset: {dataset}
- Only support for python, markdown, but got {language}
- Only support for language: python, markdown, but got {langua
- The invoice format is not zip, pdf, png, or jpg
AI-assisted analysis of FoundationAgents/MetaGPT@11cdf466d0 (2026-08-14).
Data as JSON: /api/errors/1f7d7e6a333f8d36.
Report an issue: GitHub.