[plugins] Anthropic Python: surface extended thinking (extract + stream + signature)
Parent: #5617 (Phase A, P0: items 12, 13, 14)
Why
Extended thinking can be requested, but the reasoning is never given back to the caller. Reasoning blocks are dropped when converting the response (only text and tool_use are mapped) and are never streamed (only text and tool-input deltas are handled). Both JS and Go return reasoning, stream it, and round-trip its signature.
This is the single highest-impact gap in the epic: without it, callers cannot read a model's reasoning, cannot show it as it streams, and cannot continue a reasoning turn. Preserving the signature matters specifically because Anthropic requires it when reasoning is sent back on a later turn; drop it and multi-turn thinking breaks.
This issue covers the response side only; the request-side config modes are tracked separately (item 11, #5629 ). It is independent of the typed config schema, making it the lowest-risk thinking step and immediately testable.
What needs to be done
- Return thinking to callers as reasoning content, both non-streaming and streaming, and stream thinking deltas as they arrive.
- Preserve the Anthropic reasoning signature so it can be sent back on subsequent turns. Use JS naming (
metadata.thoughtSignature) and accept the Go-stylemetadata.signatureas an input alias. - Capture redacted-thinking blocks so they can be round-tripped (full redacted-thinking support is a separate P2 item, 15).
Acceptance
- Reasoning is returned as reasoning parts (non-stream and stream), and thinking deltas are streamed.
- Signatures are preserved and round-trip back to the API on a follow-up turn.
- Tests cover extraction, streaming, and signature round-trip.
Reference
- Current response conversion (extract reasoning here):
py/plugins/anthropic/src/genkit/plugins/anthropic/models.py:421-439; streamingmodels.py:278-351. - Outbound encoding (round-trip the signature here):
_to_anthropic_block/_to_anthropic_messages,models.py:365-419— currently has noReasoningPart→thinkingbranch, so a preserved signature has nowhere to go on a follow-up turn. Signature round-trip is only meaningfully testable live (opaque server value), not in unit tests. - JS/Go return, stream, and round-trip reasoning today.