import { Agent } from '../agent'; import { TResponseInputItem } from '../items'; import { RunContextWrapper } from '../run-context'; /** * Represents a value that might be a Promise or a direct value */ export type MaybeAwaitable = T | Promise; interface GuardrailFunctionOutputArgs { output_info: any; tripwire_triggered: boolean; } /** * The output of a guardrail function. */ export declare class GuardrailFunctionOutput { /** * Optional information about the guardrail's output. For example, the guardrail could include * information about the checks it performed and granular results. */ output_info: any; /** * Whether the tripwire was triggered. If triggered, the agent's execution will be halted. */ tripwire_triggered: boolean; constructor({ output_info, tripwire_triggered }: GuardrailFunctionOutputArgs); } /** * The result of an input guardrail run. */ export declare class InputGuardrailResult { /** * The guardrail that was run. */ guardrail: InputGuardrail; /** * The output of the guardrail function. */ output: GuardrailFunctionOutput; constructor(guardrail: InputGuardrail, output: GuardrailFunctionOutput); } /** * The result of an output guardrail run. */ export declare class OutputGuardrailResult { /** * The guardrail that was run. */ guardrail: OutputGuardrail; /** * The output of the agent that was checked by the guardrail. */ agent_output: any; /** * The agent that was checked by the guardrail. */ agent: Agent; /** * The output of the guardrail function. */ output: GuardrailFunctionOutput; constructor(guardrail: OutputGuardrail, agent_output: any, agent: Agent, output: GuardrailFunctionOutput); } /** * Input guardrails are checks that run in parallel to the agent's execution. * They can be used to do things like: * - Check if input messages are off-topic * - Take over control of the agent's execution if an unexpected input is detected * * You can use the `input_guardrail()` decorator to turn a function into an `InputGuardrail`, or * create an `InputGuardrail` manually. * * Guardrails return a `GuardrailResult`. If `result.tripwire_triggered` is `True`, the agent * execution will immediately stop and a `InputGuardrailTripwireTriggered` exception will be raised */ export declare class InputGuardrail { /** * A function that receives the agent input and the context, and returns a * `GuardrailResult`. The result marks whether the tripwire was triggered, and can optionally * include information about the guardrail's output. */ guardrail_function: (context: RunContextWrapper, agent: Agent, input: string | TResponseInputItem[]) => MaybeAwaitable; /** * The name of the guardrail, used for tracing. If not provided, we'll use the guardrail * function's name. */ name: string | null; constructor(guardrail_function: (context: RunContextWrapper, agent: Agent, input: string | TResponseInputItem[]) => MaybeAwaitable, name?: string | null); get_name(): string; run(agent: Agent, input: string | TResponseInputItem[], context: RunContextWrapper): Promise; } /** * Output guardrails are checks that run on the final output of an agent. * They can be used to do check if the output passes certain validation criteria * * You can use the `output_guardrail()` decorator to turn a function into an `OutputGuardrail`, * or create an `OutputGuardrail` manually. * * Guardrails return a `GuardrailResult`. If `result.tripwire_triggered` is `True`, a * `OutputGuardrailTripwireTriggered` exception will be raised. */ export declare class OutputGuardrail { /** * A function that receives the final agent, its output, and the context, and returns a * `GuardrailResult`. The result marks whether the tripwire was triggered, and can optionally * include information about the guardrail's output. */ guardrail_function: (context: RunContextWrapper, agent: Agent, agent_output: any) => MaybeAwaitable; /** * The name of the guardrail, used for tracing. If not provided, we'll use the guardrail * function's name. */ name: string | null; constructor(guardrail_function: (context: RunContextWrapper, agent: Agent, agent_output: any) => MaybeAwaitable, name?: string | null); get_name(): string; run(context: RunContextWrapper, agent: Agent, agent_output: any): Promise; } type InputGuardrailFuncSync = (context: RunContextWrapper, agent: Agent, input: string | TResponseInputItem[]) => GuardrailFunctionOutput; type InputGuardrailFuncAsync = (context: RunContextWrapper, agent: Agent, input: string | TResponseInputItem[]) => Promise; type OutputGuardrailFuncSync = (context: RunContextWrapper, agent: Agent, agent_output: any) => GuardrailFunctionOutput; type OutputGuardrailFuncAsync = (context: RunContextWrapper, agent: Agent, agent_output: any) => Promise; type InputGuardrailDecorator = (func: InputGuardrailFuncSync | InputGuardrailFuncAsync) => InputGuardrail; type OutputGuardrailDecorator = (func: OutputGuardrailFuncSync | OutputGuardrailFuncAsync) => OutputGuardrail; /** * Decorator that transforms a sync or async function into an `InputGuardrail`. * It can be used directly (no parentheses) or with keyword args, e.g.: * * const myGuardrail = input_guardrail(myFunction); * * // Or with options * const myGuardrail = input_guardrail({ name: "guardrail_name" })(myFunction); * * @param funcOrOptions - Function to decorate or options to use * @returns An InputGuardrail instance or a decorator function */ export declare function input_guardrail(funcOrOptions?: InputGuardrailFuncSync | InputGuardrailFuncAsync | { name?: string | null; }): InputGuardrail | InputGuardrailDecorator; /** * Decorator that transforms a sync or async function into an `OutputGuardrail`. * It can be used directly (no parentheses) or with keyword args, e.g.: * * const myGuardrail = output_guardrail(myFunction); * * // Or with options * const myGuardrail = output_guardrail({ name: "guardrail_name" })(myFunction); * * @param funcOrOptions - Function to decorate or options to use * @returns An OutputGuardrail instance or a decorator function */ export declare function output_guardrail(funcOrOptions?: OutputGuardrailFuncSync | OutputGuardrailFuncAsync | { name?: string | null; }): OutputGuardrail | OutputGuardrailDecorator; export {};