Plans meet reality. A step fails because a tool is down, a page does not load or an API refuses the request, and a robust agent does not start over or give up. It replans: keep everything already done, replace the failed step's tool with a fallback, and continue with the rest. The remaining steps that depended on completed work no longer need those dependencies, because the results already exist. Implementing this as a pure function on plan data makes the recovery logic testable without running any tools.
Implement replan.
plan is a list of step dicts with keys id, tool and depends_on. completed is a set of finished step ids, failed_id is the id of the step that failed and fallbacks maps a tool name to its fallback tool name.completed. The failed step's tool is replaced by fallbacks[tool]; if it has no fallback, raise ValueError.depends_on every id in completed. Other fields are kept unchanged.failed_id must not be in completed. Do not modify the input plan.Copy each remaining step (dict(step)) before changing it, and build a new depends_on list.
Only the failed step changes its tool; later steps keep theirs.
No results yet
Run your code to check it against the examples, or submit to run every test.