liveBook · Manning

Iteration limit

As explained in AI Agents in Action, Second Edition

A fixed maximum number of iterations that an iterative agent process may execute.

An iteration limit sets the maximum number of cycles an agentic loop may execute. It is the loop’s nonnegotiable safety net: even if no other exit condition succeeds, the process stops at this ceiling. section 9.2.4 section 9.6

Treat it as one layer of a termination gate, not as a replacement for recognizing success or failure. A goal may be satisfied early, while stagnation or budget exhaustion may require earlier termination. section 9.2.4

Build the stopping policy around complementary controls:

  • Use the iteration limit as the defensive ceiling. section 9.2.4
  • Add a budget limit to control token or monetary cost. section 9.2.4
  • Allow goal satisfaction and quality thresholds to end successful work early. section 9.2.4
  • Detect stagnation when successive iterations repeat findings or stop improving confidence. section 9.2.4 section 10.3.5

A bounded research loop

A research agent can search, read, synthesize, and generate follow-up questions across several cycles, but the iteration limit guarantees that the loop eventually stops. A separate synthesis step can then compile the accumulated findings. section 9.6

Listing 10.10 11_stagnation_detector.py
def detect_stagnation(workspace: CognitiveWorkspace) -> bool:
    # Need at least 2 findings to compare
    if len(workspace.findings) < 2:
        return False

    # Check content overlap between last two findings
    last = workspace.findings[-1].content.lower().split()
    prev = workspace.findings[-2].content.lower().split()
    overlap = len(set(last) & set(prev)) / max(len(set(last)), 1)
    if overlap > 0.7:                                #1
        workspace.active_signal = AttentionSignal.STAGNATION
        workspace.signal_source = "content_overlap"
        return True

    # Check confidence plateau
    if len(workspace.confidence_trend) >= 3:
        recent = workspace.confidence_trend[-3:]
        spread = max(recent) - min(recent)
        if spread < 0.05:                            #2
            workspace.active_signal = AttentionSignal.STAGNATION
            workspace.signal_source = "confidence_plateau"
            return True

    return False

Inspect the stagnation detector to see how progress checks can prevent an agent from merely running until its iteration ceiling. section 10.3.5

How AI Agents in Action, Second Edition covers it

How deep it goes
Defines the safety role and surrounding termination layers but does not specify a universal iteration value or selection formula.
Examples
Uses deep research loops and stagnation checks based on repeated findings or flat confidence as concrete operational examples.
What it assumes
Assumes an understanding of agentic loops, iterations, goals, and termination conditions.
What you can do after
Operate/configure agentic loops with a hard ceiling and complementary cost, success, quality, and progress-based exit checks.
How it connects
Connects termination conditions with budget limits, goal satisfaction, quality thresholds, stagnation detection, and adaptive iteration budgets.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI Agents in Action, Second Edition. The section links point to the parts of the book it draws on.