Skip to content
7 min read · 1,386 words

Function: buildLiteRtConversationInput()

ts
function buildLiteRtConversationInput(input: {
  audioModalityEnabled?: boolean;
  bucketOrder: ChatCompletionsBucketOrder;
  enableThinking?: boolean;
  filterThoughts: (
    thoughts: Iterable<Thought>,
    mode: "all-self" | "latest-self" | "all",
    selfIdentity: string,
    replayCompatibility: readonly string[],
  ) => Thought[];
  memories: Iterable<Memory>;
  messages: Iterable<Message>;
  renderChatCompletionsSystemPrompt: (input: {
    bucketOrder: ChatCompletionsBucketOrder;
    memories: Iterable<Memory>;
    renderCtx?: unknown;
    renderFirstPartyRetrievables: (
      items: Iterable<{
        attrs: RetrievableAttrs;
        retrievable: Retrievable;
      }>,
    ) => Promise<string>;
    renderMemories: (
      items: Iterable<{
        attrs: MemoryAttrs;
        memory: Memory;
      }>,
    ) => string;
    renderRetrievables: (
      items: Iterable<{
        attrs: RetrievableAttrs;
        retrievable: Retrievable;
      }>,
      deps: {
        renderFirstPartyRetrievables: (
          items: Iterable<{
            attrs: RetrievableAttrs;
            retrievable: Retrievable;
          }>,
        ) => Promise<string>;
        renderRetrievableSafetyDirective: () => string;
        renderThirdPartyPrivateRetrievables: (
          items: Iterable<{
            attrs: RetrievableAttrs;
            retrievable: Retrievable;
          }>,
          deps: {
            renderUntrustedContent: (
              content: string,
              attrs: UntrustedContentAttrs,
            ) => string;
          },
        ) => Promise<string>;
        renderThirdPartyPublicRetrievables: (
          items: Iterable<{
            attrs: RetrievableAttrs;
            retrievable: Retrievable;
          }>,
          deps: {
            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: {
        renderUntrustedContent: (
          content: string,
          attrs: UntrustedContentAttrs,
        ) => string;
      },
    ) => Promise<string>;
    renderThirdPartyPublicRetrievables: (
      items: Iterable<{
        attrs: RetrievableAttrs;
        retrievable: Retrievable;
      }>,
      deps: {
        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, MessageContentItem>;
  renderFirstPartyRetrievables: (
    items: Iterable<{
      attrs: RetrievableAttrs;
      retrievable: Retrievable;
    }>,
  ) => Promise<string>;
  renderMediaToLiteRtContent?: (input: {
    media: Media;
    modalityEnabled: boolean;
    nonce: string;
    renderTrustedContent: (
      content: string,
      attrs: TrustedContentAttrs,
    ) => string;
    renderUntrustedContent: (
      content: string,
      attrs: UntrustedContentAttrs,
    ) => string;
    unsupportedMediaPolicy: UnsupportedMediaPolicy;
    warn?: (msg: string) => void;
  }) => Promise<MessageContentItem[]>;
  renderMemories: (
    items: Iterable<{
      attrs: MemoryAttrs;
      memory: Memory;
    }>,
  ) => string;
  renderRetrievables: (
    items: Iterable<{
      attrs: RetrievableAttrs;
      retrievable: Retrievable;
    }>,
    deps: {
      renderFirstPartyRetrievables: (
        items: Iterable<{
          attrs: RetrievableAttrs;
          retrievable: Retrievable;
        }>,
      ) => Promise<string>;
      renderRetrievableSafetyDirective: () => string;
      renderThirdPartyPrivateRetrievables: (
        items: Iterable<{
          attrs: RetrievableAttrs;
          retrievable: Retrievable;
        }>,
        deps: {
          renderUntrustedContent: (
            content: string,
            attrs: UntrustedContentAttrs,
          ) => string;
        },
      ) => Promise<string>;
      renderThirdPartyPublicRetrievables: (
        items: Iterable<{
          attrs: RetrievableAttrs;
          retrievable: Retrievable;
        }>,
        deps: {
          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: {
      renderUntrustedContent: (
        content: string,
        attrs: UntrustedContentAttrs,
      ) => string;
    },
  ) => Promise<string>;
  renderThirdPartyPublicRetrievables: (
    items: Iterable<{
      attrs: RetrievableAttrs;
      retrievable: Retrievable;
    }>,
    deps: {
      renderUntrustedContent: (
        content: string,
        attrs: UntrustedContentAttrs,
      ) => string;
    },
  ) => Promise<string>;
  renderThought: (
    content: string,
    attrs: ThoughtAttrs,
    payload?: unknown,
  ) => string;
  renderToolsAsPromptText?: (
    tools: readonly (Tool<SpooledArtifact> | ArtifactTool)[],
    deps: {
      descriptionToChatCompletionsJsonSchema: (
        d: DescriptionLike,
      ) => JsonSchema;
    },
  ) => 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-self" | "latest-self" | "all";
  toolCalls: Iterable<ToolCall>;
  toolDelivery?: "prompt" | "native";
  tools: ToolRegistry;
  toolsToLiteRtTools: (
    tools: readonly (Tool<SpooledArtifact> | ArtifactTool)[],
    deps: {
      descriptionToChatCompletionsJsonSchema: (
        d: DescriptionLike,
      ) => JsonSchema;
    },
  ) => Tool[];
  unsupportedMediaPolicy?: UnsupportedMediaPolicy;
  visionModalityEnabled?: boolean;
  warn?: (msg: string) => void;
}): Promise<{
  messages: Message[];
  preface: Preface;
}>;

Defined in: src/batteries/llm/litert_lm/helpers.ts:430

Build the LiteRT conversation input from the ADK dispatch context buckets.

Parameters

ParameterTypeDescription
input{ audioModalityEnabled?: boolean; bucketOrder: ChatCompletionsBucketOrder; enableThinking?: boolean; filterThoughts: (thoughts: Iterable<Thought>, mode: "all-self" | "latest-self" | "all", selfIdentity: string, replayCompatibility: readonly string[]) => Thought[]; memories: Iterable<Memory>; messages: Iterable<Message>; renderChatCompletionsSystemPrompt: (input: { bucketOrder: ChatCompletionsBucketOrder; memories: Iterable<Memory>; renderCtx?: unknown; renderFirstPartyRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>) => Promise<string>; renderMemories: (items: Iterable<{ attrs: MemoryAttrs; memory: Memory; }>) => string; renderRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderFirstPartyRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>) => Promise<string>; renderRetrievableSafetyDirective: () => string; renderThirdPartyPrivateRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { 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: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { 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, MessageContentItem>; renderFirstPartyRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>) => Promise<string>; renderMediaToLiteRtContent?: (input: { media: Media; modalityEnabled: boolean; nonce: string; renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; unsupportedMediaPolicy: UnsupportedMediaPolicy; warn?: (msg: string) => void; }) => Promise<MessageContentItem[]>; renderMemories: (items: Iterable<{ attrs: MemoryAttrs; memory: Memory; }>) => string; renderRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderFirstPartyRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>) => Promise<string>; renderRetrievableSafetyDirective: () => string; renderThirdPartyPrivateRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { 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: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderThought: (content: string, attrs: ThoughtAttrs, payload?: unknown) => string; renderToolsAsPromptText?: (tools: readonly ( | Tool<SpooledArtifact> | ArtifactTool)[], deps: { descriptionToChatCompletionsJsonSchema: (d: DescriptionLike) => JsonSchema; }) => 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-self" | "latest-self" | "all"; toolCalls: Iterable<ToolCall>; toolDelivery?: "prompt" | "native"; tools: ToolRegistry; toolsToLiteRtTools: (tools: readonly ( | Tool<SpooledArtifact> | ArtifactTool)[], deps: { descriptionToChatCompletionsJsonSchema: (d: DescriptionLike) => JsonSchema; }) => Tool[]; unsupportedMediaPolicy?: UnsupportedMediaPolicy; visionModalityEnabled?: boolean; warn?: (msg: string) => void; }-
input.audioModalityEnabled?boolean-
input.bucketOrderChatCompletionsBucketOrder-
input.enableThinking?booleanWhether the model's "thinking" mode is enabled. Passed EXPLICITLY into the chat template via preface.extra_context.enable_thinking so the template never decides for itself. Defaults to false.
input.filterThoughts(thoughts: Iterable<Thought>, mode: "all-self" | "latest-self" | "all", selfIdentity: string, replayCompatibility: readonly string[]) => Thought[]-
input.memoriesIterable<Memory>-
input.messagesIterable<Message>-
input.renderChatCompletionsSystemPrompt(input: { bucketOrder: ChatCompletionsBucketOrder; memories: Iterable<Memory>; renderCtx?: unknown; renderFirstPartyRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>) => Promise<string>; renderMemories: (items: Iterable<{ attrs: MemoryAttrs; memory: Memory; }>) => string; renderRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderFirstPartyRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>) => Promise<string>; renderRetrievableSafetyDirective: () => string; renderThirdPartyPrivateRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { 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: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { 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?unknownThe live dispatch context, threaded so DYNAMIC (evaluatable) Tokenizable content resolves against it at assembly via .render(renderCtx). Optional — a static Tokenizable ignores it, and callers outside a dispatch may omit it (the evaluator's no-context fallback applies). Typed loosely (the primitive types the arg as DispatchContext; this battery does not import that contract).
input.renderedToolCallResultsMap<string, MessageContentItem>-
input.renderFirstPartyRetrievables(items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>) => Promise<string>-
input.renderMediaToLiteRtContent?(input: { media: Media; modalityEnabled: boolean; nonce: string; renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; unsupportedMediaPolicy: UnsupportedMediaPolicy; warn?: (msg: string) => void; }) => Promise<MessageContentItem[]>-
input.renderMemories(items: Iterable<{ attrs: MemoryAttrs; memory: Memory; }>) => string-
input.renderRetrievables(items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderFirstPartyRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>) => Promise<string>; renderRetrievableSafetyDirective: () => string; renderThirdPartyPrivateRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { 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: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>-
input.renderThirdPartyPublicRetrievables(items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>-
input.renderThought(content: string, attrs: ThoughtAttrs, payload?: unknown) => string-
input.renderToolsAsPromptText?(tools: readonly ( | Tool<SpooledArtifact> | ArtifactTool)[], deps: { descriptionToChatCompletionsJsonSchema: (d: DescriptionLike) => JsonSchema; }) => 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-self" | "latest-self" | "all"-
input.toolCallsIterable<ToolCall>-
input.toolDelivery?"prompt" | "native"How tool definitions reach the model. 'prompt' (default) renders them as system-prompt text (the portable path — the Gemma-4 .litertlm template throws on native tools); 'native' uses preface.tools (the chat-template path — only for models whose template handles tools).
input.toolsToolRegistry-
input.toolsToLiteRtTools(tools: readonly ( | Tool<SpooledArtifact> | ArtifactTool)[], deps: { descriptionToChatCompletionsJsonSchema: (d: DescriptionLike) => JsonSchema; }) => Tool[]-
input.unsupportedMediaPolicy?UnsupportedMediaPolicy-
input.visionModalityEnabled?boolean-
input.warn?(msg: string) => void-

Returns

Promise<{ messages: Message[]; preface: Preface; }>

Remarks

Maps the ADK history model onto LiteRT's createConversation({ preface }) + per-turn sendMessage(messages) shape:

  • Leading buckets (system prompt + standingInstructions / memories / retrievables before timeline in bucketOrder) → a single preface.messages system message.
  • Toolspreface.tools.
  • Timeline (messages, surviving thoughts, tool calls — chronological) → the messages array sent for this turn, each a LiteRT Message. Thoughts render via the shared renderThought into assistant messages; tool calls render an assistant tool_calls message + a tool role message carrying the pre-rendered tool_response content item.

Returns { preface, messages } for engine.createConversation({ preface }) then conversation.sendMessageStreaming(messages).