promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_

Evaluator-optimizer — write a draft, let a judge critique it, revise — step 9 of 9

Checkpoint

One last thing before we move on. pass this to mark the lesson done, or skip and keep moving. hop to the next when you're ready.

Final drill. Build a production-grade evaluator-optimizer that tracks the full revision history. Write optimize(task, max_iters) that:

  • Maintains feedback = None and history = [].
  • Loops up to max_iters times. Each iteration:
    • Calls gen(task, feedback=feedback) to produce a draft.
    • Calls judge(draft) to get a verdict dict.
    • Appends one entry to history: {"iter": <1-based>, "draft": <draft>, "status": <verdict status>, "feedback": <verdict feedback>}.
    • On PASS: return {"final_draft": draft, "iters": <iteration that passed>, "passed": True, "history": history}.
    • On REJECT: update feedback = verdict["feedback"] and continue.
  • On cap exhaustion without a PASS: return {"final_draft": <last draft>, "iters": max_iters, "passed": False, "history": history}.

The script will run two cases. Expected output:

passed=True iters=3 history_len=3 final=v3-good
passed=False iters=2 history_len=2 final=stub2

full-screen editor opens — close anytime to keep reading.