promptdojo_
Checkpoint

One last thing before we move on. Same surface as a write step — but the lesson doesn't complete until this passes.

Final drill. Build the agent loop with full validation. Write run_validated_agent(question, max_iters) that:

  • Maintains messages = [{"role": "user", "content": question}].
  • Loops up to max_iters times calling fake_create(messages) → a MockMessage with .stop_reason and .content (a list of MockTextBlock and/or MockToolUseBlock).
  • On end_turn: collect text from text blocks, return {"ok": True, "answer": <text joined with " ">, "validation_errors": <count>, "iters": <iter num>}.
  • On tool_use: for each tool_use block, call dispatch_with_validation(block.name, block.input). Track how many results came back as VALIDATION_ERROR: or UNKNOWN_TOOL: — increment a validation_errors counter per such result. Append the assistant turn + a user turn with tool_result blocks (each with the right tool_use_id).
  • On cap: return {"ok": False, "error": "capped", "iters": max_iters}.

Expected output:

ok=True iters=3 validation_errors=1 answer=Found a 2026 ramen guide.

this step needs the editor

on desktop today; in the app (coming soon). save your spot and we'll bring you back here when you're ready.

open this same url on a laptop to keep going today.