Open History to see the last commit
1---
2id: maxIterations
3title: maxIterations
4---
5
6```ts
7function maxIterations(max): AgentLoopStrategy;
8```
9
10Defined in: packages/ai/src/activities/chat/agent-loop-strategies.ts:26
11
12Creates a strategy that continues for a maximum number of **model turns**
13(iterations), not tool calls.
14
15One iteration can still emit many parallel tool calls. For a tool-call
16budget, use middleware with `onBeforeToolCall` (per-turn cap) and
17`onShouldContinue` (cumulative run budget) — see the docs recipe under
18Agentic Cycle.
19
20## Parameters
21
22### max
23
24`number`
25
26Maximum number of model turns to allow
27
28## Returns
29
30[`AgentLoopStrategy`](../type-aliases/AgentLoopStrategy.md)
31
32AgentLoopStrategy that stops after max iterations
33
34## Example
35
36```typescript
37const stream = chat({
38 adapter: openaiText("gpt-6.1-sol"),
39 threadId: "thread-1",
40 messages: [...],
41 tools: [weatherTool],
42 agentLoopStrategy: maxIterations(3), // Max 3 model turns
43});
44```