Skip to main content

ReasoningState

Struct ReasoningState 

Source
pub struct ReasoningState { /* private fields */ }
Expand description

Reasoning state that a provider requires to be handed back unmodified.

Current models do not treat their own reasoning as throwaway. Anthropic requires thinking blocks to be replayed “complete and unmodified” across a tool-use turn, OpenAI’s stateless flow needs the encrypted reasoning item echoed back into the next request, and Gemini attaches a thought signature to each function call. Dropping any of them degrades multi-turn tool use quietly: the model loses the reasoning that produced the very call it is being handed a result for.

The payload is provider-encoded and deliberately opaque. Core never parses it, and neither should anything else — the encoding belongs to the provider, the meaning belongs to the provider, and the only correct operation is to give it back. Encoding the whole block rather than its parts is what lets one type carry Anthropic’s thinking and redacted_thinking blocks, whose shapes differ, without core knowing either.

§Provider tagging

State is tied to the model that produced it. Anthropic documents that thinking blocks must be stripped when switching models, and cross-provider replay is at best ignored and at worst rejected. Every value therefore records its origin, and providers read it back with payload_for rather than trusting whatever the conversation happens to carry.

Implementations§

Source§

impl ReasoningState

Source

pub fn new(provider: impl Into<String>, payload: impl Into<String>) -> Self

Creates reasoning state tagged with the provider that produced it.

provider should be the stable short name the provider crate uses for itself ("claude", "openai", "gemini"), and payload its own encoding of the block, which it alone will decode.

Source

pub fn provider(&self) -> &str

The provider that produced this state.

Source

pub fn payload(&self) -> &str

The opaque payload, without checking its origin.

Prefer payload_for when about to put the value on the wire; this accessor is for logging and inspection.

Source

pub fn payload_for(&self, provider: &str) -> Option<&str>

The payload, but only if this state came from provider.

Returns None for foreign state so callers drop it instead of replaying it into an API that cannot verify it.

Trait Implementations§

Source§

impl Clone for ReasoningState

Source§

fn clone(&self) -> ReasoningState

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 ReasoningState

Source§

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

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

impl<'de> Deserialize<'de> for ReasoningState

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 Eq for ReasoningState

Source§

impl PartialEq for ReasoningState

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for ReasoningState

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 ReasoningState

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

Source§

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

Source§

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

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.