UNPKG

@tanstack/ai

Version:

Core TanStack AI library - Open source AI SDK

60 lines (59 loc) 1.76 kB
import { AgentLoopStrategy } from '../../types.js'; /** * Creates a strategy that continues for a maximum number of iterations * * @param max - Maximum number of iterations to allow * @returns AgentLoopStrategy that stops after max iterations * * @example * ```typescript * const stream = chat({ * adapter: openaiText(), * model: "gpt-4o", * messages: [...], * tools: [weatherTool], * agentLoopStrategy: maxIterations(3), // Max 3 iterations * }); * ``` */ export declare function maxIterations(max: number): AgentLoopStrategy; /** * Creates a strategy that continues until a specific finish reason is encountered * * @param stopReasons - Finish reasons that should stop the loop * @returns AgentLoopStrategy that stops on specific finish reasons * * @example * ```typescript * const stream = chat({ * adapter: openaiText(), * model: "gpt-4o", * messages: [...], * tools: [weatherTool], * agentLoopStrategy: untilFinishReason(["stop", "length"]), * }); * ``` */ export declare function untilFinishReason(stopReasons: Array<string>): AgentLoopStrategy; /** * Creates a strategy that combines multiple strategies with AND logic * All strategies must return true to continue * * @param strategies - Array of strategies to combine * @returns AgentLoopStrategy that continues only if all strategies return true * * @example * ```typescript * const stream = chat({ * adapter: openaiText(), * model: "gpt-4o", * messages: [...], * tools: [weatherTool], * agentLoopStrategy: combineStrategies([ * maxIterations(10), * ({ messages }) => messages.length < 100, * ]), * }); * ``` */ export declare function combineStrategies(strategies: Array<AgentLoopStrategy>): AgentLoopStrategy;