Skip to main content

ContentPart

Enum ContentPart 

Source
#[non_exhaustive]
pub enum ContentPart { Text { text: String, cache_control: Option<CacheControl>, provider_echoes: Vec<ProviderEchoSnapshot>, }, Image { source: MediaSource, cache_control: Option<CacheControl>, provider_echoes: Vec<ProviderEchoSnapshot>, }, Audio { source: MediaSource, cache_control: Option<CacheControl>, provider_echoes: Vec<ProviderEchoSnapshot>, }, Video { source: MediaSource, cache_control: Option<CacheControl>, provider_echoes: Vec<ProviderEchoSnapshot>, }, Document { source: MediaSource, name: Option<String>, cache_control: Option<CacheControl>, provider_echoes: Vec<ProviderEchoSnapshot>, }, Thinking { text: String, cache_control: Option<CacheControl>, provider_echoes: Vec<ProviderEchoSnapshot>, }, RedactedThinking { provider_echoes: Vec<ProviderEchoSnapshot>, }, Citation { snippet: String, source: CitationSource, cache_control: Option<CacheControl>, provider_echoes: Vec<ProviderEchoSnapshot>, }, ToolUse { id: String, name: String, input: Value, provider_echoes: Vec<ProviderEchoSnapshot>, }, ImageOutput { source: MediaSource, provider_echoes: Vec<ProviderEchoSnapshot>, }, AudioOutput { source: MediaSource, transcript: Option<String>, provider_echoes: Vec<ProviderEchoSnapshot>, }, ToolResult { tool_use_id: String, name: String, content: ToolResultContent, is_error: bool, cache_control: Option<CacheControl>, provider_echoes: Vec<ProviderEchoSnapshot>, }, }
Expand description

One block of content inside a Message.

The enum is #[non_exhaustive] so future variants don’t break user match arms. New modalities or capability blocks land here as additional variants — codecs reach 100% IR coverage by either emitting native wire shape or a LossyEncode warning for each.

Every input-side variant carries an Option<CacheControl> field — operators mark a block as cached and codecs that support per-block caching (Anthropic, Bedrock-on-Anthropic) emit the directive natively. Other codecs emit LossyEncode. The ToolUse variant — the assistant’s outbound call — does not carry caching: the model emits it, there is nothing to cache.

Every variant also carries provider_echoes: Vec<ProviderEchoSnapshot> — vendor-keyed opaque round-trip tokens this part must echo back on the next turn (Gemini 3.x thought_signature, Anthropic signature, OpenAI Responses encrypted_content, …). Defaults to empty. Codecs only read / write entries matching their own Codec::name. See ProviderEchoSnapshot for the cross-vendor design.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Text

Plain UTF-8 text — the primary medium.

Fields

§text: String

The text payload.

§cache_control: Option<CacheControl>

Per-block cache directive.

§provider_echoes: Vec<ProviderEchoSnapshot>

Vendor opaque round-trip tokens (Gemini emits thought_signature on text parts in reasoning turns).

§

Image

An image input.

Fields

§source: MediaSource

Where the image bytes live.

§cache_control: Option<CacheControl>

Per-block cache directive.

§provider_echoes: Vec<ProviderEchoSnapshot>

Vendor opaque round-trip tokens.

§

Audio

An audio input.

Fields

§source: MediaSource

Where the audio bytes live.

§cache_control: Option<CacheControl>

Per-block cache directive.

§provider_echoes: Vec<ProviderEchoSnapshot>

Vendor opaque round-trip tokens.

§

Video

A video input.

Fields

§source: MediaSource

Where the video bytes live.

§cache_control: Option<CacheControl>

Per-block cache directive.

§provider_echoes: Vec<ProviderEchoSnapshot>

Vendor opaque round-trip tokens.

§

Document

A document input (PDF, plain-text file, etc.).

Fields

§source: MediaSource

Where the document bytes live.

§name: Option<String>

Display name shown to the model (e.g. "contract.pdf"). Optional — codecs that require a name supply a stable derivation when absent.

§cache_control: Option<CacheControl>

Per-block cache directive.

§provider_echoes: Vec<ProviderEchoSnapshot>

Vendor opaque round-trip tokens.

§

Thinking

A reasoning / extended-thinking block produced by the assistant before the user-facing reply.

Surfaced as its own variant (rather than mixed with Text) so recipes can show / hide / cache reasoning independently. Order relative to Text parts is preserved — vendors that rely on chain-of-thought integrity (Anthropic thinking, Gemini 3.x thought_signature) require the original block order on follow-up turns.

Vendor opaque tokens (Anthropic signature, Gemini thought_signature, OpenAI Responses reasoning-item encrypted_content) ride on provider_echoes.

Fields

§text: String

The reasoning text.

§cache_control: Option<CacheControl>

Per-block cache directive.

§provider_echoes: Vec<ProviderEchoSnapshot>

Vendor opaque round-trip tokens.

§

RedactedThinking

A reasoning block the safety system flagged for redaction. Carries no harness-readable text — the entire block is an opaque round-trip artifact preserved in provider_echoes.

Emitted by Anthropic Claude 3.7 Sonnet only; Claude 4.x and later do not produce this variant. Codecs that don’t recognise it on encode emit LossyEncode (invariant 6 — the prior silent-drop is replaced by a typed channel).

Fields

§provider_echoes: Vec<ProviderEchoSnapshot>

