pub trait ReasoningCodec: Send + Sync {
// Required methods
fn parse_response(&self, raw: &[Value]) -> Vec<ReasoningItem>;
fn write_assistant(&self, msg: &mut Value, items: &[ReasoningItem]);
}Expand description
Plug-and-play translator between provider-native reasoning shapes
and Clark’s typed ReasoningItem representation.
Per-provider implementations live in their respective StreamFn
modules. The agent loop never knows about provider quirks; it
holds typed items and asks the codec to read/write the wire shape.
Replay contracts are a property of the originating
ReasoningFormat, not the codec — see
ReasoningFormat::replay_contract.
The default OpenRouterReasoningCodec covers every provider that
flows through OpenRouter, since OpenRouter normalizes all upstream
reasoning into the same reasoning_details[] schema.
Required Methods§
Sourcefn parse_response(&self, raw: &[Value]) -> Vec<ReasoningItem>
fn parse_response(&self, raw: &[Value]) -> Vec<ReasoningItem>
Lift OpenRouter-shaped reasoning_details[] (or the native
equivalent) into typed items. Values whose type discriminator
matches no known variant are dropped from the typed view; the
raw Value array is still kept on the assistant message so
round-trip fidelity is preserved on replay.
Sourcefn write_assistant(&self, msg: &mut Value, items: &[ReasoningItem])
fn write_assistant(&self, msg: &mut Value, items: &[ReasoningItem])
Project typed items back into the assistant message body that
will be sent on the next request. The default emits an
reasoning_details array on the assistant message. Providers
with positional contracts (Vertex direct: signature must be
re-attached to the functionCall Part) override.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".