Map unified `thinking` to `reasoning_effort` for Z.AI GLM and DeepSeek V3.2 on Bedrock
Closes #11467
Why we make these changes
Unified thinking never reached Bedrock for Z.AI GLM and DeepSeek V3.2. Both take Bedrock's reasoning_effort field, so thinking now maps to it. A user-supplied reasoning_effort in bedrock_additional_model_requests_fields also counts as an override and is reported, as it already is for the other Bedrock variants.
New public surface
None.
User-visible behavior
from pydantic_ai import Agent
agent = Agent('bedrock:zai.glm-5', model_settings={'thinking': 'high'})
# before: no reasoning_effort is sent, so thinking='high' has no effect
# after: reasoning_effort='high' is sent
What changes for existing users
Only runs that turn thinking on change. Default and thinking=False runs keep tool output as before.
With thinking on, both models now actually reason, so they get the same output handling as other Bedrock models that think:
- A plain output type falls back to native output for Z.AI GLM (as on
main) and to prompted output for DeepSeek V3.2 (onmainit used tool output). - An explicit
ToolOutputstill works on GLM: the tool is offered withtoolChoice: auto, as onmain, and output retries cover a text answer. On DeepSeek V3.2 it raisesUserErrorpointing toPromptedOutput, as Qwen and GPT-OSS do, since it has no forced tool choice. Onmainit worked, becausethinkingwas ignored. tool_choice='required'raisesUserError, as onmainfor GLM.
GLM keeps the fallback because, in live runs with thinking on, it often answered in text instead of calling the forced output tool: 3 to 6 failures in 10 runs on GLM-4.7, GLM-4.7-flash and GLM-5. Native output failed 1 to 3 times in 10, and with thinking off neither failed.
Verification
- Recorded cassettes for
reasoning_efforton GLM-4.7, GLM-4.7-flash, GLM-5 and DeepSeek V3.2, with thinking on and off: the field reaches Converse and reasoning comes back only when it is on. - GLM-5.3 has no cassette: our account has no access ("eligible customers" only). Its mapping (
Falseandminimalsendlow,Truesendsmax, the model's default) follows the AWS model card and the live error AWS returns forminimal, which listslow/medium/high/xhigh/maxas the accepted values. It is covered bytest_zai_variant. - Unit tests: the thinking mapping per variant, the cross-scope override cases, the output-mode and forced-tool-choice behavior, and the profile resolution snapshots.
PR decisions
2026-10-25 · Bedrock GLM thinking: one 'zai' variant driven by Z.AI profile flags · iter -
- Decision: Single bedrock_thinking_variant='zai'; branch on zai_supports_reasoning_effort; Bedrock overrides zai_reasoning_effort_mapping to {'minimal': 'low'}
- Why: Avoids a behaviour-named 'on_off' public literal and a hardcoded model-name check; reuses Z.AI model facts
- Source: https://github.com/EdAbati/pydantic-ai/tree/bedrock-deepseek-glm-thinking
2026-10-25 · Bedrock GLM-5.3 thinking=True omits reasoning_effort · iter -
- Decision: thinking=True sends no reasoning_effort (model default), documented as a note in thinking.md
- Why: Author's choice; matches Z.AI direct path for the same model
- Source: https://github.com/EdAbati/pydantic-ai/tree/bedrock-deepseek-glm-thinking
2026-10-25 · Bedrock DeepSeek V3.2 unified thinking · iter -
- Decision: Own bedrock_thinking_variant='deepseek' for deepseek.v3.2 (reasoning_effort 'high'/'none' via _HIGH_ONLY_REASONING_EFFORT_MAP shared with GLM-4.7/5); R1 unchanged, sends nothing. Same branch/PR as the GLM work.
- Why: Live probe 2026-10-21: V3.2 on Converse only reasons with reasoning_effort='high', like GLM-4.7/5; vendor-named variant matches the others. R1 rejects any additionalModelRequestFields.
- Source: https://github.com/EdAbati/pydantic-ai/tree/bedrock-deepseek-glm-thinking
2026-10-27 · Z.AI GLM keeps forced tool output while thinking; DeepSeek V3.2 carve-out dropped · iter -
- Decision: Removed _accepts_forced_tool_choice_while_thinking; 'zai' joins 'xai'/'openai_responses' in _thinking_rejects_tool_forcing. DeepSeek V3.2 with thinking falls back to PromptedOutput and refuses explicit ToolOutput.
- Why: Author: Converse accepts forced toolChoice from all GLM models while thinking; GLM-5.3 always calls the tool, older GLM sometimes doesn't, which is a model issue not an API one. DeepSeek V3.2 has no forced toolChoice, so the carve-out only bypassed the guard.
- Source: https://github.com/pydantic/pydantic-ai/pull/11491
2026-11-11 · Z.AI GLM keeps the thinking output fallback · iter -
- Decision: 'zai' left out of the exempt list in _thinking_rejects_tool_forcing, so GLM falls back to NativeOutput while thinking, as on main.
- Why: Live agent runs with thinking on, 10 each: tool output failed 3 (GLM-4.7), 6 (GLM-4.7-flash), 3 (GLM-5); native output failed 3, 3, 1. Raw toolChoice any was honored 0/3 to 2/3 per model. Thinking off: no failures. Native is never worse, so the existing fallback stays.
- Source: https://github.com/pydantic/pydantic-ai/pull/11491
2026-11-11 · Bedrock GLM-5.3 gets its own variant · iter -
- Decision: New bedrock_thinking_variant='zai_effort' with _GLM_EFFORT_REASONING_EFFORT_MAP in models/bedrock.py; 'zai' and 'deepseek' share _HIGH_ONLY_REASONING_EFFORT_MAP. Removed _add_zai_thinking_fields and the ZaiModelProfile override. thinking=True sends 'max'.
- Why: Every other Bedrock variant is one table in models/bedrock.py; reading Z.AI API profile flags coupled Bedrock to Z.AI's rules. An explicit 'max' keeps every table total; the wire result matches the omitted default.
- Source: https://github.com/pydantic/pydantic-ai/pull/11491
2026-11-11 · Explicit ToolOutput allowed for Z.AI GLM while thinking · iter -
- Decision: New _thinking_rejects_output_tools skips 'zai'/'zai_effort'; _thinking_rejects_tool_forcing still picks GLM's default fallback. DeepSeek V3.2 keeps the UserError.
- Why: Converse accepts GLM's output tools while it reasons, so refusing was a regression from main. Live: 12/12 explicit ToolOutput runs on GLM-5, GLM-4.7-flash and GLM-4.7 succeeded with reasoning, 2 after one output retry.
- Source: douwebot review on c4a9a9789a's parent; https://github.com/pydantic/pydantic-ai/pull/11491