Skip to content
13 min read · 2,593 words

Function: buildOpenAIResponsesInput()

ts
function buildOpenAIResponsesInput(input: {
  bucketOrder: ChatCompletionsBucketOrder;
  descriptionToChatCompletionsJsonSchema: (d: DescriptionLike) => JsonSchema;
  filterThoughts: (thoughts: Iterable<Thought>, mode: "all-self" | "latest-self" | "all", selfIdentity: string, replayCompatibility: readonly string[]) => Thought[];
  fingerprintOpenAIResponsesPrefix: (input: {
     input: OpenAIResponsesInputItem[];
     instructions?: string;
     model: string;
     throughItem?: number;
     tools?: OpenAIResponsesTool[];
  }) => Promise<string>;
  memories: Iterable<Memory>;
  messages: Iterable<Message>;
  model: string;
  reasoningReplay: ReasoningReplayMode;
  renderChatCompletionsSystemPrompt: (input: {
     bucketOrder: ChatCompletionsBucketOrder;
     memories: Iterable<Memory>;
     renderCtx?: unknown;
     renderFirstPartyRetrievables: (items: Iterable<{
        attrs: RetrievableAttrs;
        retrievable: Retrievable;
      }>, renderRetrievableHandleBody?: (input: {
        artifact: unknown;
        byteLength: number;
        callId: string;
        encoding?: string;
        estimatedTokens?: number;
        lineCount: number;
     }) => string) => Promise<string>;
     renderMemories: (items: Iterable<{
        attrs: MemoryAttrs;
        memory: Memory;
     }>) => string;
     renderRetrievableHandleBody?: (input: {
        artifact: unknown;
        byteLength: number;
        callId: string;
        encoding?: string;
        estimatedTokens?: number;
        lineCount: number;
     }) => string;
     renderRetrievables: (items: Iterable<{
        attrs: RetrievableAttrs;
        retrievable: Retrievable;
      }>, deps: {
        renderFirstPartyRetrievables: (items: Iterable<{
           attrs: RetrievableAttrs;
           retrievable: Retrievable;
         }>, renderRetrievableHandleBody?: (input: {
           artifact: unknown;
           byteLength: number;
           callId: string;
           encoding?: string;
           estimatedTokens?: number;
           lineCount: number;
        }) => string) => Promise<string>;
        renderRetrievableHandleBody?: (input: {
           artifact: unknown;
           byteLength: number;
           callId: string;
           encoding?: string;
           estimatedTokens?: number;
           lineCount: number;
        }) => string;
        renderRetrievableSafetyDirective: () => string;
        renderThirdPartyPrivateRetrievables: (items: Iterable<{
           attrs: RetrievableAttrs;
           retrievable: Retrievable;
         }>, deps: {
           renderRetrievableHandleBody?: (input: {
              artifact: unknown;
              byteLength: number;
              callId: string;
              encoding?: ... | ...;
              estimatedTokens?: ... | ...;
              lineCount: number;
           }) => string;
           renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string;
        }) => Promise<string>;
        renderThirdPartyPublicRetrievables: (items: Iterable<{
           attrs: RetrievableAttrs;
           retrievable: Retrievable;
         }>, deps: {
           renderRetrievableHandleBody?: (input: {
              artifact: unknown;
              byteLength: number;
              callId: string;
              encoding?: ... | ...;
              estimatedTokens?: ... | ...;
              lineCount: number;
           }) => string;
           renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string;
        }) => Promise<string>;
        renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string;
     }) => Promise<string>;
     renderRetrievableSafetyDirective: () => string;
     renderStandingInstructions: (items: Iterable<Tokenizable>, attrs?: StandingInstructionAttrs) => string;
     renderThirdPartyPrivateRetrievables: (items: Iterable<{
        attrs: RetrievableAttrs;
        retrievable: Retrievable;
      }>, deps: {
        renderRetrievableHandleBody?: (input: {
           artifact: unknown;
           byteLength: number;
           callId: string;
           encoding?: string;
           estimatedTokens?: number;
           lineCount: number;
        }) => string;
        renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string;
     }) => Promise<string>;
     renderThirdPartyPublicRetrievables: (items: Iterable<{
        attrs: RetrievableAttrs;
        retrievable: Retrievable;
      }>, deps: {
        renderRetrievableHandleBody?: (input: {
           artifact: unknown;
           byteLength: number;
           callId: string;
           encoding?: string;
           estimatedTokens?: number;
           lineCount: number;
        }) => string;
        renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string;
     }) => Promise<string>;
     renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string;
     retrievables: Iterable<Retrievable>;
     standingInstructions: Iterable<Tokenizable>;
     systemPrompt: Tokenizable;
  }) => Promise<string>;
  renderCtx?: unknown;
  renderedToolCallResults: Map<string,
     | string
    | OpenAIResponsesInputContentBlock[]>;
  renderFirstPartyRetrievables: (items: Iterable<{
     attrs: RetrievableAttrs;
     retrievable: Retrievable;
   }>, renderRetrievableHandleBody?: (input: {
     artifact: unknown;
     byteLength: number;
     callId: string;
     encoding?: string;
     estimatedTokens?: number;
     lineCount: number;
  }) => string) => Promise<string>;
  renderMemories: (items: Iterable<{
     attrs: MemoryAttrs;
     memory: Memory;
  }>) => string;
  renderOpenAIResponsesMediaBlocks: (input: {
     media: Media;
     renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string;
     renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string;
     unsupportedMediaPolicy: UnsupportedMediaPolicy;
     warn?: (msg: string) => void;
  }) => Promise<OpenAIResponsesInputContentBlock[]>;
  renderOpenAIResponsesReasoningItem: (input: {
     prefixFingerprint: string;
     reasoningReplay: ReasoningReplayMode;
     replayCompatibility: readonly string[];
     thought: Thought;
     warn?: (msg: string) => void;
   }) =>
     | OpenAIResponsesReasoningItem
    | undefined;
  renderOpenAIResponsesTimelineMessage: (input: {
     message: Message;
     renderOpenAIResponsesMediaBlocks: (input: {
        media: Media;
        renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string;
        renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string;
        unsupportedMediaPolicy: UnsupportedMediaPolicy;
        warn?: (msg: string) => void;
     }) => Promise<OpenAIResponsesInputContentBlock[]>;
     renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string;
     renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string;
     selfIdentity: string;
     unsupportedMediaPolicy: UnsupportedMediaPolicy;
     warn?: (msg: string) => void;
   }) => Promise<
     | OpenAIResponsesInputItem
    | null>;
  renderOpenAIResponsesToolCallResult: (input: {
     renderArtifactHandleBody?: (input: {
        artifact: unknown;
        byteLength: number;
        callId: string;
        encoding?: string;
        estimatedTokens?: number;
        lineCount: number;
     }) => string;
     renderOpenAIResponsesMediaBlocks: (input: {
        media: Media;
        renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string;
        renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string;
        unsupportedMediaPolicy: UnsupportedMediaPolicy;
        warn?: (msg: string) => void;
     }) => Promise<OpenAIResponsesInputContentBlock[]>;
     renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string;
     renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string;
     results:   | Tokenizable
        | SpooledArtifact
        | Media
        | Media[]
        | SpooledArtifact[];
     tool:   | Tool<SpooledArtifact>
        | ArtifactTool
        | undefined;
     toolCall: ToolCall;
     unsupportedMediaPolicy: UnsupportedMediaPolicy;
     warn?: (msg: string) => void;
   }) => Promise<
     | string
    | OpenAIResponsesInputContentBlock[]>;
  renderRetrievableHandleBody?: (input: {
     artifact: unknown;
     byteLength: number;
     callId: string;
     encoding?: string;
     estimatedTokens?: number;
     lineCount: number;
  }) => string;
  renderRetrievables: (items: Iterable<{
     attrs: RetrievableAttrs;
     retrievable: Retrievable;
   }>, deps: {
     renderFirstPartyRetrievables: (items: Iterable<{
        attrs: RetrievableAttrs;
        retrievable: Retrievable;
      }>, renderRetrievableHandleBody?: (input: {
        artifact: unknown;
        byteLength: number;
        callId: string;
        encoding?: string;
        estimatedTokens?: number;
        lineCount: number;
     }) => string) => Promise<string>;
     renderRetrievableHandleBody?: (input: {
        artifact: unknown;
        byteLength: number;
        callId: string;
        encoding?: string;
        estimatedTokens?: number;
        lineCount: number;
     }) => string;
     renderRetrievableSafetyDirective: () => string;
     renderThirdPartyPrivateRetrievables: (items: Iterable<{
        attrs: RetrievableAttrs;
        retrievable: Retrievable;
      }>, deps: {
        renderRetrievableHandleBody?: (input: {
           artifact: unknown;
           byteLength: number;
           callId: string;
           encoding?: string;
           estimatedTokens?: number;
           lineCount: number;
        }) => string;
        renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string;
     }) => Promise<string>;
     renderThirdPartyPublicRetrievables: (items: Iterable<{
        attrs: RetrievableAttrs;
        retrievable: Retrievable;
      }>, deps: {
        renderRetrievableHandleBody?: (input: {
           artifact: unknown;
           byteLength: number;
           callId: string;
           encoding?: string;
           estimatedTokens?: number;
           lineCount: number;
        }) => string;
        renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string;
     }) => Promise<string>;
     renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string;
  }) => Promise<string>;
  renderRetrievableSafetyDirective: () => string;
  renderStandingInstructions: (items: Iterable<Tokenizable>, attrs?: StandingInstructionAttrs) => string;
  renderThirdPartyPrivateRetrievables: (items: Iterable<{
     attrs: RetrievableAttrs;
     retrievable: Retrievable;
   }>, deps: {
     renderRetrievableHandleBody?: (input: {
        artifact: unknown;
        byteLength: number;
        callId: string;
        encoding?: string;
        estimatedTokens?: number;
        lineCount: number;
     }) => string;
     renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string;
  }) => Promise<string>;
  renderThirdPartyPublicRetrievables: (items: Iterable<{
     attrs: RetrievableAttrs;
     retrievable: Retrievable;
   }>, deps: {
     renderRetrievableHandleBody?: (input: {
        artifact: unknown;
        byteLength: number;
        callId: string;
        encoding?: string;
        estimatedTokens?: number;
        lineCount: number;
     }) => string;
     renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string;
  }) => Promise<string>;
  renderThought: (content: string, attrs: ThoughtAttrs, payload?: unknown) => string;
  renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string;
  renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string;
  replayCompatibility: readonly string[];
  retrievables: Iterable<Retrievable>;
  selfIdentity: string;
  standingInstructions: Iterable<Tokenizable>;
  strict?: boolean;
  systemPrompt: Tokenizable;
  systemPromptChannel: SystemPromptChannel;
  thoughts: Iterable<Thought>;
  thoughtSurfacing: "all-self" | "latest-self" | "all";
  toolCalls: Iterable<ToolCall>;
  tools: ToolRegistry;
  toolsToOpenAIResponsesTools: (tools: readonly (
     | Tool<SpooledArtifact>
     | ArtifactTool)[], deps: {
     descriptionToChatCompletionsJsonSchema: (d: unknown) => JsonSchema;
     strict?: boolean;
  }) => OpenAIResponsesTool[];
  unsupportedMediaPolicy: UnsupportedMediaPolicy;
  warn?: (msg: string) => void;
}): Promise<{
  fingerprintableLength: number;
  input: OpenAIResponsesInputItem[];
  instructions?: string;
  tools?: OpenAIResponsesTool[];
}>;

