Prompt Buddy logoPrompt Buddy

vercel · Vercel AI SDK Docs

AI SDK Agents: Loop Control

Teaches how to implement loop control mechanisms for AI agents to prevent infinite loops and manage execution flow during multi-step reasoning processes.

Import to Prompt Buddy

Derived skill

Files assembled from official documentation

Viewing SKILL.md

AI SDK Agents: Loop Control

Teaches how to implement loop control mechanisms for AI agents to prevent infinite loops and manage execution flow during multi-step reasoning processes.

When To Use

Use when you need to implement safeguards, maximum iteration limits, or exit conditions to prevent AI agents from entering infinite loops during autonomous task execution.

Reference Files

FileContainsUse For
SKILL.mdEntry point: scope, routing table, and workflow.Start here.
docs/ai-sdk-agents-loop-control-workflow-guide.mdDocumentation explaining how to manage agent execution flow and stop conditions within the AI SDK agent loop.Questions about documentation explaining how to manage agent execution flow and stop conditions within the AI SDK agent loop.
examples/ai-sdk-agents-loop-control-ai-sdk-tool-loop-agent-step-count-stop-condit.textA TypeScript code example demonstrating how to use ToolLoopAgent with a custom stepCountIs stop condition to control agent execution loops.Exact payloads, commands, or snippets shown in A TypeScript code example demonstrating how to use ToolLoopAgent with a custom stepCountIs stop condition to control...
examples/ai-sdk-agents-loop-control-ai-sdk-tool-loop-agent-typescript.textA TypeScript code example demonstrating how to implement a ToolLoopAgent with a custom stop condition using isLoopFinished.Exact payloads, commands, or snippets shown in A TypeScript code example demonstrating how to implement a ToolLoopAgent with a custom stop condition using isLoopFin...
examples/ai-sdk-agents-loop-control-ai-sdk-tool-loop-agent-stop-conditions-typesc.textA TypeScript code example demonstrating how to use ToolLoopAgent with stopWhen conditions like stepCountIs and hasToolCall.Exact payloads, commands, or snippets shown in A TypeScript code example demonstrating how to use ToolLoopAgent with stopWhen conditions like stepCountIs and hasToo...
examples/ai-sdk-agents-loop-control-ai-sdk-tool-loop-agent-stop-condition.textA TypeScript code example demonstrating how to implement a custom StopCondition using ToolLoopAgent to control agent execution loops.Exact payloads, commands, or snippets shown in A TypeScript code example demonstrating how to implement a custom StopCondition using ToolLoopAgent to control agent...
examples/ai-sdk-agents-loop-control-stop-condition.textA TypeScript implementation of a budget-based stop condition function for AI SDK agents using the steps property.Exact payloads, commands, or snippets shown in A TypeScript implementation of a budget-based stop condition function for AI SDK agents using the steps property.
examples/ai-sdk-agents-loop-control-ai-sdk-tool-loop-agent-prepare-step-model-swi.textA TypeScript example demonstrating how to use the prepareStep function in ToolLoopAgent to switch to a more capable model during complex reasoning steps.Exact payloads, commands, or snippets shown in A TypeScript example demonstrating how to use the prepareStep function in ToolLoopAgent to switch to a more capable m...
examples/ai-sdk-agents-loop-control-ai-sdk-tool-loop-agent-typescript-2.textA TypeScript code example demonstrating how to implement a ToolLoopAgent with message history management for loop control.Exact payloads, commands, or snippets shown in A TypeScript code example demonstrating how to implement a ToolLoopAgent with message history management for loop con...
examples/ai-sdk-agents-loop-control-ai-sdk-tool-loop-agent-prepare-step-logic.textA TypeScript code example demonstrating how to use the prepareStep function in a ToolLoopAgent to control tool selection based on the current step number.Exact payloads, commands, or snippets shown in A TypeScript code example demonstrating how to use the prepareStep function in a ToolLoopAgent to control tool select...
examples/ai-sdk-agents-loop-control-preparestep-logic.textA text representation of the prepareStep function used to control tool selection and execution flow within an AI SDK agent loop.Exact payloads, commands, or snippets shown in A text representation of the prepareStep function used to control tool selection and execution flow within an AI SDK...
examples/ai-sdk-agents-loop-control-ai-sdk-tool-loop-agent-prepare-step-implement.textA TypeScript implementation demonstrating how to use the prepareStep function in a ToolLoopAgent to summarize tool results and manage token usage.Exact payloads, commands, or snippets shown in A TypeScript implementation demonstrating how to use the prepareStep function in a ToolLoopAgent to summarize tool re...
examples/ai-sdk-agents-loop-control-prepare-step-implementation.textA text implementation of the prepareStep function used to manage state and tool call history within an AI SDK agent loop.Exact payloads, commands, or snippets shown in A text implementation of the prepareStep function used to manage state and tool call history within an AI SDK agent l...
examples/ai-sdk-agents-loop-control-ai-sdk-tool-loop-agent-typescript-3.textA TypeScript code example demonstrating how to implement a ToolLoopAgent with custom tools for autonomous task execution.Exact payloads, commands, or snippets shown in A TypeScript code example demonstrating how to implement a ToolLoopAgent with custom tools for autonomous task execut...
examples/ai-sdk-agents-loop-control-typescript-max-steps-implementation.textA TypeScript code implementation demonstrating how to use a while loop and maxSteps to control agent execution cycles in the AI SDK.Exact payloads, commands, or snippets shown in A TypeScript code implementation demonstrating how to use a while loop and maxSteps to control agent execution cycles...

What This Skill Covers

  • You can control both the execution flow and the settings at each step of the agent loop. The loop continues until:
  • Main sections: Stop Conditions, Use Built-in Conditions, Run Up to a Maximum Number of Steps, Run Until Finished, Combine Multiple Conditions.

Workflow

  1. Open the most relevant file under docs/ for the exact documented workflow and wording.
  2. Open schemas/ files for exact structured contracts.
  3. Open examples/ files for concrete requests, commands, snippets, and manifests.
  4. Do not add behavior or configuration that is not present in the attached source files.

Canonical source: https://ai-sdk.dev/docs/agents/loop-control