Replanning and Plan Repair
What you'll learn: How AI agents detect plan failures during execution and adapt by generating new plans or fixing existing ones.
Why Plans Need Repair
Even well-designed plans can fail. An API might be unavailable, a function might return unexpected data, or the environment might change mid-execution. Unlike rigid scripts, intelligent agents need to detect failures and adapt their approach without starting from scratch every time.
What Is Replanning?
Replanning means generating an entirely new plan when the current one becomes unworkable. Think of it like GPS navigation: if you miss a turn, the system calculates a completely new route rather than stubbornly insisting you follow the original directions.
What Is Plan Repair?
Plan repair is more surgical—modifying specific steps in the existing plan while preserving what's still valid. If you're baking a cake and realize you're out of butter, plan repair means substituting oil for that one step rather than starting the whole recipe over.
Detection Strategies
Agents detect failures through:
- Execution feedback: Tool calls return errors or unexpected outputs
- Validation checks: Comparing outcomes against expected conditions
- Timeout monitoring: Steps taking too long signal problems
Choosing Between Repair and Replanning
- Use repair when the failure is localized (one tool failed, but the overall goal remains achievable)
- Use replanning when fundamental assumptions break (the entire approach won't work)
Implementation Pattern
After each action in the perception-reasoning-action loop, the agent evaluates whether the plan is still viable. If not, it triggers either a repair (adjusting affected steps) or replanning (invoking the original planning mechanism with updated context).
Key Takeaway: Replanning generates new plans from scratch when strategies fail completely, while plan repair surgically fixes individual broken steps—both allow agents to adapt gracefully to execution problems.