FoundationAgents/MetaGPT · error · ValueError

Item list is empty.

Error message

Item list is empty.

What it means

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.

Source

Thrown at metagpt/ext/aflow/scripts/optimizer_utils/data_utils.py:50

        first_round = next((item for item in self.top_scores if item["round"] == 1), None)
        if first_round:
            unique_top_scores.append(first_round)
            unique_rounds.add(1)

        for item in self.top_scores:
            if item["round"] not in unique_rounds:
                unique_top_scores.append(item)
                unique_rounds.add(item["round"])

                if len(unique_top_scores) >= sample:
                    break

        return unique_top_scores

    def select_round(self, items):
        if not items:
            raise ValueError("Item list is empty.")

        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:

View on GitHub (pinned to 11cdf466d0)

Solutions

  1. Check that prior optimization rounds have been scored and persisted before selecting a round to reuse
  2. Verify the experience/results directory passed to DataUtils actually contains scored entries
  3. Guard the caller: skip selection (e.g. fall back to the default graph) when the filtered item list is empty

Example fix

// before
round = data_utils.select_round(items)

// after
if not items:
    round = None  # or use default graph / run a fresh round
else:
    round = data_utils.select_round(items)
Defensive patterns

Strategy: validation

Validate before calling

if not items:
    raise/return early before calling select_round

Type guard

def has_selectable_rounds(items: list[dict]) -> bool:
    return isinstance(items, list) and len(items) > 0 and all("score" in i and "round" in i for i in items)

Try / catch

try:
    round_ = du.select_round(items)
except ValueError as e:
    logger.warning(f"no rounds to select: {e}")
    round_ = None

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of FoundationAgents/MetaGPT@11cdf466d0 (2026-08-14). Data as JSON: /api/errors/140b617f1ab8aa92. Report an issue: GitHub.