@openai/agents-core
Version:
The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows.
147 lines (146 loc) • 5.05 kB
TypeScript
import { Agent } from './agent';
import { Handoff } from './handoff';
import { RunItem, RunToolApprovalItem } from './items';
import { ModelResponse } from './model';
import { ComputerTool, FunctionTool, HostedMCPTool } from './tool';
import { AgentInputItem, UnknownContext } from './types';
import { StreamedRunResult } from './result';
import { z } from 'zod';
import * as protocol from './types/protocol';
import type { Session, SessionInputCallback } from './memory/session';
type ToolRunHandoff = {
toolCall: protocol.FunctionCallItem;
handoff: Handoff<any, any>;
};
type ToolRunFunction<TContext = UnknownContext> = {
toolCall: protocol.FunctionCallItem;
tool: FunctionTool<TContext>;
};
type ToolRunComputer = {
toolCall: protocol.ComputerUseCallItem;
computer: ComputerTool;
};
type ToolRunMCPApprovalRequest = {
requestItem: RunToolApprovalItem;
mcpTool: HostedMCPTool;
};
export type ProcessedResponse<TContext = UnknownContext> = {
newItems: RunItem[];
handoffs: ToolRunHandoff[];
functions: ToolRunFunction<TContext>[];
computerActions: ToolRunComputer[];
mcpApprovalRequests: ToolRunMCPApprovalRequest[];
toolsUsed: string[];
hasToolsOrApprovalsToRun(): boolean;
};
export declare const nextStepSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
type: z.ZodLiteral<"next_step_handoff">;
newAgent: z.ZodAny;
}, "strip", z.ZodTypeAny, {
type: "next_step_handoff";
newAgent?: any;
}, {
type: "next_step_handoff";
newAgent?: any;
}>, z.ZodObject<{
type: z.ZodLiteral<"next_step_final_output">;
output: z.ZodString;
}, "strip", z.ZodTypeAny, {
type: "next_step_final_output";
output: string;
}, {
type: "next_step_final_output";
output: string;
}>, z.ZodObject<{
type: z.ZodLiteral<"next_step_run_again">;
}, "strip", z.ZodTypeAny, {
type: "next_step_run_again";
}, {
type: "next_step_run_again";
}>, z.ZodObject<{
type: z.ZodLiteral<"next_step_interruption">;
data: z.ZodRecord<z.ZodString, z.ZodAny>;
}, "strip", z.ZodTypeAny, {
type: "next_step_interruption";
data: Record<string, any>;
}, {
type: "next_step_interruption";
data: Record<string, any>;
}>]>;
export type NextStep = z.infer<typeof nextStepSchema>;
/**
* Internal convenience wrapper that groups the outcome of a single agent turn. It lets the caller
* update the RunState in one shot and decide which step to execute next.
*/
declare class SingleStepResult {
/**
* The input items (i.e., the items before run() was called). May be mutated by handoff input filters.
*/
originalInput: string | AgentInputItem[];
/**
* The model response for the current step
*/
modelResponse: ModelResponse;
/**
* The items before the current step was executed
*/
preStepItems: RunItem[];
/**
* The items after the current step was executed
*/
newStepItems: RunItem[];
/**
* The next step to execute
*/
nextStep: NextStep;
constructor(
/**
* The input items (i.e., the items before run() was called). May be mutated by handoff input filters.
*/
originalInput: string | AgentInputItem[],
/**
* The model response for the current step
*/
modelResponse: ModelResponse,
/**
* The items before the current step was executed
*/
preStepItems: RunItem[],
/**
* The items after the current step was executed
*/
newStepItems: RunItem[],
/**
* The next step to execute
*/
nextStep: NextStep);
/**
* The items generated during the agent run (i.e. everything generated after originalInput)
*/
get generatedItems(): RunItem[];
}
export declare function streamStepItemsToRunResult(result: StreamedRunResult<any, any>, items: RunItem[]): void;
export declare function addStepToRunResult(result: StreamedRunResult<any, any>, step: SingleStepResult, options?: {
skipItems?: Set<RunItem>;
}): void;
export declare class AgentToolUseTracker {
#private;
addToolUse(agent: Agent<any, any>, toolNames: string[]): void;
hasUsedTools(agent: Agent<any, any>): boolean;
toJSON(): Record<string, string[]>;
}
export declare function prepareInputItemsWithSession(input: string | AgentInputItem[], session?: Session, sessionInputCallback?: SessionInputCallback, options?: {
/**
* When true (default), the returned `preparedInput` includes both the persisted session history
* and the new turn items. Set to false when upstream code already provides history to the model
* (e.g. server-managed conversations) to avoid sending duplicated messages each turn.
*/
includeHistoryInPreparedInput?: boolean;
/**
* When true, ensures new turn inputs are still provided to the model even if the session input
* callback drops them from persistence (used for server-managed conversations that redact
* writes).
*/
preserveDroppedNewItems?: boolean;
}): Promise<PreparedInputWithSessionResult>;
export {};