Skip to main content
Lightning Jar - Web Studio Lightning Jar Wordmark

Findings No. 46

A provider-executed tool can end an AI SDK agent loop early

A step that calls only a provider-executed tool returns without handing control back to the AI SDK's multi-step loop, so the agent stops after one step whatever stopWhen says.

Replicator LLM Operations verified Vercel AI SDK with AI Gateway's perplexitySearch tool

In the Vercel AI SDK, a tool the provider executes can finish the whole agent run. If a step calls only provider-executed tools, control never comes back to the client-side multi-step loop for another step.

Replicator's blog writing assistant used gateway.tools.perplexitySearch(), which runs inside the AI Gateway rather than in our code. After researching, the writing assistant was meant to call our own set_article_body tool. It never did; it emitted its research and stopped, and a "please proceed" only made it search again. It looked like a prompting problem, and an earlier round of prompt hardening did not fix it. The step limit was not the cause either: stopWhen: stepCountIs(10) was never reached, because the loop ended at the search step.

The fix was to make the search tool client-executed. Its execute function now runs Perplexity's Sonar model through generateText and returns an answer with sources, so the search happens inside our own tool call and the standard multi-step loop resumes afterwards.

The general rule: if a tool needs the model to take another turn after it runs, make it client-executed. A provider-executed tool can quietly end a multi-step loop early, and no step limit will reveal it.

Receipt: Replicator v3.79.0 (FINDINGS.md, "AI chat and agent surfaces").

Ask Eljay

Ask about the studio's work, research, packages, or writing. A few starters:

Answers come from this site's own content and link their sources. For anything that matters, email hello@lightningjar.com.