import { Agent, AgentOutputType } from '../agent'; import { MaxTurnsExceededError } from '../errors'; import { RunItem } from '../items'; import { ModelResponse } from '../model'; import { RunResult, StreamedRunResult } from '../result'; import { RunContext } from '../runContext'; import { RunState } from '../runState'; import type { AgentInputItem, AgentOutputItem, ResolvedAgentOutput } from '../types'; import type { OutputGuardrailDefinition, OutputGuardrailMetadata } from '../guardrail'; /** * Error kinds supported by run error handlers. */ export type RunErrorKind = 'maxTurns'; /** * Snapshot of run data passed to error handlers. */ export type RunErrorData> = { input: string | AgentInputItem[]; newItems: RunItem[]; history: AgentInputItem[]; output: AgentOutputItem[]; rawResponses: ModelResponse[]; lastAgent?: TAgent; state?: RunState; }; export type RunErrorHandlerInput> = { error: MaxTurnsExceededError; context: RunContext; runData: RunErrorData; }; export type RunErrorHandlerResult> = { /** * The final output to return for the run. */ finalOutput: ResolvedAgentOutput; /** * Whether to append the synthesized output to history for subsequent runs. */ includeInHistory?: boolean; }; export type RunErrorHandler> = (input: RunErrorHandlerInput) => RunErrorHandlerResult | void | Promise | void>; export type RunErrorHandlers> = Partial>> & { /** * Fallback handler for supported error kinds. */ default?: RunErrorHandler; }; type TryHandleRunErrorArgs> = { error: unknown; state: RunState; errorHandlers?: RunErrorHandlers; outputGuardrailDefs: OutputGuardrailDefinition>[]; emitAgentEnd: (context: RunContext, agent: TAgent, outputText: string) => void; streamResult?: StreamedRunResult; }; export declare const tryHandleRunError: >({ error, state, errorHandlers, outputGuardrailDefs, emitAgentEnd, streamResult, }: TryHandleRunErrorArgs) => Promise | undefined>; export {};