Open History to see the last commit
1---
2id: untilFinishReason
3title: untilFinishReason
4---
5
6```ts
7function untilFinishReason(stopReasons): AgentLoopStrategy;
8```
9
10Defined in: [packages/ai/src/activities/chat/agent-loop-strategies.ts:47](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/agent-loop-strategies.ts#L47)
11
12Creates a strategy that continues until a specific finish reason is encountered
13
14## Parameters
15
16### stopReasons
17
18`string`[]
19
20Finish reasons that should stop the loop
21
22## Returns
23
24[`AgentLoopStrategy`](../type-aliases/AgentLoopStrategy.md)
25
26AgentLoopStrategy that stops on specific finish reasons
27
28## Example
29
30```typescript
31const stream = chat({
32 adapter: openaiText(),
33 model: "gpt-4o",
34 messages: [...],
35 tools: [weatherTool],
36 agentLoopStrategy: untilFinishReason(["stop", "length"]),
37});
38```