Open History to see the last commit
1---
2id: maxIterations
3title: maxIterations
4---
5
6# Function: maxIterations()
7
8```ts
9function maxIterations(max): AgentLoopStrategy;
10```
11
12Defined in: [packages/typescript/ai/src/activities/chat/agent-loop-strategies.ts:20](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/activities/chat/agent-loop-strategies.ts#L20)
13
14Creates a strategy that continues for a maximum number of iterations
15
16## Parameters
17
18### max
19
20`number`
21
22Maximum number of iterations to allow
23
24## Returns
25
26[`AgentLoopStrategy`](../type-aliases/AgentLoopStrategy.md)
27
28AgentLoopStrategy that stops after max iterations
29
30## Example
31
32```typescript
33const stream = chat({
34 adapter: openaiText(),
35 model: "gpt-4o",
36 messages: [...],
37 tools: [weatherTool],
38 agentLoopStrategy: maxIterations(3), // Max 3 iterations
39});
40```