UNPKG

@openai/agents-core

Version:

The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows.

82 lines (81 loc) • 5.78 kB
import { type OpenAIResponsesCompactionArgs, type OpenAIResponsesCompactionAwareSession, type Session, type SessionInputCallback } from '../memory/session'; import { RunResult, StreamedRunResult } from '../result'; import { RunState, type PendingSessionWrite } from '../runState'; import type { RunContext } from '../runContext'; import { RunItem } from '../items'; import { AgentInputItem } from '../types'; import { type ReasoningItemIdPolicy } from './items'; export { selectRunItemIndexesForBlockedOutput } from './blockedOutputPersistence'; export type PreparedInputWithSessionResult = { preparedInput: string | AgentInputItem[]; sessionItems?: AgentInputItem[]; }; export type SessionPersistenceOptions = { runCompaction?: boolean; compactionMode?: OpenAIResponsesCompactionArgs['compactionMode']; outputBlocked?: boolean; additionalRunItems?: RunItem[]; }; export type ResumedSessionWritePreparation = { readonly session: Session; readonly state: RunState<any, any>; readonly sessionId: string; readonly reasoningItemIdPolicy: ReasoningItemIdPolicy; handoffInput?: PendingSessionWrite['handoffInput']; }; export type SessionCompactionState = { session: Session; ownership: object | null; modelExchange?: Parameters<OpenAIResponsesCompactionAwareSession['runCompaction']>[3]; }; export declare function getSessionCompactionState(session: Session | undefined, state?: RunState<any, any>): SessionCompactionState | undefined; export declare function bindSessionCompactionState(state: RunState<any, any>, binding: SessionCompactionState | undefined): void; /** Capture final input now, but authorize compaction only after the response succeeds. */ export declare function prepareSessionCompactionExchange(session: Session | undefined, state: RunState<any, any>, input: AgentInputItem[]): (output: AgentInputItem[], responseId?: string) => void; export declare function prepareResumedSessionWrite(session: Session, state: RunState<any, any>): Promise<ResumedSessionWritePreparation>; export declare function acquireResumedSessionWriteOperation(state: RunState<any, any>): () => void; export declare function reconcilePendingSessionWriteBeforeRun(session: Session | undefined, state: RunState<any, any>, options: { serverManagesConversation: boolean; operationAlreadyOwned?: boolean; }): Promise<boolean>; export declare function selectRunItemsForBlockedOutput(items: RunItem[], unpersistedStartIndex?: number): RunItem[]; export declare function canPersistBlockedOutputToSession(session: Session | undefined, state: RunState<any, any>): boolean; export declare function prepareSessionHistoryTransactionsForRun(session: Session | undefined, state: RunState<any, any>, options: { serverManagesConversation: boolean; }): Promise<void>; export declare function captureSessionHistoryTransactionInputItems(session: Session | undefined, state: RunState<any, any>, items: AgentInputItem[] | undefined): void; export declare function markSessionHistoryTransactionInputPersisted(state: RunState<any, any>): void; export declare function releaseUnusedSessionHistoryTransactionBinding(state: RunState<any, any>): void; export declare function releaseProvisionalSessionHistoryTransactionBinding(state: RunState<any, any>, provisionalSessionId: string | undefined, portableInputItems: AgentInputItem[] | undefined): void; export type SessionPersistenceTracker = { setPreparedItems: (items?: AgentInputItem[], preparedInput?: string | AgentInputItem[]) => void; setPreparedTurnItems: (preparedItems: AgentInputItem[], processedItems: AgentInputItem[]) => void; recordTurnItems: (sourceItems: (AgentInputItem | undefined)[], filteredItems?: AgentInputItem[]) => void; getItemsForPersistence: () => AgentInputItem[] | undefined; buildPersistInputOnce: (serverManagesConversation: boolean) => (() => Promise<void>) | undefined; }; export declare function createSessionPersistenceTracker(options: { session?: Session; runContext?: RunContext<any>; compactionState?: SessionCompactionState; hasCallModelInputFilter: boolean; persistInput?: typeof saveStreamInputToSession; resumingFromState?: boolean; resumedSessionInputItems?: AgentInputItem[]; }): SessionPersistenceTracker | undefined; /** * Maps selected input occurrences through sandbox capability context processing. */ export declare function mapOwnedInputItemsAfterContextProcessing(preparedItems: AgentInputItem[], processedItems: AgentInputItem[], ownedItems: AgentInputItem[]): Array<{ item: AgentInputItem; ownerIndex: number; }>; export declare function saveToSession(session: Session | undefined, sessionInputItems: AgentInputItem[] | undefined, result: RunResult<any, any>, options?: SessionPersistenceOptions): Promise<void>; export declare function saveStreamInputToSession(session: Session | undefined, sessionInputItems: AgentInputItem[] | undefined, runContext?: RunContext<any>, compactionState?: SessionCompactionState): Promise<void>; export declare function saveStreamResultToSession(session: Session | undefined, result: StreamedRunResult<any, any>, options?: SessionPersistenceOptions, sessionInputItems?: AgentInputItem[]): Promise<void>; export declare function reconcileLegacyCompactionSessionBeforeResume(session: Session | undefined, state: RunState<any, any>): Promise<void>; export declare function prepareInputItemsWithSession(input: string | AgentInputItem[], session?: Session, sessionInputCallback?: SessionInputCallback, options?: { includeHistoryInPreparedInput?: boolean; preserveDroppedNewItems?: boolean; reasoningItemIdPolicy?: ReasoningItemIdPolicy; }, runContext?: RunContext<any>, compactionState?: SessionCompactionState): Promise<PreparedInputWithSessionResult>;