Skip to content

feat(zai): support thinking effort for GLM-5.2 - #46446

Closed
potatogim wants to merge 1 commit into
NousResearch:mainfrom
potatogim:feat/zai-glm52-effort
Closed

feat(zai): support thinking effort for GLM-5.2#46446
potatogim wants to merge 1 commit into
NousResearch:mainfrom
potatogim:feat/zai-glm52-effort

Conversation

@potatogim

Copy link
Copy Markdown

What does this PR do?

GLM-5.2 accepts an effort field (high/max) inside the thinking object, per the Z.AI official docs. Without this PR, Hermes reasoning_effort is silently ignored for Z.AI — the configured value never reaches the API.

This adds a ZAIProfile subclass that overrides build_api_kwargs_extras() to emit thinking.type + optional effort, mirroring the DeepSeek profile pattern.

Related Issue

Supersedes the effort portion of #45483 (closed as duplicate after #45695 merged the model registration). GLM-5.2 model registration and context length are already on main via #45695 — this PR adds only the missing effort support.

Type of Change

  • ✨ New feature (non-breaking change that adds functionality)

Changes Made

plugins/model-providers/zai/__init__.py:

  • New ZAIProfile(ProviderProfile) class with build_api_kwargs_extras() override
  • _model_supports_effort() guard — GLM-5.2 only, with boundary matching (glm-5.2 or glm-5.2-*, not glm-5.20)
  • Effort mapping per Z.AI docs:
    • xhigh/maxthinking.effort=max
    • highthinking.effort=high
    • lower efforts (none/minimal/low/medium) → omit (server default = high)
  • When reasoning_config=None, returns empty dicts — preserves default wire format for existing GLM users (5.1, 5, 4.x)

tests/plugins/model_providers/test_zai_profile.py:

  • 35 tests across 4 suites: wire shape, model gating, backward compat, transport integration

How to Test

  1. Configure Z.AI with GLM-5.2: hermes config set model.default glm-5.2 && hermes config set agent.reasoning_effort xhigh
  2. Send a message and verify the API request includes "thinking": {"type": "enabled", "effort": "max"} in extra_body
  3. Run tests: pytest tests/plugins/model_providers/test_zai_profile.py -v — 35 passed

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes
  • I've tested on my platform: Linux 6.18.20-1-lts

Documentation & Housekeeping

  • I've updated relevant documentation (docstrings) — or N/A
  • N/A — no config keys changed
  • N/A — follows existing DeepSeek profile pattern, no architecture change
  • N/A — cross-platform safe (provider profile only)

Validation

Effort wire shape (build_api_kwargs_extras):

Config extra_body
None (no reasoning) {} (preserved default)
{enabled: True, effort: xhigh} {thinking: {type: enabled, effort: max}}
{enabled: True, effort: high} {thinking: {type: enabled, effort: high}}
{enabled: True, effort: medium} {thinking: {type: enabled}}
{enabled: False} {thinking: {type: disabled}}

Effort was verified against the live Z.AI API: effort=max produces ~55% more reasoning tokens than baseline.

Screenshots / Logs

N/A

@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/plugins Plugin system and bundled plugins provider/zai ZAI provider labels Jun 15, 2026

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review Summary

Verdict: Approved

zai provider now supports thinking effort for GLM-5.2 model. Small, focused change (2 files).

Looks Good

  • Well-scoped, clean implementation

Reviewed by Hermes Agent

sebitabravo added a commit to sebitabravo/AgroVoz that referenced this pull request Jun 18, 2026
…hropic

z.ai NO soporta reasoning_effort (Anthropic nativo). Usa formato propio:
  {"thinking": {"type": "enabled", "effort": "max"}}
El CI anterior enviaba reasoning_effort y z.ai lo ignoraba silenciosamente
(cero thinking blocks en los 3 passes). Con este fix deberian aparecer
bloques 🧠 Razonamiento activo en los logs.

Ref: NousResearch/hermes-agent#46446
GLM-5.2 accepts an effort field (high/max) inside the thinking
object per Z.AI official docs. Without this, Hermes reasoning_effort
is silently ignored for Z.AI — the value never reaches the API.

Override build_api_kwargs_extras() in a new ZAIProfile subclass,
mirroring the DeepSeek profile pattern. Effort mapping:

  xhigh/max → thinking.effort=max
  high      → thinking.effort=high
  lower     → omit (server default = high)

Effort is GLM-5.2 only — guarded by _model_supports_effort() with
boundary matching (glm-5.2 or glm-5.2-*, not glm-5.20).

When reasoning_config is None, returns empty dicts to preserve the
default wire format for existing GLM users (5.1, 5, 4.x).

35 tests: wire shape, model gating, backward compat, transport integration.
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the focused Z.AI investigation. This is now implemented on current main; this is an automated hermes-sweeper review.

  • a6079dd3502ee94c47481bc068caeea503045f70 (feat(providers): GLM-5.2 native reasoning_effort controls (#58884)) added GLM-5.2 effort forwarding and is included in v2026.7.7.
  • plugins/model-providers/zai/__init__.py:49-106 recognizes GLM-5.2 aliases and maps configured effort to the native top-level reasoning_effort value.
  • tests/plugins/model_providers/test_zai_profile.py:81-107 and :237-250 cover high/max mapping and the outgoing transport kwargs.
  • The merged implementation also covers OpenCode Go aliases, beyond this PR's direct-Z.AI scope.

@teknium1 teknium1 closed this Jul 14, 2026
@teknium1 teknium1 added sweeper:implemented-on-main Sweeper: behavior already present on current main sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels 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:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:implemented-on-main Sweeper: behavior already present on current main sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants