Files
langchain/libs/core/tests
Nick Hollon 922a000f21 fix(core): preserve reasoning block extras across stream deltas
Anthropic's thinking stream emits a `signature_delta` after the
reasoning text finishes. The adapter surfaces this as a reasoning
delta carrying `extras.signature` (and no new text). Two places
were dropping those fields while assembling the accumulated block:

- `_compat_bridge._accumulate` only concatenated the `reasoning`
  text, silently discarding any other keys (including `extras`) on
  later deltas.
- `chat_model_stream._push_content_block_finish` rebuilt the
  finalized reasoning block as `{"type": "reasoning", "reasoning": ...}`,
  dropping everything the finish event carried.

Together, these stripped Claude's `extras.signature` from the
assembled `AIMessage`, and the next turn in a `create_agent` loop
failed with `messages.<n>.content.<k>.thinking.signature: Field
required`.

The bridge now merges `extras` (so earlier keys survive later
deltas) and replaces other non-text fields; `ChatModelStream`
spreads the incoming finish block before overwriting the two
fields it owns.

Covered by the new
`test_lifecycle_validator_anthropic_reasoning_preserves_signature`
case.
2026-04-21 14:20:59 -04:00
..