Command Palette

Search for a command to run...

Hectal
Phase 8: Tools and Human Approval
AI Frontend · Exercise 4 of 5 PreviousNext
Advanced

Stop the Runaway Loop

The model in this route keeps asking for checkPayment, and the tool always answers pending. Right now the route has no stopWhen, so the loop ends after one step and the user sees no answer.

On the server, allow at most 3 steps with stopWhen: stepCountIs(3). In the page, when the chat is ready, the assistant message has tool parts and no text, show in #stopped the sentence After N lookups I still have no clear answer. where N is the number of tool parts. #count must always say N tool calls so far.

What Check tests

  1. Before the question, #count says 0 tool calls so far and there is no #stopped
  2. After the loop ends, #count says 3 tool calls so far
  3. #stopped explains that there is no answer
  4. The code sets a step limit

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.