Skip to content

fix(bedrock): don't replay reasoning to xAI (Grok) models - #729

Open
umzcio wants to merge 1 commit into
LibreChat-AI:mainfrom
umzcio:fix/bedrock-xai-reasoning-replay
Open

umzcio wants to merge 1 commit into
LibreChat-AI:mainfrom
umzcio:fix/bedrock-xai-reasoning-replay

Conversation

@umzcio

@umzcio umzcio commented Nov 22, 2026

Copy link
Copy Markdown

Fixes #728.

Grok on Bedrock (us.xai.grok-4.7) returns a reasoningContent block with its tool calls, then rejects that block when it is replayed on the next step:

ValidationException: This model doesn't support the reasoningContent.reasoningText.text field for assistant messages.

So every tool loop (web search, MCP, code) fails on its second request. The library already suppresses replay for OpenAI models on Bedrock; this adds xAI to that rule.

Changes

  • utils/message_inputs.ts: factor the ARN and inference-profile parsing out of isBedrockOpenAIModel into bedrockModelId(), add isBedrockXAIModel(), and make replaysBedrockReasoning() return false for OpenAI or xAI. convertToConverseMessages() now uses replaysBedrockReasoning(). Harmony handling stays OpenAI-only.
  • index.ts: the non-streaming path picks the local converter when !replaysBedrockReasoning(model), so xAI gets the same treatment there.
  • reasoning-replay.test.ts: xAI cases for a cross-region profile ID, an inference-profile ARN, and an application inference profile.

Testing

  • Verified against Bedrock in us-west-2 with the same change applied to the built 4.2.7 dist: a real Grok tool loop through CustomChatBedrockConverse failed with the error above before the change and completed after it, including when Grok made parallel tool calls. Converter output for Claude, GPT and Mistral models was unchanged. It has also been running in a LibreChat v0.8.9 deployment, where Grok web search now completes.
  • I haven't run this repo's test suite locally. CI should cover the new test cases.

🤖 Generated with Claude Code

https://claude.ai/code/session_016zWwhp1WwhMm7guDzQPSEc

Grok on Bedrock returns reasoningContent with its tool calls but rejects it when
replayed on the next step ("This model doesn't support the
reasoningContent.reasoningText.text field for assistant messages"), so every tool
loop failed. Treat xAI like OpenAI in replaysBedrockReasoning(), and use that in
convertToConverseMessages() and the non-streaming converter choice.

Fixes LibreChat-AI#728

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016zWwhp1WwhMm7guDzQPSEc
danny-avila pushed a commit that referenced this pull request Nov 23, 2026
Grok 4.7 on Bedrock returns reasoningContent with its tool calls and rejects it when replayed, so every tool loop failed on its second request. Omit the replay on the streaming and non-streaming Converse paths, including named inference profiles and application profiles. Other families, Grok 4.6 and opaque resources keep the existing behavior.

Design credit: umzcio (#729; reported #728).

Co-authored-by: Lia <lia@librechat.ai>

This branch has not been deployed

No deployments
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.

Bedrock: xAI (Grok) models fail on the second step of any tool call because reasoning is replayed

1 participant