promptdojo_

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

Build the full agent loop. The starter has:

  • fake_llm(messages) — returns hardcoded responses based on history length (1 message → tool_use, 3 messages → end_turn).
  • run_tool(name, args) — handles tool dispatch.
  • MAX_TURNS = 5 — the loop guardrail.
  • messages = [...] — initial user prompt.

Write the agent loop that:

  1. Runs at most MAX_TURNS iterations.
  2. Calls fake_llm(messages).
  3. If stop_reason == "end_turn", prints the text and breaks.
  4. If stop_reason == "tool_use", runs the tool, then appends two messages — the assistant's tool_use, and a user message wrapping the tool_result.

Expected output:

done. todos: write tests

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