Add reasoning content normalization middleware #896
+574
−4
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.


Description
Quick fix for missing reasoning content in GLM 4.7-Flash.
Normalize reasoning from provider-specific fields (reasoning_content, reasoning) into tags in content, and strip them on outbound requests to providers that use separate reasoning fields.
Type of Change
Testing
uv run pytestlocally.Checklist
Note
Medium Risk
Touches core request/response handling and validation for model calls; behavior changes depend on provider response shape and could affect prompts or error handling if detection/stripping misfires.
Overview
Normalizes provider-specific reasoning fields into a consistent
<think>...</think>prefix on inbound chat responses, so models that returnreasoning_content/reasoningno longer drop reasoning.Adds
reasoning_formathandling toEnvironment: strips<think>blocks from outbound assistant messages for providers that expect separate reasoning fields, auto-detects the format from the first response, and relaxes response validation to accept reasoning-only replies. Includes a newreasoning_utilsmodule and comprehensive unit/integration tests covering extraction, normalization, stripping, and provider message prep.Written by Cursor Bugbot for commit fcf95fa. This will update automatically on new commits. Configure here.