Extended Thinking
Extended thinking exposes the model’s step-by-step reasoning as structuredthinking_blocks. Unlike the plain-text reasoning_content field, thinking blocks carry cryptographic signatures — required to continue a reasoning chain across multiple turns.
Provider Support
Response Fields
On OpenAI and Azure OpenAI the reasoning is returned encrypted, so blocks carry
{type: "reasoning", id, encrypted_content} instead of thinking and signature. Everything below — echoing the assistant message back, keeping blocks alongside tool_calls — works the same for both shapes.Basic Usage
Streaming
Use the helper below to accumulate a stream intocontent, thinking_blocks, and tool_calls — ready to pass directly into the next turn.
Multi-Turn Conversations
Usemodel_dump(exclude_none=True) on the assistant message — it captures content, tool_calls, and thinking_blocks in one shot, so you don’t need to construct the dict manually.
Multi-Turn with Tool Calls
When thinking is enabled, Anthropic and Bedrock require the assistant message to includethinking_blocks alongside tool_calls. Use model_dump(exclude_none=True) — it captures both in one step.