Open History to see the last commit
1---
2id: AgentLoopState
3title: AgentLoopState
4---
5
6Defined in: [packages/ai/src/types.ts:1207](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1207)
7
8State passed to agent loop strategy for determining whether to continue
9
10## Properties
11
12### finishReason
13
14```ts
15finishReason: string | null;
16```
17
18Defined in: [packages/ai/src/types.ts:1213](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1213)
19
20Finish reason from the last response
21
22***
23
24### iterationCount
25
26```ts
27iterationCount: number;
28```
29
30Defined in: [packages/ai/src/types.ts:1209](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1209)
31
32Current iteration count (0-indexed). One iteration = one model turn.
33
34***
35
36### lastTurnToolCallCount
37
38```ts
39lastTurnToolCallCount: number;
40```
41
42Defined in: [packages/ai/src/types.ts:1225](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1225)
43
44Tool calls in the most recent batch — a live model turn or a
45pending/resume batch (0 when the last phase produced no tool calls).
46
47***
48
49### messages
50
51```ts
52messages: ModelMessage<
53 | string
54 | ContentPart<unknown, unknown, unknown, unknown, unknown>[]
55 | null>[];
56```
57
58Defined in: [packages/ai/src/types.ts:1211](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1211)
59
60Current messages array
61
62***
63
64### toolCallCount
65
66```ts
67toolCallCount: number;
68```
69
70Defined in: [packages/ai/src/types.ts:1220](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1220)
71
72Cumulative tool calls counted so far in this run (model-emitted during the
73agent loop, including ones skipped by middleware, and pending tools from
74the inbound message list when resumed). Not a recount of full message
75history; not model turns.