Skip to content
13 min read · 2,645 words

Function: buildAnthropicMessagesHistory()

ts
function buildAnthropicMessagesHistory(input: {
  bucketOrder: ChatCompletionsBucketOrder;
  cacheBreakpoints: AnthropicCacheBreakpoints;
  cacheTtl?: AnthropicCacheTtl;
  filterThoughts: (thoughts: Iterable<Thought>, mode: "all" | "all-self" | "latest-self", selfIdentity: string, replayCompatibility: readonly string[]) => Thought[];
  memories: Iterable<Memory>;
  messages: Iterable<Message>;
  model: string;
  renderAnthropicSegmentedSystemPrompt: (input: {
     bucketOrder: ChatCompletionsBucketOrder;
     cacheBreakpoints: AnthropicCacheBreakpoints;
     cacheTtl?: AnthropicCacheTtl;
     memories: Iterable<Memory>;
     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;
     warn?: (msg: string) => void;
  }) => Promise<TextBlockParam[]>;
  renderAnthropicThinkingBlocks: (input: {
     model: string;
     prefixFingerprint: string;
     replayCompatibility: readonly string[];
     thought: Thought;
     warn?: (msg: string) => void;
  }) => ContentBlockParam[];
  renderAnthropicTimelineMessage: (input: {
     message: Message;
     renderAnthropicMediaBlocks: (input: {
        media: Media;
        renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string;
        renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string;
        unsupportedMediaPolicy: UnsupportedMediaPolicy;
        warn?: (msg: string) => void;
     }) => Promise<ContentBlockParam[]>;
     selfIdentity: string;
     unsupportedMediaPolicy: UnsupportedMediaPolicy;
     warn?: (msg: string) => void;
  }) => Promise<MessageParam | null>;
  renderAnthropicToolCallResult: (input: {
     renderAnthropicMediaBlocks: (input: {
        media: Media;
        renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string;
        renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string;
        unsupportedMediaPolicy: UnsupportedMediaPolicy;
        warn?: (msg: string) => void;
     }) => Promise<ContentBlockParam[]>;
     renderArtifactHandleBody?: (input: {
        artifact: unknown;
        byteLength: number;
        callId: string;
        encoding?: string;
        estimatedTokens?: number;
        lineCount: number;
     }) => string;
     renderRetrievableHandleBody?: (input: {
        artifact: unknown;
        byteLength: number;
        callId: string;
        encoding?: string;
        estimatedTokens?: number;
        lineCount: number;
     }) => string;
     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<ToolResultBlockParam>;
  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>;
  renderedToolCallResults: Map<ToolCall, ToolResultBlockParam>;
  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?: 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>;
  systemPrompt: Tokenizable;
  thoughts: Iterable<Thought>;
  thoughtSurfacing: "all" | "all-self" | "latest-self";
  toolCalls: Iterable<ToolCall>;
  tools: ToolRegistry;
  unsupportedMediaPolicy: UnsupportedMediaPolicy;
  warn?: (msg: string) => void;
}): Promise<{
  messages: MessageParam[];
  system?: string | TextBlockParam[];
  tools?: Tool[];
}>;

Defined in: src/batteries/llm/anthropic_messages/helpers.ts:521

Assembles Anthropic system content, messages, tools, and safely replayable thinking.

Parameters

ParameterTypeDescription
input{ bucketOrder: ChatCompletionsBucketOrder; cacheBreakpoints: AnthropicCacheBreakpoints; cacheTtl?: AnthropicCacheTtl; filterThoughts: (thoughts: Iterable<Thought>, mode: "all" | "all-self" | "latest-self", selfIdentity: string, replayCompatibility: readonly string[]) => Thought[]; memories: Iterable<Memory>; messages: Iterable<Message>; model: string; renderAnthropicSegmentedSystemPrompt: (input: { bucketOrder: ChatCompletionsBucketOrder; cacheBreakpoints: AnthropicCacheBreakpoints; cacheTtl?: AnthropicCacheTtl; memories: Iterable<Memory>; 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; warn?: (msg: string) => void; }) => Promise<TextBlockParam[]>; renderAnthropicThinkingBlocks: (input: { model: string; prefixFingerprint: string; replayCompatibility: readonly string[]; thought: Thought; warn?: (msg: string) => void; }) => ContentBlockParam[]; renderAnthropicTimelineMessage: (input: { message: Message; renderAnthropicMediaBlocks: (input: { media: Media; renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; unsupportedMediaPolicy: UnsupportedMediaPolicy; warn?: (msg: string) => void; }) => Promise<ContentBlockParam[]>; selfIdentity: string; unsupportedMediaPolicy: UnsupportedMediaPolicy; warn?: (msg: string) => void; }) => Promise<MessageParam | null>; renderAnthropicToolCallResult: (input: { renderAnthropicMediaBlocks: (input: { media: Media; renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; unsupportedMediaPolicy: UnsupportedMediaPolicy; warn?: (msg: string) => void; }) => Promise<ContentBlockParam[]>; renderArtifactHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string; renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string; 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<ToolResultBlockParam>; 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>; renderedToolCallResults: Map<ToolCall, ToolResultBlockParam>; 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?: 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>; systemPrompt: Tokenizable; thoughts: Iterable<Thought>; thoughtSurfacing: "all" | "all-self" | "latest-self"; toolCalls: Iterable<ToolCall>; tools: ToolRegistry; unsupportedMediaPolicy: UnsupportedMediaPolicy; warn?: (msg: string) => void; }-
input.bucketOrderChatCompletionsBucketOrder-
input.cacheBreakpointsAnthropicCacheBreakpoints-
input.cacheTtl?AnthropicCacheTtl-
input.filterThoughts(thoughts: Iterable<Thought>, mode: "all" | "all-self" | "latest-self", selfIdentity: string, replayCompatibility: readonly string[]) => Thought[]-
input.memoriesIterable<Memory>-
input.messagesIterable<Message>-
input.modelstring-
input.renderAnthropicSegmentedSystemPrompt(input: { bucketOrder: ChatCompletionsBucketOrder; cacheBreakpoints: AnthropicCacheBreakpoints; cacheTtl?: AnthropicCacheTtl; memories: Iterable<Memory>; 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; warn?: (msg: string) => void; }) => Promise<TextBlockParam[]>-
input.renderAnthropicThinkingBlocks(input: { model: string; prefixFingerprint: string; replayCompatibility: readonly string[]; thought: Thought; warn?: (msg: string) => void; }) => ContentBlockParam[]-
input.renderAnthropicTimelineMessage(input: { message: Message; renderAnthropicMediaBlocks: (input: { media: Media; renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; unsupportedMediaPolicy: UnsupportedMediaPolicy; warn?: (msg: string) => void; }) => Promise<ContentBlockParam[]>; selfIdentity: string; unsupportedMediaPolicy: UnsupportedMediaPolicy; warn?: (msg: string) => void; }) => Promise<MessageParam | null>-
input.renderAnthropicToolCallResult(input: { renderAnthropicMediaBlocks: (input: { media: Media; renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; unsupportedMediaPolicy: UnsupportedMediaPolicy; warn?: (msg: string) => void; }) => Promise<ContentBlockParam[]>; renderArtifactHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string; renderRetrievableHandleBody?: (input: { artifact: unknown; byteLength: number; callId: string; encoding?: string; estimatedTokens?: number; lineCount: number; }) => string; 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<ToolResultBlockParam>-
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.renderedToolCallResultsMap<ToolCall, ToolResultBlockParam>Pre-rendered results keyed by the live ToolCall instances used during assembly.
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.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.systemPromptTokenizable-
input.thoughtsIterable<Thought>-
input.thoughtSurfacing"all" | "all-self" | "latest-self"-
input.toolCallsIterable<ToolCall>-
input.toolsToolRegistry-
input.unsupportedMediaPolicyUnsupportedMediaPolicy-
input.warn?(msg: string) => void-

Returns

Promise<{ messages: MessageParam[]; system?: string | TextBlockParam[]; tools?: Tool[]; }>