0Pricing
AI Agents · Lesson

Agentic Patterns: Plan-Execute-Verify

First make a plan, then execute step by step, then verify against acceptance criteria — beats one-shot.

Agentic Patterns: Plan-Execute-Verify is a free AI Agents lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AI Agents learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why Plan First?

One-shot code generation works for tiny tasks ("write a fizzbuzz"). For real software changes, the agent should:

  1. Plan — decompose the task into steps
  2. Execute — implement each step
  3. Verify — test, lint, run
  4. Iterate — fix until verified

Step 1: Plan

Ask the model to produce a structured plan:

PLAN_PROMPT = '''
You are a senior engineer. Given this task, produce a JSON plan:
{steps: [{description, files_to_touch: [str], test_commands: [str]}], risks: [str]}

Task: {user_task}
'''

Plan Schema

from pydantic import BaseModel

class Step(BaseModel):
    description: str
    files_to_touch: list[str]
    test_commands: list[str]

class Plan(BaseModel):
    steps: list[Step]
    risks: list[str]

Step 2: Execute

Execute each step in order. Provide the model with file contents as context:

for step in plan.steps:
    context = {f: read_file(f) for f in step.files_to_touch}
    diff = llm.invoke(f'Implement: {step.description}\nFiles:\n{context}').content
    apply_diff(diff)

Step 3: Verify

Run tests / lint / build for each step:

for cmd in step.test_commands:
    result = sandbox.run(cmd)
    if result.exit_code != 0:
        # Verification failed; iterate
        loop_until_verified(step, result.stderr)

Step 4: Iterate Until Pass

MAX_ITERS = 5
for iter in range(MAX_ITERS):
    result = sandbox.run(test_cmd)
    if result.exit_code == 0:
        break
    fix = llm.invoke(f'Tests failed:\n{result.stderr}\nFix the code.').content
    apply_diff(fix)

Show Diffs, Not Full Files

For incremental changes, the model should produce UNIFIED DIFFS:

diff = '''
--- a/main.py
+++ b/main.py
@@ -10,3 +10,4 @@
  def add(a, b):
      return a + b
+
+def sub(a, b): return a - b
'''
import patch
patch.fromstring(diff).apply()

Plan Quality Matters

A bad plan dooms execution. Use a stronger model for planning (GPT-4o, Claude Sonnet 4.5) and a cheaper one for execution (gpt-4o-mini, haiku) if budget tight.

Replan When Stuck

If verification fails repeatedly, abandon the current plan and ask the LLM to RE-PLAN with the new information:

if iter == MAX_ITERS - 1:
    new_plan = llm.invoke(f'Original plan failed. Errors: {errors}. Make a new plan.').content

Long-Horizon Planning Trade-off

The longer the horizon, the worse the model plans. For 10+ step tasks, generate a coarse plan; refine at each step.

Plan + Critic

Have a "critic" agent review the plan before execution. Catches obvious mistakes early — cheaper than fixing during execution.

Surface the Plan to the User

Show the plan to the user before executing. Let them edit:

approved_plan = await ask_user_to_approve_or_edit(plan)
execute(approved_plan)

Plan-Execute-Verify

Why is this pattern more reliable than one-shot code generation?

Recap

Plan, execute, verify, iterate. Use strong planner, cheap executor, run real tests. Surface plans to users when stakes are high.

Frequently asked questions

Is the “Agentic Patterns: Plan-Execute-Verify” lesson free?

Yes — the full text of “Agentic Patterns: Plan-Execute-Verify” is free to read here on the web, and the AI Agents course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AI Agents course, upgrade to CoddyKit PRO.

What will I learn in “Agentic Patterns: Plan-Execute-Verify”?

First make a plan, then execute step by step, then verify against acceptance criteria — beats one-shot. You practise AI Agents with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start AI Agents?

No prior experience is required. AI Agents on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Agentic Patterns: Plan-Execute-Verify” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this AI Agents lesson?

Yes. Every AI Agents lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Agentic Patterns: Plan-Execute-Verify
  2. Tool Surfaces for Coding (Read, Edit, Bash)
  3. Iterative Self-Correction Loops
  4. SWE-Agent and OpenDevin Architectures
← Back to AI Agents