Skip to content

feat(zai): wire reasoning_effort for GLM-5.x thinking models - #48004

Closed
kivo360 wants to merge 1 commit into
NousResearch:mainfrom
kivo360:feat/zai-glm5-reasoning-effort
Closed

feat(zai): wire reasoning_effort for GLM-5.x thinking models#48004
kivo360 wants to merge 1 commit into
NousResearch:mainfrom
kivo360:feat/zai-glm5-reasoning-effort

Conversation

@kivo360

@kivo360 kivo360 commented Jun 17, 2026

Copy link
Copy Markdown

Summary

GLM-5.x is a reasoning (thinking) family: every response carries a reasoning_content field alongside content, and Z.AI's API accepts a top-level reasoning_effort parameter that controls thinking depth (minimal disables it entirely; low/medium/high scale it).

The problem: the agent's reasoning_effort config 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_extras on ZaiProfile to emit reasoning_effort as a top-level API param for GLM-5.x models. This mirrors the established pattern from DeepSeekProfile (commit cd9470f41) and KimiProfile — reasoning controls routed through the provider profile, not the legacy transport fallback.

Behavior

  • GLM-5.x + effort setreasoning_effort sent as top-level param
  • xhigh → clamped to high (Hermes-internal level with no Z.AI equivalent; empirically yields fewer reasoning tokens than high)
  • enabled: false → emits minimal (turns Z.AI thinking off entirely)
  • No effort / no config → omits the param so Z.AI applies its server default
  • GLM-4.x (non-reasoning) → untouched, never sends reasoning_effort

Empirical verification

Tested against api.z.ai/api/coding/paas/v4/chat/completions — reasoning token counts by effort:

effort sent reasoning tokens
(none — current behavior) 237
minimal 0 (reasoning off)
low 184
medium 171
high 235
xhigh 173 (no distinct level — clamped to high)

Test plan

  • TestZaiProfile — 7 new tests covering full VALID_REASONING_EFFORTS range, disabled state, no-config, and non-reasoning model guard
  • Full tests/providers/ suite passes (118 passed; 1 pre-existing failure in test_bundled_plugins_discovered unrelated to this change — ai-gateway missing __init__.py on main)
  • ruff check passes
  • End-to-end verified on live Z.AI gateway: agent turns with tools + multi-turn reasoning work cleanly

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.
@alt-glitch alt-glitch added type/feature New feature or request comp/plugins Plugin system and bundled plugins provider/zai ZAI provider P3 Low — cosmetic, nice to have labels Jun 17, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the provider-profile work. This is now implemented on main by a later, more precise GLM-5.2 implementation. This is an automated hermes-sweeper review.

  • a6079dd3502ee94c47481bc068caeea503045f70 (feat(providers): GLM-5.2 native reasoning_effort controls, PR feat(providers): GLM-5.2 native reasoning_effort controls (salvage #51108) #58884) added ZaiProfile reasoning-effort handling.
  • plugins/model-providers/zai/__init__.py:49-106 recognizes GLM-5.2 aliases and sends top-level reasoning_effort with the supported high/max mapping.
  • agent/transports/chat_completions.py:579-592 invokes the profile and merges its top-level kwargs into the live request.
  • tests/plugins/model_providers/test_zai_profile.py:78-163 covers effort mapping, disabled/unset behavior, aliases, and exclusion of non-5.2 models.

The implementation shipped in v2026.7.7.

@teknium1 teknium1 closed this Jul 14, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have provider/zai ZAI provider sweeper:implemented-on-main Sweeper: behavior already present on current main type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants