Type Alias References

AgentLoopStrategy

Type Alias: AgentLoopStrategy()

ts
type AgentLoopStrategy = (state) => boolean;
type AgentLoopStrategy = (state) => boolean;

Defined in: packages/ai/src/types.ts:868

Strategy function that determines whether the agent loop should continue

Parameters

state

AgentLoopState

Current state of the agent loop

Returns

boolean

true to continue looping, false to stop

Example

typescript
// Continue for up to 5 iterations (model turns, not tool calls)
const strategy: AgentLoopStrategy = ({ iterationCount }) => iterationCount < 5;
// Cap total tool calls across the run
const byTools: AgentLoopStrategy = ({ toolCallCount }) => toolCallCount < 20;
// Continue for up to 5 iterations (model turns, not tool calls)
const strategy: AgentLoopStrategy = ({ iterationCount }) => iterationCount < 5;
// Cap total tool calls across the run
const byTools: AgentLoopStrategy = ({ toolCallCount }) => toolCallCount < 20;