Phase 19: Capstone Projects

Plan-Execute Control Flow

A plan that cannot survive a failure is a script. A script that can replan is an agent. Build the replanner first. Represent a plan as an ordered list of typed steps so the executor can reason about progress and outcome. Execute steps sequentially with a controlled failure handoff back to the planner. Replan from the current cursor with the prior error in the context so the next plan is informed. Emit a plan diff on each revision so a downstream tracer or UI can show why the plan changed. Enforce two budgets: a hard step ceiling and a hard replan ceiling. A chain-of-thought agent emits tokens and lets the loop guess where the tool call ends. A plan-and-execute agent emits a structured plan first, then executes each step deterministically. The plan is data the harness can introspect. The execution is the harness running that data through a dispatcher. Two pieces. A planner that produces a plan. An executor that runs the plan. The interesting work is what happens when the executor hits a failure. Three options: Replan is the one that turns a script into an agent. expectedoutcome is a short sentence the planner emits alongside the step. It is not enforced by the executor. It is for two things: the replanner reads it when revising the plan; the…

Plan-Execute Control Flow: A plan that cannot survive a failure is a script. A script that can replan is an agent. Build the replanner first.

This free lesson is part of the AI Engineering from Scratch curriculum. Read the full explanation, run the lesson code, and verify the result in the interactive reader or from the repository source.

Browse the complete course catalog or open this lesson on GitHub.