import type { ToolSet, TypedToolCall } from 'ai';
import type { AgentLayerToolOutput } from './messages';
/**
 * The result of a single tool execution within a step.
 */
export interface StepToolResult {
    toolCallId: string;
    toolName: string;
    output: AgentLayerToolOutput;
    isError: boolean;
}
/**
 * A Step represents one iteration of the agent loop — one model call plus all
 * tool executions that resulted from it.
 *
 * Before execution, `toolResults` is empty. After execution, it contains one
 * entry per tool call with the output and error status.
 */
export interface Step {
    /** The tool calls the model generated during this step. */
    toolCalls: Array<TypedToolCall<ToolSet>>;
    /** The results of executing each tool call. Empty before execution. */
    toolResults: StepToolResult[];
}
/**
 * When a stop condition should be evaluated in the agent loop.
 *
 * - `'beforeExecution'` — after the model generates tool calls, before they run.
 *   Useful for approval gates where you want to inspect intent without side effects.
 * - `'afterExecution'` — after tool calls have been executed and results recorded.
 *   This is the default for most conditions.
 */
export type StopTiming = 'beforeExecution' | 'afterExecution';
/**
 * A stop condition is an object that describes when and why the agent should stop.
 *
 * - `name` — identifies the condition (e.g. "maxSteps", "toolCalled:deploy")
 * - `check` — the predicate; receives the step history and returns true to stop
 * - `timing` — when to evaluate: before or after tool execution. Defaults to 'afterExecution'
 * - `message` — optional human-readable explanation shown when triggered (e.g. "Maximum steps (50) reached")
 * - `onTriggered` — optional callback fired when this condition triggers the stop
 */
export interface StopConditionDef {
    name: string;
    check: (steps: Step[]) => boolean;
    timing?: StopTiming;
    message?: string;
    onTriggered?: () => void;
}
/** Accepts a single stop condition, or an array where any triggering will stop the loop. */
export type StopWhen = StopConditionDef | StopConditionDef[];
/**
 * Returned by `shouldStop` when a condition fires, so the caller knows which one.
 */
export interface StopResult {
    /** The name of the condition that triggered the stop. */
    name: string;
    /** The human-readable message, if the condition provided one. */
    message?: string;
}
/**
 * Stop after at most `n` completed steps.
 *
 * Evaluated after execution (default timing).
 */
export declare function maxSteps(n: number): StopConditionDef;
/**
 * Stop when a tool with the given name is called by the model, **before** the
 * tool is executed. Useful for approval gates — the tool call is visible in
 * the output messages but no side effects have occurred.
 *
 * @param toolName - The name of the tool to watch for.
 */
export declare function toolCalled(toolName: string): StopConditionDef;
/**
 * Stop when a tool with the given name has been called **and** executed
 * successfully (non-error result) in the most recent step.
 *
 * @param toolName - The name of the tool to watch for.
 */
export declare function toolCompleted(toolName: string): StopConditionDef;
/**
 * Stop when total (cumulative) tool execution failures reach `threshold`.
 * Failures do not need to be consecutive — they are counted across all steps.
 *
 * @param threshold - Number of total failures that triggers the stop.
 * @param toolName - Optional tool name to filter. When omitted, counts failures across all tools.
 */
export declare function totalToolFailures(threshold: number, toolName?: string): StopConditionDef;
/**
 * Stop when `threshold` tool failures occur in a row (consecutive steps).
 * A successful tool execution resets the streak.
 *
 * @param threshold - Number of consecutive failures that triggers the stop.
 * @param toolName - Optional tool name to filter. When omitted, counts consecutive failures across all tools.
 */
export declare function consecutiveToolFailures(threshold: number, toolName?: string): StopConditionDef;
/**
 * Stop when the same tool is called with identical input `threshold` consecutive
 * times. Detects agents stuck in a retry loop.
 *
 * @param threshold - Number of identical consecutive calls before stopping. Defaults to 3.
 */
export declare function doomLoop(threshold?: number): StopConditionDef;
/**
 * Stop when the `structured_output` tool is called, **before** execution.
 *
 * This is a convenience wrapper around `toolCalled('structured_output')` for use
 * with the StructuredOutput tool. The agent loop stops immediately when the model
 * calls `structured_output`, and the structured data can be extracted from the
 * pending tool call in the run result.
 *
 * @example
 * ```ts
 * const agent = new Agent({
 *   tools: { structured_output: createStructuredOutputTool(mySchema) },
 *   stopWhen: structuredOutputCalled(),
 * })
 * ```
 */
export declare function structuredOutputCalled(): StopConditionDef;
/**
 * Evaluate stop conditions against the current steps, filtered by timing phase.
 * Returns the `StopResult` of the first triggered condition, or `null` if none fired.
 *
 * @param stopWhen - The stop condition(s) to evaluate.
 * @param steps - The completed steps so far.
 * @param timing - Which phase we're in. Conditions without a `timing` property default to `'afterExecution'`.
 */
export declare function shouldStop(stopWhen: StopWhen, steps: Step[], timing?: StopTiming): StopResult | null;
//# sourceMappingURL=stop-conditions.d.ts.map