@openai/agents-core
Version:
The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows.
159 lines (158 loc) • 5.84 kB
TypeScript
import { Agent, AgentOutputType } from './agent';
import { InputGuardrailResult, OutputGuardrailMetadata, OutputGuardrailResult } from './guardrail';
import { ToolInputGuardrailResult, ToolOutputGuardrailResult } from './toolGuardrail';
import { RunContext } from './runContext';
import { RunState } from './runState';
import { TextOutput } from './types';
import * as protocol from './types/protocol';
/**
* Base class for all errors thrown by the library.
*/
export declare abstract class AgentsError extends Error {
state?: RunState<any, Agent<any, any>>;
constructor(message: string, state?: RunState<any, Agent<any, any>>);
}
/**
* System error thrown when the library encounters an error that is not caused by the user's
* misconfiguration.
*/
export declare class SystemError extends AgentsError {
}
/**
* Error thrown when the maximum number of turns is exceeded.
*/
export declare class MaxTurnsExceededError extends AgentsError {
}
/**
* Error thrown when the model refuses to produce output.
*/
export declare class ModelRefusalError extends AgentsError {
/**
* The refusal text returned by the model.
*/
refusal: string;
constructor(refusal: string, state?: RunState<any, Agent<any, any>>);
}
/**
* Error thrown when a model behavior is unexpected.
*/
export declare class ModelBehaviorError extends AgentsError {
}
/**
* Error thrown when a model call exceeds its configured timeout.
*/
export declare class ModelTimeoutError extends AgentsError {
readonly code: "ETIMEDOUT";
readonly timeoutMs: number;
/**
* The provider or transport error observed after the timeout signal was sent, if any.
*/
readonly cause?: unknown;
constructor({ timeoutMs, cause }: {
timeoutMs: number;
cause?: unknown;
});
}
/**
* Context from tool invocation that failed validation.
*/
export type ToolInvocationErrorContext = {
/** The run context at the time of the error. */
runContext?: RunContext<any>;
/** The invalid tool input produced by the model. */
input?: string;
/** The details of the tool call made by the model. */
details?: {
toolCall?: protocol.FunctionCallItem;
resumeState?: string;
signal?: AbortSignal;
};
};
/**
* Error thrown when a model produces invalid tool input.
*/
export declare class InvalidToolInputError extends ModelBehaviorError {
/** The original error thrown during validation, if any. */
originalError?: unknown;
/** Context from the tool invocation that failed. */
toolInvocation?: ToolInvocationErrorContext;
constructor(message: string, state?: RunState<any, Agent<any, any>>, originalError?: unknown, toolInvocation?: ToolInvocationErrorContext);
}
/**
* Error thrown when the error is caused by the library user's misconfiguration.
*/
export declare class UserError extends AgentsError {
}
/**
* Context from a function tool output that failed runtime validation.
*/
export type ToolOutputErrorContext = {
/** The run context at the time of the error. */
runContext?: RunContext<any>;
/** The invalid value returned by the tool or one of its fallback paths. */
output?: unknown;
/** The details of the tool call made by the model. */
details?: ToolInvocationErrorContext['details'];
};
/**
* Error thrown when a function tool returns a value that does not match its
* runtime output schema.
*/
export declare class InvalidToolOutputError extends UserError {
/** The original error thrown during validation, if any. */
originalError?: unknown;
/** Context from the tool output that failed validation. */
toolOutput?: ToolOutputErrorContext;
constructor(message: string, state?: RunState<any, Agent<any, any>>, originalError?: unknown, toolOutput?: ToolOutputErrorContext);
}
/**
* Error thrown when a guardrail execution fails.
*/
export declare class GuardrailExecutionError extends AgentsError {
error: Error;
constructor(message: string, error: Error, state?: RunState<any, Agent<any, any>>);
}
export declare class ToolCallError extends AgentsError {
error: Error;
constructor(message: string, error: Error, state?: RunState<any, Agent<any, any>>);
}
/**
* Error thrown when a function tool invocation exceeds its timeout.
*/
export declare class ToolTimeoutError extends AgentsError {
toolName: string;
timeoutMs: number;
constructor({ toolName, timeoutMs, state, }: {
toolName: string;
timeoutMs: number;
state?: RunState<any, Agent<any, any>>;
});
}
/**
* Error thrown when an input guardrail tripwire is triggered.
*/
export declare class InputGuardrailTripwireTriggered extends AgentsError {
result: InputGuardrailResult;
constructor(message: string, result: InputGuardrailResult, state?: RunState<any, any>);
}
/**
* Error thrown when an output guardrail tripwire is triggered.
*/
export declare class OutputGuardrailTripwireTriggered<TMeta extends OutputGuardrailMetadata, TOutputType extends AgentOutputType = TextOutput> extends AgentsError {
result: OutputGuardrailResult<TMeta, TOutputType>;
constructor(message: string, result: OutputGuardrailResult<TMeta, TOutputType>, state?: RunState<any, any>);
}
/**
* Error thrown when a tool input guardrail tripwire is triggered.
*/
export declare class ToolInputGuardrailTripwireTriggered extends AgentsError {
result: ToolInputGuardrailResult;
constructor(message: string, result: ToolInputGuardrailResult, state?: RunState<any, any>);
}
/**
* Error thrown when a tool output guardrail tripwire is triggered.
*/
export declare class ToolOutputGuardrailTripwireTriggered extends AgentsError {
result: ToolOutputGuardrailResult;
constructor(message: string, result: ToolOutputGuardrailResult, state?: RunState<any, any>);
}