-
|
Hi everyone 👋 I’m building an agent with AI SDK v5 that has access to tools (like webSearch). My goal: let the agent run in a truly agentic way — it could make 0, 1, 2, or many tool calls, depending on what’s needed. Basically, I don’t want to hard-set the number of steps, I just want it to run until it decides it’s done. Questions: What’s the right way to do this in AI SDK v5? Specifically, with stepCountIs(n) And if I want open-ended behavior (agent free to stop whenever), should I just avoid stepCountIs and loop manually? Or is there a built-in pattern for “run until done but cap at max N to avoid infinite loops”? Thanks 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
|
You can provide a finished tool that the agent can call to let you know is done, and use stopWhen: hasToolCall('finish') https://ai-sdk.dev/docs/reference/ai-sdk-core/stream-text#stop-when |
Beta Was this translation helpful? Give feedback.
-
|
The agentic loop stops in 4 cases:
|
Beta Was this translation helpful? Give feedback.
-
|
Thanks a lot for the explaination! |
Beta Was this translation helpful? Give feedback.
-
|
This discussion was automatically locked because it has not been updated in over 30 days. If you still have questions about this topic, please ask us at community.vercel.com/ai-sdk |
Beta Was this translation helpful? Give feedback.
You can provide a finished tool that the agent can call to let you know is done, and use stopWhen: hasToolCall('finish')
https://ai-sdk.dev/docs/reference/ai-sdk-core/stream-text#stop-when