import type { ModelItem } from './types/protocol'; import { Agent, AgentOutputType } from './agent'; import { RunContext } from './runContext'; import { AgentOutputItem, ResolvedAgentOutput, TextOutput, UnknownContext } from './types'; import type { ModelResponse } from './model'; /** * Definition of input/output guardrails; SDK users usually do not need to create this. */ export type GuardrailDefinition = InputGuardrailDefinition | OutputGuardrailDefinition; /** * The output of a guardrail function. */ export interface GuardrailFunctionOutput { /** * Whether the tripwire was triggered. If triggered, the agent's execution will be halted. */ tripwireTriggered: boolean; /** * Optional information about the guardrail's output. * For example, the guardrail could include information about the checks it performed and granular results. */ outputInfo: any; } /** * Arguments for an input guardrail function. */ export interface InputGuardrailFunctionArgs { /** * The agent that is being run. */ agent: Agent; /** * The input to the agent. */ input: string | ModelItem[]; /** * The context of the agent run. */ context: RunContext; } /** * A guardrail that checks the input to the agent. */ export interface InputGuardrail { /** * The name of the guardrail. */ name: string; /** * The function that performs the guardrail check */ execute: InputGuardrailFunction; /** * Whether the guardrail should execute alongside the agent (true, default) or block the * agent until it completes (false). */ runInParallel?: boolean; } /** * The result of an input guardrail execution. */ export interface InputGuardrailResult { /** * The metadata of the guardrail. */ guardrail: InputGuardrailMetadata; /** * The output of the guardrail. */ output: GuardrailFunctionOutput; } /** * The function that performs the actual input guardrail check and returns the decision on whether * a guardrail was triggered. */ export type InputGuardrailFunction = (args: InputGuardrailFunctionArgs) => Promise; /** * Metadata for an input guardrail. */ export interface InputGuardrailMetadata { type: 'input'; name: string; } /** * Definition of an input guardrail. SDK users usually do not need to create this. */ export interface InputGuardrailDefinition extends InputGuardrailMetadata { guardrailFunction: InputGuardrailFunction; runInParallel: boolean; run(args: InputGuardrailFunctionArgs): Promise; } /** * Arguments for defining an input guardrail definition. */ export interface DefineInputGuardrailArgs { name: string; execute: InputGuardrailFunction; runInParallel?: boolean; } /** * Defines an input guardrail definition. */ export declare function defineInputGuardrail({ name, execute, runInParallel, }: DefineInputGuardrailArgs): InputGuardrailDefinition; /** * Arguments for an output guardrail function. */ export interface OutputGuardrailFunctionArgs { agent: Agent; agentOutput: ResolvedAgentOutput; context: RunContext; /** * Additional details about the agent output. */ details?: { /** Model response associated with the output if available. */ modelResponse?: ModelResponse; /** Model output items generated during the run (excluding approvals). */ output?: AgentOutputItem[]; }; } /** * The result of an output guardrail execution. */ export interface OutputGuardrailResult { /** * The metadata of the guardrail. */ guardrail: TMeta; /** * The output of the agent that ran. */ agentOutput: ResolvedAgentOutput; /** * The agent that ran. */ agent: Agent; /** * The output of the guardrail. */ output: GuardrailFunctionOutput; } /** * A function that takes an output guardrail function arguments and returns a `GuardrailFunctionOutput`. */ export type OutputGuardrailFunction = (args: OutputGuardrailFunctionArgs) => Promise; /** * A guardrail that checks the output of the agent. */ export interface OutputGuardrail { /** * The name of the guardrail. */ name: string; /** * The function that performs the guardrail check. */ execute: OutputGuardrailFunction; } /** * Metadata for an output guardrail. */ export interface OutputGuardrailMetadata { type: 'output'; name: string; } /** * Definition of an output guardrail. */ export interface OutputGuardrailDefinition extends OutputGuardrailMetadata { guardrailFunction: OutputGuardrailFunction; run(args: OutputGuardrailFunctionArgs): Promise>; } /** * Arguments for defining an output guardrail definition. */ export interface DefineOutputGuardrailArgs { name: string; execute: OutputGuardrailFunction; } /** * Creates an output guardrail definition. */ export declare function defineOutputGuardrail({ name, execute, }: DefineOutputGuardrailArgs): OutputGuardrailDefinition;