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
impl ReasoningState
Sourcepub fn new(provider: impl Into<String>, payload: impl Into<String>) -> Self
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.
Sourcepub fn payload(&self) -> &str
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.
Sourcepub fn payload_for(&self, provider: &str) -> Option<&str>
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
impl Clone for ReasoningState
Source§fn clone(&self) -> ReasoningState
fn clone(&self) -> ReasoningState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more