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:
- Runs at most
MAX_TURNSiterations. - Calls
fake_llm(messages). - If
stop_reason == "end_turn", prints the text and breaks. - 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
⌘↵ runs the editor.read, then continue.
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:
- Runs at most
MAX_TURNSiterations. - Calls
fake_llm(messages). - If
stop_reason == "end_turn", prints the text and breaks. - 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
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.