Function References

untilFinishReason

Function: untilFinishReason()

ts
function untilFinishReason(stopReasons): AgentLoopStrategy;

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

Creates a strategy that continues until a specific finish reason is encountered

Parameters

stopReasons

string[]

Finish reasons that should stop the loop

Returns

AgentLoopStrategy

AgentLoopStrategy that stops on specific finish reasons

Example

ts
const stream = chat({
  adapter: openaiText(),
  model: "gpt-4o",
  messages: [...],
  tools: [weatherTool],
  agentLoopStrategy: untilFinishReason(["stop", "length"]),
});