Defined in: src/batteries/llm/openai_responses/helpers.ts:758

Implements OpenAIResponsesHelpers.buildOpenAIResponsesInput.

Parameters

ParameterTypeDescription
input{ bucketOrder: ChatCompletionsBucketOrder; descriptionToChatCompletionsJsonSchema: (d: DescriptionLike) => JsonSchema; filterThoughts: (thoughts: Iterable<Thought>, mode: "all-self" | "latest-self" | "all", selfIdentity: string, replayCompatibility: readonly string[]) => Thought[]; fingerprintOpenAIResponsesPrefix: (input: { input: OpenAIResponsesInputItem[]; instructions?: string; model: string; throughItem?: number; tools?: OpenAIResponsesTool[]; }) => Promise<string>; memories: Iterable<Memory>; messages: Iterable<Message>; model: string; reasoningReplay: ReasoningReplayMode; renderChatCompletionsSystemPrompt: (input: { bucketOrder: ChatCompletionsBucketOrder; memories: Iterable<Memory>; renderCtx?: unknown; renderFirstPartyRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string) => Promise<string>; renderMemories: (items: Iterable<{ attrs: MemoryAttrs; memory: Memory; }>) => string; renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string; renderRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderFirstPartyRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string) => Promise<string>; renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string; renderRetrievableSafetyDirective: () => string; renderThirdPartyPrivateRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: ... | ...; estimatedTokens?: ... | ...; lineCount: number; }) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: ... | ...; estimatedTokens?: ... | ...; lineCount: number; }) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderRetrievableSafetyDirective: () => string; renderStandingInstructions: (items: Iterable<Tokenizable>, attrs?: StandingInstructionAttrs) => string; renderThirdPartyPrivateRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; retrievables: Iterable<Retrievable>; standingInstructions: Iterable<Tokenizable>; systemPrompt: Tokenizable; }) => Promise<string>; renderCtx?: unknown; renderedToolCallResults: Map<string, | string | OpenAIResponsesInputContentBlock[]>; renderFirstPartyRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string) => Promise<string>; renderMemories: (items: Iterable<{ attrs: MemoryAttrs; memory: Memory; }>) => string; renderOpenAIResponsesMediaBlocks: (input: { media: Media; renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; unsupportedMediaPolicy: UnsupportedMediaPolicy; warn?: (msg: string) => void; }) => Promise<OpenAIResponsesInputContentBlock[]>; renderOpenAIResponsesReasoningItem: (input: { prefixFingerprint: string; reasoningReplay: ReasoningReplayMode; replayCompatibility: readonly string[]; thought: Thought; warn?: (msg: string) => void; }) => | OpenAIResponsesReasoningItem | undefined; renderOpenAIResponsesTimelineMessage: (input: { message: Message; renderOpenAIResponsesMediaBlocks: (input: { media: Media; renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; unsupportedMediaPolicy: UnsupportedMediaPolicy; warn?: (msg: string) => void; }) => Promise<OpenAIResponsesInputContentBlock[]>; renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; selfIdentity: string; unsupportedMediaPolicy: UnsupportedMediaPolicy; warn?: (msg: string) => void; }) => Promise< | OpenAIResponsesInputItem | null>; renderOpenAIResponsesToolCallResult: (input: { renderArtifactHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string; renderOpenAIResponsesMediaBlocks: (input: { media: Media; renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; unsupportedMediaPolicy: UnsupportedMediaPolicy; warn?: (msg: string) => void; }) => Promise<OpenAIResponsesInputContentBlock[]>; renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; results: | Tokenizable | SpooledArtifact | Media | Media[] | SpooledArtifact[]; tool: | Tool<SpooledArtifact> | ArtifactTool | undefined; toolCall: ToolCall; unsupportedMediaPolicy: UnsupportedMediaPolicy; warn?: (msg: string) => void; }) => Promise< | string | OpenAIResponsesInputContentBlock[]>; renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string; renderRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderFirstPartyRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string) => Promise<string>; renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string; renderRetrievableSafetyDirective: () => string; renderThirdPartyPrivateRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderRetrievableSafetyDirective: () => string; renderStandingInstructions: (items: Iterable<Tokenizable>, attrs?: StandingInstructionAttrs) => string; renderThirdPartyPrivateRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderThought: (content: string, attrs: ThoughtAttrs, payload?: unknown) => string; renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; replayCompatibility: readonly string[]; retrievables: Iterable<Retrievable>; selfIdentity: string; standingInstructions: Iterable<Tokenizable>; strict?: boolean; systemPrompt: Tokenizable; systemPromptChannel: SystemPromptChannel; thoughts: Iterable<Thought>; thoughtSurfacing: "all-self" | "latest-self" | "all"; toolCalls: Iterable<ToolCall>; tools: ToolRegistry; toolsToOpenAIResponsesTools: (tools: readonly ( | Tool<SpooledArtifact> | ArtifactTool)[], deps: { descriptionToChatCompletionsJsonSchema: (d: unknown) => JsonSchema; strict?: boolean; }) => OpenAIResponsesTool[]; unsupportedMediaPolicy: UnsupportedMediaPolicy; warn?: (msg: string) => void; }-
input.bucketOrderChatCompletionsBucketOrder-
input.descriptionToChatCompletionsJsonSchema(d: DescriptionLike) => JsonSchema-
input.filterThoughts(thoughts: Iterable<Thought>, mode: "all-self" | "latest-self" | "all", selfIdentity: string, replayCompatibility: readonly string[]) => Thought[]-
input.fingerprintOpenAIResponsesPrefix(input: { input: OpenAIResponsesInputItem[]; instructions?: string; model: string; throughItem?: number; tools?: OpenAIResponsesTool[]; }) => Promise<string>-
input.memoriesIterable<Memory>-
input.messagesIterable<Message>-
input.modelstring-
input.reasoningReplayReasoningReplayMode-
input.renderChatCompletionsSystemPrompt(input: { bucketOrder: ChatCompletionsBucketOrder; memories: Iterable<Memory>; renderCtx?: unknown; renderFirstPartyRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string) => Promise<string>; renderMemories: (items: Iterable<{ attrs: MemoryAttrs; memory: Memory; }>) => string; renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string; renderRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderFirstPartyRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string) => Promise<string>; renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string; renderRetrievableSafetyDirective: () => string; renderThirdPartyPrivateRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: ... | ...; estimatedTokens?: ... | ...; lineCount: number; }) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: ... | ...; estimatedTokens?: ... | ...; lineCount: number; }) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderRetrievableSafetyDirective: () => string; renderStandingInstructions: (items: Iterable<Tokenizable>, attrs?: StandingInstructionAttrs) => string; renderThirdPartyPrivateRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; retrievables: Iterable<Retrievable>; standingInstructions: Iterable<Tokenizable>; systemPrompt: Tokenizable; }) => Promise<string>-
input.renderCtx?unknownLive dispatch context used to resolve a DYNAMIC systemPrompt via .render(ctx). Forwarded to renderChatCompletionsSystemPrompt, whose own renderCtx seam exists for this. Without it a context-reading system prompt renders against undefined and silently loses whatever it was reading.
input.renderedToolCallResultsMap<string, | string | OpenAIResponsesInputContentBlock[]>-
input.renderFirstPartyRetrievables(items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string) => Promise<string>-
input.renderMemories(items: Iterable<{ attrs: MemoryAttrs; memory: Memory; }>) => string-
input.renderOpenAIResponsesMediaBlocks(input: { media: Media; renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; unsupportedMediaPolicy: UnsupportedMediaPolicy; warn?: (msg: string) => void; }) => Promise<OpenAIResponsesInputContentBlock[]>-
input.renderOpenAIResponsesReasoningItem(input: { prefixFingerprint: string; reasoningReplay: ReasoningReplayMode; replayCompatibility: readonly string[]; thought: Thought; warn?: (msg: string) => void; }) => | OpenAIResponsesReasoningItem | undefined-
input.renderOpenAIResponsesTimelineMessage(input: { message: Message; renderOpenAIResponsesMediaBlocks: (input: { media: Media; renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; unsupportedMediaPolicy: UnsupportedMediaPolicy; warn?: (msg: string) => void; }) => Promise<OpenAIResponsesInputContentBlock[]>; renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; selfIdentity: string; unsupportedMediaPolicy: UnsupportedMediaPolicy; warn?: (msg: string) => void; }) => Promise< | OpenAIResponsesInputItem | null>-
input.renderOpenAIResponsesToolCallResult(input: { renderArtifactHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string; renderOpenAIResponsesMediaBlocks: (input: { media: Media; renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; unsupportedMediaPolicy: UnsupportedMediaPolicy; warn?: (msg: string) => void; }) => Promise<OpenAIResponsesInputContentBlock[]>; renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; results: | Tokenizable | SpooledArtifact | Media | Media[] | SpooledArtifact[]; tool: | Tool<SpooledArtifact> | ArtifactTool | undefined; toolCall: ToolCall; unsupportedMediaPolicy: UnsupportedMediaPolicy; warn?: (msg: string) => void; }) => Promise< | string | OpenAIResponsesInputContentBlock[]>-
input.renderRetrievableHandleBody?(input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string-
input.renderRetrievables(items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderFirstPartyRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string) => Promise<string>; renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string; renderRetrievableSafetyDirective: () => string; renderThirdPartyPrivateRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>-
input.renderRetrievableSafetyDirective() => string-
input.renderStandingInstructions(items: Iterable<Tokenizable>, attrs?: StandingInstructionAttrs) => string-
input.renderThirdPartyPrivateRetrievables(items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>-
input.renderThirdPartyPublicRetrievables(items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>-
input.renderThought(content: string, attrs: ThoughtAttrs, payload?: unknown) => string-
input.renderTrustedContent(content: string, attrs: TrustedContentAttrs) => string-
input.renderUntrustedContent(content: string, attrs: UntrustedContentAttrs) => string-
input.replayCompatibilityreadonly string[]-
input.retrievablesIterable<Retrievable>-
input.selfIdentitystring-
input.standingInstructionsIterable<Tokenizable>-
input.strict?boolean-
input.systemPromptTokenizable-
input.systemPromptChannelSystemPromptChannel-
input.thoughtsIterable<Thought>-
input.thoughtSurfacing"all-self" | "latest-self" | "all"-
input.toolCallsIterable<ToolCall>-
input.toolsToolRegistry-
input.toolsToOpenAIResponsesTools(tools: readonly ( | Tool<SpooledArtifact> | ArtifactTool)[], deps: { descriptionToChatCompletionsJsonSchema: (d: unknown) => JsonSchema; strict?: boolean; }) => OpenAIResponsesTool[]-
input.unsupportedMediaPolicyUnsupportedMediaPolicy-
input.warn?(msg: string) => void-

Returns

Promise<{ fingerprintableLength: number; input: OpenAIResponsesInputItem[]; instructions?: string; tools?: OpenAIResponsesTool[]; }>

Remarks

Algorithm (mirrors the plan's Part 2 spec exactly):

  1. Leading instructions (or leading developer/system-role item, per systemPromptChannel) — ALWAYS ADK-rendered via renderChatCompletionsSystemPrompt; there is no consumer-facing escape hatch.
  2. Timeline: messages/thoughts/tool-calls merged and sorted by createdAt. A tool call renders as two SIBLING top-level items (function_call then function_call_output), with composite id splitting. A thought replays as a native reasoning item only when reasoningReplay !== 'off' and a valid, prefix-matched signature exists; otherwise it renders as plain text.
  3. Reasoning-pairing enforcement pass — walks input left to right, dropping any reasoning item not immediately followed by its paired output item, and stripping the id from an output item whose paired reasoning item was just dropped.
  4. Trailing buckets (bucketOrder labels after 'timeline') render as a trailing {type:'message', role:'system', ...} item.

Load-bearing invariants

These are consequences of the step ORDER above, not incidental details. Both were unwritten once, and both were violated in ways that silently disabled reasoning replay — so they are stated here explicitly and pinned by executable tests (see tests/unit/batteries/llm/openai_responses/reasoning_replay.cross.spec.ts, "assembly invariants").

  1. The step-3 sweep only ever sees a PREFIX of the final input. Step 4 appends the trailing bucket AFTER the sweep has run, so any item added there is invisible to every fingerprint the sweep computes. A reasoning-replay fingerprint must therefore cover only the sweep-visible region — that is what the returned fingerprintableLength marks, and why persistThought passes it as throughItem. Hashing the whole input instead cannot match on the next turn whenever a trailing bucket exists, and drops every replayed item as stale.

  2. A reasoning item must sort STRICTLY BEFORE the output item it is paired with. The step-2 timeline pushes messages before thoughts and then applies a STABLE sort by createdAt, so on an identical timestamp the message wins the tie and lands ahead of its own reasoning item — leaving that item unpaired, and the step-3 sweep drops it. Callers persisting a thought and its message from one response must therefore assign strictly increasing timestamps rather than calling a clock twice (two DateTime.now() calls collide ~998 times in 1000).

  3. tools is undefined, never [], when the registry is empty (see the return shape). Fingerprints on both the persist and validate side must use that same shape: canonicalFingerprint serialises undefined and [] to different bytes, so coercing on one side only makes every hash mismatch for tool-less agents.