Skip to content

Conversation

@TejasGhatte
Copy link
Collaborator

@TejasGhatte TejasGhatte commented Dec 23, 2025

Summary

Improve handling of reasoning messages in Anthropic provider by emitting them immediately rather than collecting and emitting them at the end.

Changes

  • Modified convertAnthropicContentBlocksToResponsesMessagesGrouped to emit reasoning messages immediately when encountered instead of collecting and emitting them at the end
  • Added proper role assignment to reasoning messages
  • Added signature support for reasoning messages in both directions (Anthropic to Bifrost and Bifrost to Anthropic)
  • Removed the collection of reasoning blocks in a separate array since they're now emitted inline

Type of change

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (Next.js)
  • Docs

How to test

Test the Anthropic provider with models that support reasoning:

# Core/Transports
go version
go test ./core/providers/anthropic/...

Verify that reasoning messages are properly emitted in the correct order and contain the appropriate signature information.

Breaking changes

  • Yes
  • No

Related issues

Improves message handling for Anthropic models with reasoning capabilities.

Security considerations

No security implications.

Checklist

  • I read docs/contributing/README.md and followed the guidelines
  • I added/updated tests where appropriate
  • I updated documentation where needed
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 23, 2025

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Reasoning (thinking) blocks now emit as standalone messages immediately, each with a generated identifier and signature.
  • Refactor

    • Reasoning messages are emitted independently from text/tool content, changing ordering and grouping.
    • Signature preservation for reasoning content has been improved across conversion and delta flows.
    • Removed legacy compatibility pathway that previously combined reasoning with other blocks.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

Thinking/reasoning blocks are emitted immediately as standalone reasoning messages (with generated rs_... IDs) containing a Reasoning content block with Text and Signature. The in-memory batching and the Bedrock compatibility path that combined reasoning with text/tool blocks were removed.

Changes

Cohort / File(s) Summary
Anthropic response processing
core/providers/anthropic/responses.go
Emit Thinking blocks immediately as separate reasoning messages (rs_... IDs) containing a Reasoning content block with Text and Signature. Removed in-memory aggregation and Bedrock compatibility branch that previously emitted combined reasoning blocks. Signature propagation added to reasoning content/deltas and Bifrost→Anthropic conversions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through code with nimble paws,
Reasoning now speaks without a pause,
Signatures snug on every thought,
Messages spring the way they ought,
A rabbit cheers for tidy laws 🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: thought signature handling in anthropic' clearly and specifically describes the main change: improving thought/reasoning signature handling in the Anthropic provider.
Description check ✅ Passed The PR description is comprehensive, covering all major template sections including summary, detailed changes, type of change, affected areas, testing instructions, breaking changes, and checklist completion.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b827d5b and d13d811.

📒 Files selected for processing (1)
  • core/providers/anthropic/responses.go

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

🧪 Test Suite Available

This PR can be tested by a repository admin.

Run tests for PR #1162

Copy link
Collaborator Author

TejasGhatte commented Dec 23, 2025

@TejasGhatte TejasGhatte marked this pull request as ready for review December 23, 2025 07:16
@TejasGhatte TejasGhatte force-pushed the 12-23-fix_thought_signature_handling_in_anthropic branch from c47650d to 46e7fab Compare December 23, 2025 07:17
@TejasGhatte TejasGhatte changed the base branch from main to graphite-base/1162 December 23, 2025 13:19
@TejasGhatte TejasGhatte force-pushed the 12-23-fix_thought_signature_handling_in_anthropic branch from 46e7fab to b827d5b Compare December 23, 2025 13:19
@TejasGhatte TejasGhatte changed the base branch from graphite-base/1162 to 12-23-fix_pass_reasoning_max_tokens_key_to_reasoning_struct_in_chat_compltion_request December 23, 2025 13:19
Copy link
Collaborator

Pratham-Mishra04 commented Dec 23, 2025

Merge activity

  • Dec 23, 4:35 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Dec 23, 4:37 PM UTC: Graphite rebased this pull request as part of a merge.
  • Dec 23, 4:38 PM UTC: @Pratham-Mishra04 merged this pull request with Graphite.

@Pratham-Mishra04 Pratham-Mishra04 changed the base branch from 12-23-fix_pass_reasoning_max_tokens_key_to_reasoning_struct_in_chat_compltion_request to graphite-base/1162 December 23, 2025 16:35
@Pratham-Mishra04 Pratham-Mishra04 changed the base branch from graphite-base/1162 to main December 23, 2025 16:35
@Pratham-Mishra04 Pratham-Mishra04 force-pushed the 12-23-fix_thought_signature_handling_in_anthropic branch from b827d5b to d13d811 Compare December 23, 2025 16:36
@Pratham-Mishra04 Pratham-Mishra04 merged commit 03e5f6a into main Dec 23, 2025
8 of 9 checks passed
@Pratham-Mishra04 Pratham-Mishra04 deleted the 12-23-fix_thought_signature_handling_in_anthropic branch December 23, 2025 16:38
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.

3 participants