Skip to main content

AssistantBlock

Enum AssistantBlock 

Source
#[non_exhaustive]
pub enum AssistantBlock { Text { text: String, cache_control: Option<CacheControl>, }, ToolCall { id: String, name: String, args: Value, cache_control: Option<CacheControl>, }, Reasoning { text: String, signature: Option<String>, }, RedactedReasoning { data: String, }, }
Expand description

One block inside a Message::Assistant turn.

Block ordering is preserved on replay because some providers (Anthropic extended thinking) require the original sequence on every subsequent request.

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

Visible model-authored text.

Fields

§text: String

Text content.

§

ToolCall

A tool invocation request from the model. Pair with a UserBlock::ToolResult in the next user turn that matches id to call_id.

Fields

§id: String

Provider-assigned id; mirrors back as call_id on the matching UserBlock::ToolResult.

§name: String

Tool name as registered in the crate::ChatRequest::tools list.

§args: Value

JSON arguments. Adapters serialize this through to the provider verbatim; the engine does not validate the schema.

§

Reasoning

Visible reasoning emitted by the model. signature is provider-issued material that must be replayed verbatim on subsequent turns when tools are involved (Anthropic extended thinking). Providers without a signature concept (e.g. OpenAI reasoning) leave it None.

Reasoning blocks intentionally have no cache_control slot: Anthropic does not accept the field on thinking / redacted_thinking blocks. Place breakpoints on adjacent text or tool blocks instead.

Fields

§text: String

Visible reasoning text.

§signature: Option<String>

Provider signature (Anthropic extended thinking). Replay verbatim on subsequent turns when tools are involved; None for providers without a signature concept.

§

RedactedReasoning

Opaque reasoning block whose content the provider chose to hide. data is verbatim provider material — store it untouched and replay it back when the next request continues a tool-use chain.

Fields

§data: String

Verbatim provider payload; treat as opaque bytes.

Implementations§

Source§

impl AssistantBlock

Source

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

Build an AssistantBlock::Text with no cache breakpoint.

Source

pub fn tool_call( id: impl Into<String>, name: impl Into<String>, args: Value, ) -> Self

Build an AssistantBlock::ToolCall with no cache breakpoint.

Source

pub fn with_cache_control(self, cache_control: Option<CacheControl>) -> Self

Builder-style helper: set or replace the cache breakpoint on this block. No-op for reasoning variants (they do not carry cache breakpoints on the wire).

Source

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

Read the current cache breakpoint. Always None for the reasoning variants (they do not carry breakpoints on the wire).

Trait Implementations§

Source§

impl Clone for AssistantBlock

Source§

fn clone(&self) -> AssistantBlock

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 AssistantBlock

Source§

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

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

impl<'de> Deserialize<'de> for AssistantBlock

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 AssistantBlock

Source§

fn eq(&self, other: &AssistantBlock) -> 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 AssistantBlock

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 StructuralPartialEq for AssistantBlock

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,