Repository navigation
feat(dialect): round-trip Chat reasoning_content across dialects - #316
Merged
Merged
Conversation
Thinking decoded from a Chat upstream (`reasoning_content`, or `reasoning` as OpenRouter and vLLM call it) used to carry no signature, so it was dropped when the next turn was encoded for a Chat upstream. DeepSeek requires the reasoning of a tool-calling turn to be sent back on the following requests of that turn, so a Claude Code or Codex conversation with tools against DeepSeek lost its reasoning every turn. Give such thinking a signature of a new vendor, `Vendor::Chat`, with an empty value. It is carried in the client's signature field like the other vendors (`tw1.ch.`), read back on the next turn, and only then written as `reasoning_content` for a Chat upstream. Thinking signed by any other vendor, or unsigned, is still dropped for Chat upstreams: OpenAI's own Chat API rejects unknown message fields. The Chat encoder now merges consecutive assistant messages first. A Responses client sends one item per message, so the reasoning, the text and the tool call of one turn arrived as three assistant messages, and the reasoning-only one was discarded; DeepSeek also wants `reasoning_content` on the same assistant message as `tool_calls`. User messages are left alone so a mid-conversation system turn folded into a user message stays where it was. The Chat stream parser closes a thinking block with that signature, and the non-stream decoders read `reasoning` as well, matching the stream decoder. Chat -> Chat passthrough is untouched; `strip_carried` removes the carried value on the other dialects as it does for any `tw1.` value. The cross-dialect matrix now covers thinking: history signed by each vendor reaches only the upstream that signed it, and whole, streamed and collected responses bring the text and signature back to every client. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Thinking decoded from a Chat upstream (
reasoning_content, orreasoningas OpenRouter and vLLM spell it) now carries a signature of a new vendor,Vendor::Chat(empty value), so it is vendor-tagged like Anthropic / OpenAI / Google thinking.tw1.<tag>.scheme, astw1.ch.(calone is the compaction item's tag). It is read back on the next turn.reasoning_contenton that message. Thinking signed by any other vendor, or unsigned, is still dropped for Chat upstreams and recorded as before — OpenAI's own Chat API rejects unknown message fields.reasoningas well asreasoning_content, matching the stream decoder.reasoning_contenton the same assistant message astool_calls. User messages are not merged (a mid-conversation system turn folded into a user message stays in place; the gateway test for that still passes).strip_carriedstill returnsNonefor Chat clients); on the other dialectstw1.ch.is stripped on passthrough like every carried value, which is pinned by the existingstrip_carriedtest.Result: a Claude Code (Anthropic) or Codex (Responses) conversation with tools against DeepSeek keeps its reasoning across the tool-calling turns.
Tests
crates/tw-dialect/tests/matrix.rsnow covers thinking for every client × upstream pair:Unit tests: Chat request/response/stream decoding tags the vendor,
reasoningis read, other vendors' thinking is not written to a Chat upstream.Verified
cargo fmt --all -- --checkcargo clippy --workspace --all-targets -- -D warningscargo test -p tw-dialect,cargo test -p tw-gateway, andcargo test --workspace(local proxy unset)New messages
None. No control API / protocol change.
🤖 Generated with Claude Code