Docs
CodeRabbit
Cloudflare
Railway
Netlify
WorkOS
AG Grid
Clerk
OpenRouter
SerpAPI
Sentry
Unkey
Prisma
Electric
CodeRabbit
Cloudflare
Railway
Netlify
WorkOS
AG Grid
Clerk
OpenRouter
SerpAPI
Sentry
Unkey
Prisma
Electric
Class References
Function References
Interface References
Type Alias References
Variable References
Function References

maxIterations

Function: maxIterations()

ts
function maxIterations(max): AgentLoopStrategy;
function maxIterations(max): AgentLoopStrategy;

Defined in: packages/ai/src/activities/chat/agent-loop-strategies.ts:20

Creates a strategy that continues for a maximum number of iterations

Parameters

max

number

Maximum number of iterations to allow

Returns

AgentLoopStrategy

AgentLoopStrategy that stops after max iterations

Example

typescript
const stream = chat({
  adapter: openaiText(),
  model: "gpt-4o",
  messages: [...],
  tools: [weatherTool],
  agentLoopStrategy: maxIterations(3), // Max 3 iterations
});
const stream = chat({
  adapter: openaiText(),
  model: "gpt-4o",
  messages: [...],
  tools: [weatherTool],
  agentLoopStrategy: maxIterations(3), // Max 3 iterations
});