0PricingLogin
AI Agents · Lesson

Common Agent Loop Failures

Infinite loops, repeating the same tool call, and never reaching a final answer.

The Agent Loop and Its Failure Modes

An agent loop runs repeatedly: reason → call tool → observe result → reason again. This loop is powerful but fragile. Several well-known failure modes can trap an agent, waste tokens, and produce no useful output.

Understanding these failures is the first step to defending against them.

Failure 1: Infinite Loops

An infinite loop occurs when the agent calls the same tool repeatedly with the same arguments without making progress. This can happen when the tool returns an unhelpful result and the agent cannot reason its way out.

# Example of an agent in an infinite loop:
# Step 1: reasoning='Need to search for Python docs'
#         tool='search_web', args={'query': 'Python documentation'}
# Step 2: reasoning='Search result was unhelpful, try again'
#         tool='search_web', args={'query': 'Python documentation'}
# Step 3: reasoning='Search result was unhelpful, try again'
#         tool='search_web', args={'query': 'Python documentation'}
# ... repeats until max_iterations or token budget is exhausted

print('Symptom: same tool + same arguments appearing repeatedly in steps')
print('Fix: detect repeated (tool, args) pairs and break the loop')

All lessons in this course

  1. Common Agent Loop Failures
  2. Trace Logging for Agent Steps
  3. Detecting and Breaking Infinite Loops
  4. Step-Through Debugging Techniques
← Back to AI Agents