Vendor opaque round-trip tokens. Anthropic emits { "data": "<base64>" } here under provider key "anthropic-messages".

§

Citation

A grounded citation produced by the assistant — the snippet is the verbatim cited text; source describes provenance.

Fields

§snippet: String

The cited substring as it appears in the assistant’s reply.

§source: CitationSource

Where the snippet came from.

§cache_control: Option<CacheControl>

Per-block cache directive.

§provider_echoes: Vec<ProviderEchoSnapshot>

Vendor opaque round-trip tokens.

§

ToolUse

A tool call emitted by the assistant. The harness dispatches it. Tool calls are model output — they do not carry a cache directive (the model emits each call afresh).

Vendor opaque tokens (Gemini 3.x thought_signature on functionCall parts, OpenAI Responses function_call.id) ride on provider_echoes. Missing the Gemini token on the first functionCall of a step yields HTTP 400 on the next turn — codecs MUST round-trip it.

Fields

§id: String

Stable ID matched against the corresponding ToolResult.

§name: String

Tool name to dispatch (must exist in the active ToolRegistry).

§input: Value

JSON arguments for the tool — must validate against the tool’s input_schema before dispatch.

§provider_echoes: Vec<ProviderEchoSnapshot>

Vendor opaque round-trip tokens.

§

ImageOutput

An image the assistant produced (vendor-managed image generation: OpenAI image_generation_call.result, Gemini inline_data parts on the model output, …). Distinct from Self::Image which is a user-supplied input.

Output blocks have no cache directive — they are produced fresh per turn.

Fields

§source: MediaSource

Where the produced image bytes live. Most vendors return inline base64 (MediaSource::Base64); some return a hosted URL.

§provider_echoes: Vec<ProviderEchoSnapshot>

Vendor opaque round-trip tokens.

§

AudioOutput

Audio the assistant produced (text-to-speech reply). Distinct from Self::Audio which is a user-supplied input.

Fields

§source: MediaSource

Where the produced audio bytes live.

§transcript: Option<String>

Optional textual transcript the vendor returned alongside the audio. Surfaced separately so callers can route transcript text through the operator’s logging channel without re-decoding the audio.

§provider_echoes: Vec<ProviderEchoSnapshot>

Vendor opaque round-trip tokens.

§

ToolResult

The harness’s reply to a previous ToolUse call.

Both tool_use_id and name are carried because providers disagree on which one keys correlation: Anthropic / OpenAI / Bedrock use the id (tool_use_id / tool_call_id / toolUseId), while Gemini’s functionResponse keys by name. Carrying both keeps the IR provider-neutral — codecs use whichever their wire format requires without needing the agent harness to know.

Fields

§tool_use_id: String

The originating ToolUse::id.

§name: String

The originating ToolUse::name. Required for Gemini’s functionResponse wire shape; ignored by codecs that correlate purely by id.

§content: ToolResultContent

Result payload — either a string or structured data.

§is_error: bool

True if the tool reported a failure.

§cache_control: Option<CacheControl>

Per-block cache directive. Tool result blocks often carry the heaviest payloads; caching them across turns is the canonical RAG-cache pattern.

§provider_echoes: Vec<ProviderEchoSnapshot>

Vendor opaque round-trip tokens.

Implementations§

Source§

impl ContentPart

Source

pub fn text(text: impl Into<String>) -> Self

Build a text part from anything string-like.

Source

pub fn image(source: MediaSource) -> Self

Build an image part from a media source.

Source

pub fn audio(source: MediaSource) -> Self

Build an audio part from a media source.

Source

pub fn video(source: MediaSource) -> Self

Build a video part from a media source.

Source

pub fn document(source: MediaSource, name: Option<String>) -> Self

Build a document part from a media source.

Source

pub fn thinking(text: impl Into<String>) -> Self

Build a thinking part with no opaque tokens. Codecs attach vendor opaque tokens via Self::with_provider_echo.

Source

pub fn redacted_thinking() -> Self

Build a redacted-thinking part. Anthropic Claude 3.7 Sonnet emits these for safety-flagged reasoning; the codec attaches the opaque data payload via Self::with_provider_echo.

Source

pub const fn cache_control(&self) -> Option<&CacheControl>

Borrow the cache directive on this part, when any is set. Returns None for assistant-output variants (ToolUse, ImageOutput, AudioOutput, RedactedThinking) — they are produced fresh per turn and have nothing to cache.

Source

pub fn provider_echoes(&self) -> &[ProviderEchoSnapshot]

Borrow this part’s vendor opaque round-trip tokens. Codecs use this to recover their own blob (matched by Codec::name) on the encode side.

Source

pub fn with_cache_control(self, cache: CacheControl) -> Self

Attach (or clear) a cache directive on this part. Returns the value back so callers can chain. No-op on ToolUse / ImageOutput / AudioOutput / RedactedThinking (model output never carries caching) — the directive is silently dropped.

Source

pub fn with_provider_echo(self, echo: ProviderEchoSnapshot) -> Self

Append a vendor opaque round-trip token to this part. Codecs call this on the decode side after extracting the wire-shape signature / encrypted_content / data field. Returns the value back so callers can chain.

Trait Implementations§

Source§

impl Clone for ContentPart

Source§

fn clone(&self) -> ContentPart

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ContentPart

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ContentPart

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for ContentPart

Source§

fn eq(&self, other: &ContentPart) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for ContentPart

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for ContentPart

Source§

impl StructuralPartialEq for ContentPart

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,