Skip to main content

Module reasoning

Module reasoning 

Source
Expand description

Provider-agnostic reasoning replay.

Captures provider-native reasoning content from one assistant turn and replays it on the next, in a shape each provider accepts. Mirrors OpenRouter’s reasoning_details[] schema (the broadest typed surface across providers): every item is one of three variants — plain reasoning text (with optional opaque signature), provider-emitted summary, or fully-encrypted blob — tagged with the originating provider’s format discriminator.

Why this exists: providers split on two axes. Where the handle attaches (Gemini binds thoughtSignature to a specific Part; Anthropic binds signature to a thinking content block; OpenAI/xAI carry encrypted_content on a separate reasoning input item) and whether replay is required (Gemini 3 always-with-tools; Anthropic only when next turn carries tool_result; OpenAI when a function call is in the turn; Grok stateless). A flat opaque-bytes abstraction collapses the attachment point and breaks Gemini.

The right shape: typed enum with provider-shaped variants, and the per-provider ReasoningCodec knows how to read each native shape on response and emit each native shape on the next request. The bridge stores the typed enum verbatim; the codec is a stateless translator between typed item and provider wire shape.

Structs§

OpenRouterReasoningCodec
Default codec: reads OpenRouter’s reasoning_details[] schema on response, writes the same on the assistant message for replay. Covers every provider OpenRouter routes to (Anthropic, Google, OpenAI, xAI, Azure, etc.) because OpenRouter normalizes them all to this shape.
ReplayAudit
Diagnostic about a single assistant turn’s reasoning state.

Enums§

ReasoningFormat
Tagged provider source for a reasoning item.
ReasoningItem
One provider-emitted reasoning element.
ReplayContract
Whether this turn’s reasoning items satisfy the next-turn replay contract for the originating provider.
ReplayViolation
A specific way the audited turn would fail upstream on replay.

Traits§

ReasoningCodec
Plug-and-play translator between provider-native reasoning shapes and Clark’s typed ReasoningItem representation.

Functions§

audit_replay
Audit a turn’s reasoning items against the codec’s replay contract.