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
- Before the question,
#countsays0 tool calls so farand there is no#stopped - After the loop ends,
#countsays3 tool calls so far #stoppedexplains that there is no answer- 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.