promptdojo_

Wire it all together — a CLI agent in 12 steps — step 10 of 12

Cursor wrote an agent loop without a max-turns guard. The fake LLM in this snippet always returns tool_use (it never produces an end_turn), so the loop would run forever in real life. Convert the while True on line 14 into a bounded loop that stops after exactly 3 turns and prints the turn count.

Expected output:

bailed after 3 turns
The break is on line 14 — but read the whole snippet first.

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