Public declaration syntax from forge-ts/packages/forge-agent/src/loop-control.ts Original source SHA-256: 0c956a76d40aa30e8ff6a533c84527ce3e0d5e88a03667444c14f20d69cc7d95 Function bodies and constant values are omitted. This is not the complete implementation. Source line 20 export const AgentStopReason /* type inferred in source */; Source line 32 export type AgentStopReason = (typeof AgentStopReason)[keyof typeof AgentStopReason]; Source line 48 export interface AgentStopCondition { /** A human-readable name for this stop condition. */ readonly name: string; /** * Evaluates the stop condition against the current loop context. * * @param context - The current loop iteration context. * @returns `true` if the loop should stop. */ check(context: LoopContext): boolean; } Source line 64 export interface LoopContext { /** The current iteration number (0-indexed). */ readonly iteration: number; /** The cumulative token usage across all iterations. */ readonly totalUsage: Usage; /** The finish reason from the last model call. */ readonly lastFinishReason: FinishReason; /** The number of tool calls in the last iteration. */ readonly lastToolCallCount: number; } Source line 86 export function maxIterations(max: number): AgentStopCondition; Source line 104 export function maxTotalTokens(max: number): AgentStopCondition; Source line 124 export function modelStopsNaturally(): AgentStopCondition; Source line 143 export function customStop( name: string, predicate: (context: LoopContext) => boolean ): AgentStopCondition; Source line 160 export function evaluateStopConditions( context: LoopContext, conditions: readonly AgentStopCondition[] ): { reason: AgentStopReason; conditionName: string } | undefined;