liveBook · Manning

Stagnation

As explained in AI Agents in Action, Second Edition

Stagnation detection is the identification of repeated iterations whose outputs do not meaningfully change.

An agent can keep producing plausible findings without making progress—like repeating the same search in slightly different words. Stagnation detection identifies iterations whose outputs have not meaningfully changed. Unlike an error check, it catches work that looks successful but adds little value. section 9.2.4

A practical check has three parts:

  • Keep comparable records of successive iterations, such as normalized summaries or findings. section 9.2.4
  • Measure whether they are too similar. One approach compares semantic overlap using embeddings and cosine similarity; a simpler exercise checks word overlap. section 9.2.4 section 9.5
  • Choose a response: stop and return existing findings in a basic loop, or signal the planner to try a different strategy. section 9.2.4 section 10.3.5
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

The Python detector compares words in the last two findings and also checks whether recent confidence scores have barely changed. When it detects high content overlap, it records a stagnation signal in the workspace. section 10.3.5

Test the broken-record case

Give an evaluation module two consecutive identical findings and verify that it flags stagnation. To test a loop’s stopping behavior, compare a run with an overlap check against one governed only by its other termination conditions. section 10.5 section 9.5

Use stagnation detection alongside a hard iteration limit and a cost ceiling, not instead of them. Similarity thresholds are design choices: the examples use different measures and cutoffs. Decide whether repeated findings should end the task or trigger replanning, then test that behavior. section 9.6 section 10.3.5

How AI Agents in Action, Second Edition covers it

How deep it goes
Shows summary comparison, overlap thresholds, and a Python detector that checks findings and confidence trends; it does not specify a universal threshold.
Examples
Tests two identical findings, an 80% word-overlap stopping rule, and a detector that checks recent findings and confidence scores.
What it assumes
Requires successive iteration summaries or recorded findings; checking a confidence plateau additionally requires confidence history.
What you can do after
Build it from scratch by comparing consecutive findings and using the result to stop a loop or request replanning.
How it connects
Links stagnation detection to termination conditions, semantic similarity, confidence trends, attention routing, and replanning.

Also explained in

Compare how 2 books explain stagnation →

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.