Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Heuristic:666ghj BettaFish Iteration Cap Management

From Leeroopedia
Knowledge Sources
Domains Optimization, LLMs
Last Updated 2026-10-08 21:30 GMT

Overview

Cap LLM reflection iterations to control cost and latency — default 3 rounds for InsightEngine, 2 rounds for Media/Query engines.

Description

The reflection loop in BettaFish's search agents runs multiple rounds of search-query-refinement, where each round generates new queries based on previous results. Without a cap, the loop could run indefinitely, accumulating LLM API costs and latency. Each engine has a configurable `MAX_REFLECTIONS` setting: InsightEngine defaults to 3, MediaEngine to 2, and QueryEngine to 2. The agent checks the reflection count before each iteration and stops when the cap is reached.

Usage

Use this heuristic when designing iterative LLM search or refinement loops to prevent unbounded API costs and latency. Apply when the optimal number of iterations is not known in advance but diminishing returns are expected after a few rounds.

The Insight (Rule of Thumb)

  • Action: Set `MAX_REFLECTIONS` per engine based on task complexity and budget.
  • Value: InsightEngine: 3, MediaEngine: 2, QueryEngine: 2. Range: 1-5 for most use cases.
  • Trade-off: Fewer reflections = lower cost but potentially less comprehensive coverage. More reflections = better coverage but higher cost and latency.
  • Compatibility: Works with any iterative LLM pipeline. The cap is checked before each reflection round.

Reasoning

Empirically, reflection loops show diminishing returns after 2-3 rounds. Most search queries converge on relevant results within 2-3 iterations, and additional rounds tend to rephrase existing queries rather than discover new information. The InsightEngine uses 3 reflections because database mining benefits from broader exploration; Media/Query engines use 2 because web search results are more immediately relevant. Each reflection round costs one LLM call plus one search round, so the cap directly controls cost.

Code Evidence

InsightEngine config from `InsightEngine/utils/config.py:25`:

MAX_REFLECTIONS: int = Field(3, description="最大反思次数")

Global config from `config.py:101`:

MAX_REFLECTIONS: int = Field(3, description="最大反思次数")

MediaEngine config from `MediaEngine/utils/config.py:44`:

MAX_REFLECTIONS: int = Field(2, description="最大反思轮数")

QueryEngine config from `QueryEngine/utils/config.py:40`:

MAX_REFLECTIONS: int = Field(2, description="最大反思轮数")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment