Skip to main content

Agent Failure Modes

AI agents fail in ways that traditional software doesn’t. Understanding these failure modes is essential to building resilient production systems. StateBase is designed to help you detect, debug, and recover from each of these patterns.

The 7 Deadly Failures

1. Hallucination Corruption

What happens: The LLM generates plausible-sounding but completely false information, which gets stored in state or memory.
Detection:
Recovery with StateBase:
Prevention:
  • Never trust LLM output for critical data (balances, medical info, legal advice)
  • Always verify with authoritative sources (APIs, databases)
  • Use structured output (JSON schema validation) to catch hallucinations early

2. Context Overflow

What happens: The conversation history grows too large, causing:
  • Increased latency (slow responses)
  • Increased cost (more tokens)
  • Context window limits (truncation)
Detection:
Recovery with StateBase:
Prevention:
  • Set turn limits in get_context() (10-20 is usually enough)
  • Summarize periodically (every 20 turns)
  • Use memory for long-term facts (don’t rely on turn history)

3. State Drift

What happens: The agent’s internal state diverges from reality because external systems changed.
Detection:
Recovery with StateBase:
Prevention:
  • Sync state with external systems before critical operations
  • Use TTLs on cached data (e.g., {"weather": {...}, "cached_until": timestamp})
  • Validate state against source of truth periodically

4. Tool Call Failures

What happens: The agent calls an external API (weather, database, payment processor) and it fails.
Detection:
Recovery with StateBase:
Prevention:
  • Always checkpoint before risky operations
  • Implement retry logic (with exponential backoff)
  • Have fallback responses for common failures

5. Infinite Loops

What happens: The agent gets stuck repeating the same action over and over.
Detection:
Recovery with StateBase:
Prevention:
  • Track action history in state (e.g., {"attempted_actions": ["search", "search"]})
  • Limit retries (max 3 attempts per action)
  • Use circuit breakers (stop trying after repeated failures)

6. Permission Violations

What happens: The agent attempts an action the user isn’t authorized for.
Detection:
Recovery with StateBase:
Prevention:
  • Implement permission checks before every destructive operation
  • Use allowlists (explicitly define what agent CAN do, not what it can’t)
  • Require human confirmation for high-risk actions

7. Memory Pollution

What happens: The agent stores incorrect or irrelevant information in long-term memory.
Detection:
Recovery with StateBase:
Prevention:
  • Confirm before storing preferences (“Just to confirm, you prefer X?”)
  • Use confidence scores (only store high-confidence facts)
  • Allow users to review/edit memories (via dashboard)

Failure Detection Framework

Implement this monitoring system to catch failures early:

Recovery Decision Tree

When a failure is detected, use this decision tree:

Best Practices

✅ Do This

  • Monitor for all 7 failure modes (use the detection framework above)
  • Checkpoint before risky operations (tool calls, state updates)
  • Implement graceful degradation (fallback responses when tools fail)
  • Log everything (you’ll need it for debugging)
  • Test failure scenarios (inject failures in staging)

❌ Avoid This

  • Don’t ignore repeated failures (they indicate systemic issues)
  • Don’t trust LLM output blindly (always validate critical data)
  • Don’t let sessions grow unbounded (summarize or split)
  • Don’t skip permission checks (security > convenience)

Testing Failure Modes

Inject failures in your test environment to verify recovery:

Next Steps


Key Takeaway: AI agents will fail. The question is whether you can detect and recover fast enough. StateBase gives you the tools to turn failures into learning opportunities.