stop_reason, tool_use, tool_result — the loop every agent runs — step 7 of 9
AI wrote an agent loop that BREAKS on tool_use. That's backwards —
tool_use is the signal to KEEP GOING (run the tool, append the
result, loop again). end_turn is the signal to stop. The fake
model returns one tool_use then one end_turn. The broken loop
bails on the first response and never sees "done".
Fix line 12 so the loop breaks on end_turn, runs the loop body
for the tool_use turn, and prints the final text.
Expected output:
done
AI wrote an agent loop that BREAKS on tool_use. That's backwards —
tool_use is the signal to KEEP GOING (run the tool, append the
result, loop again). end_turn is the signal to stop. The fake
model returns one tool_use then one end_turn. The broken loop
bails on the first response and never sees "done".
Fix line 12 so the loop breaks on end_turn, runs the loop body
for the tool_use turn, and prints the final text.
Expected output:
done
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.