agent loops — tool_use and the request/tool/respond cycle7 / 9
stop_reason, tool_use, tool_result — the loop every agent runs
AI wrote an agent loop that checks stop_reason == "tool_use" to
CONTINUE, but never checks for end_turn to STOP. Without an iteration
cap, this would run forever in real life — here, the fake model returns
end_turn after one round, and the loop spins past it because the
break condition is wrong. Fix line 13 so the loop exits on end_turn.
Expected output:
done
The break is on line 13 — but read the whole snippet first.
⌘↵ runs the editor.
Booting Python…
Output
[promptdojo:~]$ _