Building an Android AI Agent, Part 11: Mid-Task Replanning Without Starting Over A developer building an Android AI agent added mid-task replanning that preserves completed steps instead of regenerating the full plan from scratch. The approach sends the LLM the completed steps, the failed step with its failure reason, a capped screen snapshot summary, and a target count for remaining steps, then merges the revised steps onto the existing task. The engineer argues that naive full regeneration risks replaying finished actions and causing duplicate side effects, while also discarding the live screen context that makes replanning useful. In Part 10 we added an obstruction detector that handles spinners, dismissible overlays, and permission dialogs inline. When none of those apply and the expected screen simply isn't there, the executor returns a FAILED step with a reason. That's where this part picks up. The task hasn't failed — two of four steps completed successfully. What failed is the plan for step three. The agent needs a new plan for the remaining steps, built on top of what already happened. The naive recovery is to send the original instruction back to the LLM and regenerate the full step list. This has two problems. First, it replays completed steps. If step one opened the right app and step two filled in a form, regenerating from scratch may produce a plan that tries to do both again — which either fails the form is already filled or causes a side effect it submits twice . Second, it throws away context. The LLM that generated the original plan didn't know what the screen looks like right now. The replanning call does — and that's the only reason to make it. The right call: send the completed steps, the failed step, the failure reason, and the current screen snapshot. Ask for a revised plan for the remaining steps only. data class ReplanRequest val originalInstruction: String, val completedSteps: List