Course contentsShow
← Machine Learning and Deep Learning
Lesson 1903 of 3,53840. Advanced Prompting TechniquesFree lesson

Error Recovery and Replanning

Handling failed actions and using reasoning to adjust plans based on unexpected observations.

Error Recovery and Replanning

What You'll Learn

You'll learn how ReAct agents handle failed actions and dynamically adjust their reasoning and plans when observations don't match expectations.

The Core Problem

Even well-designed agents encounter failures: APIs return errors, tools produce unexpected outputs, or reasoning steps lead to dead ends. Without recovery mechanisms, a single failure terminates the entire task. Error recovery and replanning enables agents to detect failures, diagnose what went wrong, and generate alternative strategies.

How It Works

When a ReAct agent receives an observation that signals failure (error messages, "None" results, contradictory information), it must:

  1. Recognize the failure: Detect that the current action didn't achieve the intended goal
  2. Diagnose the cause: Reason about why it failed (invalid input, wrong tool, flawed assumption)
  3. Replan: Generate an alternative reasoning path and action sequence
  4. Execute the new plan: Try a different approach

The Reasoning Loop

Instead of rigid sequential execution, the agent maintains a flexible reasoning loop:

Thought: Try searching for "GPT-4 release date"
Action: search["GPT-4 release date"]
Observation: Error: API rate limit exceeded

Thought: The search failed due to rate limiting. I'll wait and try a different tool.
Action: wikipedia["GPT-4"]
Observation: GPT-4 is a large language model released in March 2023...

Analogy: GPS Navigation

Think of a GPS that encounters a road closure. It doesn't freeze—it recalculates a new route using the updated information. Similarly, ReAct agents use observations as feedback to adjust their trajectory toward the goal.

Key Strategies

  • Explicit error detection in thought steps
  • Alternative tool selection when one fails
  • Input reformulation if the format was wrong
  • Backtracking to earlier reasoning states
  • Maximum retry limits to prevent infinite loops

Key Takeaway: Error recovery transforms brittle sequential agents into robust problem-solvers by treating failures as informative observations that trigger replanning rather than termination.