feat(zai): wire reasoning_effort for GLM-5.x thinking models - #48004
Closed
kivo360 wants to merge 1 commit into
Closed
feat(zai): wire reasoning_effort for GLM-5.x thinking models#48004kivo360 wants to merge 1 commit into
kivo360 wants to merge 1 commit into
Conversation
GLM-5.x is a reasoning family that emits reasoning_content on every response and accepts a top-level reasoning_effort parameter to control thinking depth (minimal disables it; low/medium/high scale it). The generic transport gate (_supports_reasoning_extra_body) only forwards reasoning params for OpenRouter/Nous/GitHub/LM Studio, so the agent's reasoning_effort config was a no-op for Z.AI — the effort level never reached the wire and the model kept its server default regardless of config. This overrides build_api_kwargs_extras on ZaiProfile to emit reasoning_effort as a top-level API param for GLM-5.x, mirroring the established DeepSeek/Kimi profile pattern. xhigh (a Hermes-internal level with no Z.AI equivalent) is clamped to high. Verified empirically against api.z.ai: minimal=0 reasoning tokens, low/medium/high scale depth as expected, xhigh has no distinct effect.
Contributor
|
Thanks for the provider-profile work. This is now implemented on
The implementation shipped in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
GLM-5.x is a reasoning (thinking) family: every response carries a
reasoning_contentfield alongsidecontent, and Z.AI's API accepts a top-levelreasoning_effortparameter that controls thinking depth (minimaldisables it entirely;low/medium/highscale it).The problem: the agent's
reasoning_effortconfig was a no-op for Z.AI. The generic transport gate (_supports_reasoning_extra_body) only forwards reasoning params for OpenRouter / Nous / GitHub / LM Studio, so the effort level never reached the wire — the model kept its server default regardless of config.The fix: override
build_api_kwargs_extrasonZaiProfileto emitreasoning_effortas a top-level API param for GLM-5.x models. This mirrors the established pattern fromDeepSeekProfile(commitcd9470f41) andKimiProfile— reasoning controls routed through the provider profile, not the legacy transport fallback.Behavior
reasoning_effortsent as top-level paramxhigh→ clamped tohigh(Hermes-internal level with no Z.AI equivalent; empirically yields fewer reasoning tokens thanhigh)enabled: false→ emitsminimal(turns Z.AI thinking off entirely)reasoning_effortEmpirical verification
Tested against
api.z.ai/api/coding/paas/v4/chat/completions— reasoning token counts by effort:minimallowmediumhighxhighTest plan
TestZaiProfile— 7 new tests covering fullVALID_REASONING_EFFORTSrange, disabled state, no-config, and non-reasoning model guardtests/providers/suite passes (118 passed; 1 pre-existing failure intest_bundled_plugins_discoveredunrelated to this change —ai-gatewaymissing__init__.pyon main)ruff checkpasses