Skip to content

feat: cross-provider reasoning trace roundtrip#1396

Merged
joshua-mo-143 merged 2 commits into0xPlaygrounds:mainfrom
darinkishore:pr/reasoning-provider-roundtrip
Feb 17, 2026
Merged

feat: cross-provider reasoning trace roundtrip#1396
joshua-mo-143 merged 2 commits into0xPlaygrounds:mainfrom
darinkishore:pr/reasoning-provider-roundtrip

Conversation

@darinkishore
Copy link
Copy Markdown
Contributor

@darinkishore darinkishore commented Feb 13, 2026

Stacked on #1395 — review/merge that first. The diff here includes both PRs; the incremental diff is only the provider-specific changes and integration tests.

Summary

Builds on #1395 to implement full reasoning trace preservation across all providers, ensuring reasoning content survives multi-turn conversations including tool call loops.

  • OpenAI Responses API: Threads msg_ IDs through streaming/non-streaming paths; reverts strip-reasoning workaround; emits MessageId from OutputItemDone; includes reasoning_encrypted_content automatically when reasoning is configured
  • Anthropic: Multi-block ReasoningThinking/RedactedThinking conversion with signature preservation; streaming RedactedThinking support via get_or_insert_with
  • Gemini: thought_signature roundtrip preservation; emits full Reasoning block (not just delta) when signature is present in streaming
  • xAI: Structured Reasoning ↔ Chat Completions reasoning_content conversion with encrypted/redacted mapping; fixes #[serde(rename)]#[serde(rename_all)]
  • OpenRouter: Groups reasoning_details by ID preserving ordering; maps Encrypted/Redacted content types through Chat Completions format
  • Streaming agent loop bug fix: ReasoningDelta events now accumulate in a separate text buffer instead of being converted to unsigned Reasoning blocks — fixes Anthropic 400 "signature required" errors in multi-turn tool call loops

Closes #1147, closes #1146

Integration Tests

Four test suites covering both streaming and non-streaming code paths with per-provider coverage:

Streaming Tests

reasoning_roundtrip.rs (streaming) — Text-only 2-turn streaming conversation:

  • Turn 1: model.stream() → collect reasoning blocks/deltas + text
  • Turn 2: follow-up with reasoning in chat history → provider accepts

reasoning_tool_roundtrip.rs (streaming) — Reasoning + tool call via agent.stream_chat().multi_turn():

  • Agent receives weather prompt → model thinks → calls get_weather tool
  • Agent loop preserves [Reasoning, ToolCall] in chat history
  • Agent sends tool result → model responds with text referencing tool output
  • 11 universal assertions per provider (no errors, tool invoked, reasoning before tool call, etc.)
  • Provider-specific assertions (OpenAI: Encrypted content, Anthropic: signatures)

Non-Streaming Tests

reasoning_roundtrip.rs (non-streaming) — Text-only 2-turn non-streaming conversation:

  • Turn 1: model.completion() → verify CompletionResponse.choice contains Reasoning blocks
  • Turn 2: follow-up with reasoning in chat history → provider accepts
  • Directly inspects reasoning content types in the structured response

reasoning_tool_roundtrip.rs (non-streaming) — Reasoning + tool call via agent.chat():

  • Non-streaming agent loop internally calls model.completion(), preserves reasoning via resp.choice.clone()
  • Verifies: no errors (400 = dropped reasoning), tool invoked, text references tool output
  • 4 universal assertions per provider

Results

Provider Streaming Text Streaming Tool Non-Streaming Text Non-Streaming Tool
OpenAI PASS PASS PASS PASS
Anthropic PASS PASS PASS PASS
Gemini PASS PASS PASS PASS
OpenRouter PASS PASS PASS PASS
xAI

Test plan

  • cargo fmt clean
  • cargo clippy -p rig-core --tests — 0 warnings
  • cargo test -p rig-core --lib — 271 tests pass
  • Streaming reasoning_roundtrip integration tests pass (4/4 providers)
  • Streaming reasoning_tool_roundtrip integration tests pass (4/4 providers)
  • Non-streaming reasoning_roundtrip integration tests pass (4/4 providers)
  • Non-streaming reasoning_tool_roundtrip integration tests pass (4/4 providers)
  • xAI tests pending API key validation with grok-4-0725

Implement lossless reasoning trace preservation for all providers
that require it, enabling multi-turn conversations with reasoning
models (tool call loops, follow-up questions).

Provider changes:
- OpenAI Responses API: encrypted_content roundtrip, msg_ ID threading
- Anthropic: redacted reasoning blocks, multi-block signature preservation
- Gemini: thinking-part thought_signature roundtrip
- xAI: structured reasoning conversion and streaming alignment
- OpenRouter: reasoning_details response parsing and request emission

Includes integration tests for all 5 providers (reasoning_roundtrip.rs).

Implements 0xPlaygrounds#1147, 0xPlaygrounds#1146, 0xPlaygrounds#684
@darinkishore darinkishore force-pushed the pr/reasoning-provider-roundtrip branch from 5a93c3f to 561e102 Compare February 17, 2026 00:44
@joshua-mo-143
Copy link
Copy Markdown
Contributor

Looks like just needs cargo fmt then lgtm

@joshua-mo-143 joshua-mo-143 added this pull request to the merge queue Feb 17, 2026
Merged via the queue into 0xPlaygrounds:main with commit 0977167 Feb 17, 2026
6 checks passed
@github-actions github-actions Bot mentioned this pull request Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Add support for more reasoning types feat: OpenRouter reasoning details

2 participants