Skip to content

fix: drop Groq reasoning_content from assistant history#6065

Merged
Soulter merged 1 commit intoAstrBotDevs:masterfrom
stablegenius49:fix/5946-groq-reasoning-history
Mar 15, 2026
Merged

fix: drop Groq reasoning_content from assistant history#6065
Soulter merged 1 commit intoAstrBotDevs:masterfrom
stablegenius49:fix/5946-groq-reasoning-history

Conversation

@stablegenius49
Copy link
Contributor

@stablegenius49 stablegenius49 commented Mar 11, 2026

Summary

  • strip reasoning_content / reasoning from assistant history before Groq requests
  • keep the existing think-block cleanup from the OpenAI-compatible base provider
  • add regression tests covering OpenAI vs Groq payload conversion behavior

Why

Groq rejects assistant history messages that include reasoning_content, which breaks follow-up turns after prior responses contained reasoning. This keeps the cleaned assistant text while omitting the unsupported field for Groq.

Closes #5946

Summary by Sourcery

调整 Groq 聊天补全(chat completion)请求负载的处理方式:在保留现有 OpenAI 行为的同时,从 assistant 历史消息中剥离不受支持的推理字段,并为两个提供商增加回归测试覆盖。

Bug Fixes:

  • 通过从发出的请求负载中的 assistant 消息里移除 reasoningreasoning_content 字段,防止 Groq 请求失败。

Tests:

  • 添加回归测试,用于验证在负载转换过程中,OpenAI 会保留 assistant 历史中的 reasoning_content 字段,而 Groq 会丢弃推理相关字段。
Original summary in English

Summary by Sourcery

Adjust Groq chat completion payload handling to strip unsupported reasoning fields from assistant history while preserving existing OpenAI behavior and add regression coverage for both providers.

Bug Fixes:

  • Prevent Groq requests from failing by removing reasoning and reasoning_content fields from assistant messages in the outgoing payload.

Tests:

  • Add regression tests verifying OpenAI retains reasoning_content in assistant history while Groq drops reasoning fields during payload conversion.

@auto-assign auto-assign bot requested review from Fridemn and Soulter March 11, 2026 16:50
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 11, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical compatibility issue with the Groq API, which previously rejected assistant history messages containing specific reasoning fields. By proactively removing these unsupported fields, the change ensures seamless follow-up interactions and maintains the integrity of conversational flows when using the Groq provider. The update also includes robust testing to validate the correct behavior across different API providers.

Highlights

  • Groq API Compatibility: Implemented a mechanism to strip reasoning_content and reasoning fields from assistant history messages before sending requests to the Groq API, resolving an issue where Groq would reject such messages.
  • Existing Cleanup Preservation: Ensured that the existing 'think-block' cleanup logic from the OpenAI-compatible base provider remains intact.
  • Regression Tests: Added new regression tests to cover the distinct payload conversion behaviors between OpenAI and Groq providers, specifically regarding the handling of reasoning content.
Changelog
  • astrbot/core/provider/sources/groq_source.py
    • Added a new method _finally_convert_payload to the ProviderGroq class.
    • Implemented logic within _finally_convert_payload to remove reasoning_content and reasoning keys from assistant messages in the payload.
  • tests/test_openai_source.py
    • Imported ProviderGroq for testing purposes.
    • Added a helper function _make_groq_provider to facilitate the creation of Groq provider instances in tests.
    • Introduced test_openai_payload_keeps_reasoning_content_in_assistant_history to verify that OpenAI payloads retain reasoning content.
    • Added test_groq_payload_drops_reasoning_content_from_assistant_history to confirm that Groq payloads correctly remove reasoning content.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗨——我已经审查了你的更改,一切看起来都很棒!


Sourcery 对开源项目是免费的——如果你觉得我们的代码审查有帮助,请考虑分享给更多人 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈来改进后续的代码审查。
Original comment in English

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dosubot dosubot bot added the area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. label Mar 11, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses an issue with Groq rejecting assistant history messages containing reasoning content. The fix is implemented by stripping reasoning_content and reasoning fields from assistant messages before sending requests to Groq. This is achieved by overriding _finally_convert_payload in the ProviderGroq class. The changes include valuable regression tests that verify the new behavior for Groq and ensure the existing behavior for the base OpenAI provider remains unchanged. The overall approach is sound.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Mar 15, 2026
@Soulter Soulter merged commit 64e0183 into AstrBotDevs:master Mar 15, 2026
1 check passed
stevessr pushed a commit to stevessr/AstrBot that referenced this pull request Mar 15, 2026
…6065)

Co-authored-by: Stable Genius <259448942+stablegenius49@users.noreply.github.com>
no-teasy pushed a commit to no-teasy/AstrBot that referenced this pull request Mar 16, 2026
…6065)

Co-authored-by: Stable Genius <259448942+stablegenius49@users.noreply.github.com>
no-teasy pushed a commit to no-teasy/AstrBot that referenced this pull request Mar 16, 2026
…6065)

Co-authored-by: Stable Genius <259448942+stablegenius49@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: groq相关错误,当历史中存在思考部分时,会导致400错误。

2 participants