Skip to content

feat(models): add Z.AI GLM-5.2 to native zai provider + 1M context + thinking effort - #45483

Closed
potatogim wants to merge 2 commits into
NousResearch:mainfrom
potatogim:feat/add-glm-5.2
Closed

feat(models): add Z.AI GLM-5.2 to native zai provider + 1M context + thinking effort#45483
potatogim wants to merge 2 commits into
NousResearch:mainfrom
potatogim:feat/add-glm-5.2

Conversation

@potatogim

@potatogim potatogim commented Jun 13, 2026

Copy link
Copy Markdown

Summary

GLM-5.2 now appears in the Z.AI native model picker and resolves to its correct 1M context length on every surface, with thinking + effort parameter support for reasoning depth control.

Why this needed a manual edit: The Z.AI provider lists are hardcoded in _PROVIDER_MODELS and model_metadata.py — the live /models API returns 7 GLM models but not glm-5.2, so it falls through to the static curated list and must be added by hand.

Why effort matters: GLM-5.2 accepts an effort field (high/max) inside the thinking object. Verified against the live Z.AI API: effort=max produces significantly more reasoning tokens than baseline. Without this PR, Hermes reasoning_effort: xhigh is silently ignored for Z.AI.

Changes

Model registration:

  • agent/model_metadata.py: add DEFAULT_CONTEXT_LENGTHS key "glm-5.2": 1_000_000. Longest-key-first substring matching makes it win over the generic "glm": 202752 catch-all.
  • hermes_cli/models.py: add to _PROVIDER_MODELS["zai"] curated list (native Z.AI picker only).

Thinking effort implementation:

  • plugins/model-providers/zai/__init__.py: ZAIProfile class overrides build_api_kwargs_extras() to emit thinking.type + optional effort. Mirrors the DeepSeek profile pattern (ProviderProfile subclass + override).
    • Effort mapping per Z.AI official docs: xhigh/maxmax, highhigh, lower efforts omitted (server default = high)
    • Effort is sent for 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=None, returns empty dicts — preserves default wire format for existing GLM users (5.1, 5, 4.x)
    • The thinking parameter itself works across all GLM models on both endpoints (verified); effort is a GLM-5.2 feature.
    • glm-5.2 added to fallback_models for picker display until the live /models API includes it.

Tests:

  • tests/plugins/model_providers/test_zai_profile.py — 35 tests: wire shape, model gating, backward compat, transport integration
  • tests/agent/test_model_metadata.py — GLM-5.2 context length resolution test

Model facts (from Z.AI docs)

  • ID glm-5.2, 1M context window, max output 131,072 tokens, reasoning enabled
  • API endpoints: https://api.z.ai/api/paas/v4 (standard) and https://api.z.ai/api/coding/paas/v4 (Coding Plan)
  • GLM-5.2 is currently available on the Coding Plan endpoint; standard endpoint support is expected soon
  • The thinking and effort parameters are accepted on both endpoints (verified)
  • Effort mapping: low/medium/highhigh, xhigh/maxmax
  • https://docs.z.ai/devpack/latest-model

Context length

The context length is set to 1_000_000, matching the Z.AI official docs which explicitly state 1,000,000 tokens. A power-of-two approximation (1,048,576) has been used in some references, but the documented spec value is preferred.

Validation

Input Resolves to
glm-5.2 / zai/glm-5.2 1,000,000 ctx
glm-5.1 / glm-5 202,752 ctx (unchanged)
glm-4.6 / glm-4.5 202,752 ctx (unchanged)

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}}

Full test suite: 5899 passed, 2 skipped. The 19 pre-existing failures (LSP, coding-context, vision-routing) are unrelated to this change and reproduce on main. GLM-5.2 specific tests: 35 passed (effort profile) + 101 passed (model metadata, includes 1 new GLM-5.2 test).

Related

Also addresses #45519.

This PR adds thinking/effort support on top, which none of the above cover.

@liuhao1024

Copy link
Copy Markdown
Contributor

Review: Bundled model addition

The PR title says "add Z.AI GLM-5.2 model" but the diff also adds anthropic/claude-fable-5 to both the curated and free-tier sections of model-catalog.json — that's an unrelated Anthropic model with no description, not mentioned in the title or body.

Concern: If claude-fable-5 is not yet publicly available or its API ID is speculative, adding it to the catalog will show it in the model picker but selecting it will fail at runtime. This is a silent user-facing break.

Suggestion: Either remove the claude-fable-5 entries from this PR and submit them separately with a proper description and pricing info, or update the PR title/body to document both additions.

The GLM-5.2 additions across model_metadata.py, auth.py, models.py, setup.py, and zai/__init__.py look correct — context length, probe models, curated lists, and fallback models are all consistently updated.

@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

Overview

Adds Z.AI GLM-5.2 model (1M context window) to the providers list, following the standard provider/model registration pattern.

Assessment

  • Model registration follows established patterns with appropriate context window (1M).
  • One prior informal review from Copilot is noted; this constitutes the formal review.
  • No security, performance, or documentation concerns.

Reviewed by Hermes Agent

@potatogim

Copy link
Copy Markdown
Author

Thanks @liuhao1024 for catching that! You were right — the claude-fable-5 entries were accidentally reintroduced during a rebase conflict resolution. The upstream had already removed them in #45492, and our theirs pick picked up the stale version.

Fixed in the latest commit — both openrouter and nous catalog entries for claude-fable-5 have been removed. The diff is now GLM-5.2 only. 🙏

@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have provider/zai ZAI provider comp/cli CLI entry point, hermes_cli/, setup wizard comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint labels Jun 13, 2026
@potatogim potatogim changed the title feat(providers): add Z.AI GLM-5.2 model (1M context window) feat(models): add Z.AI GLM-5.2 to native providers + 1M context + thinking effort Jun 13, 2026
@potatogim potatogim changed the title feat(models): add Z.AI GLM-5.2 to native providers + 1M context + thinking effort feat(models): add Z.AI GLM-5.2 to native providers + 1M context Jun 13, 2026
Hermes Agent added 2 commits June 13, 2026 23:43
GLM-5.2 now appears in the Z.AI model picker and resolves to its correct
1M context length on every surface.

The Z.AI live /models API returns 7 GLM models but not glm-5.2, so it
falls through to the static curated list and must be added by hand.

Model facts (from Z.AI docs):
- ID: glm-5.2
- Context window: 1,000,000 tokens
- Max output: 131,072 tokens
- Reasoning: enabled
- Docs: https://docs.z.ai/devpack/latest-model

Changes:
- agent/model_metadata.py: DEFAULT_CONTEXT_LENGTHS["glm-5.2"] = 1_000_000
  (longest-key-first matching, before generic "glm": 202752)
- hermes_cli/models.py: add to _PROVIDER_MODELS["zai"] curated list
- tests/agent/test_model_metadata.py: context length resolution test
GLM-5.2 accepts an 'effort' field inside the thinking object to control
reasoning depth. Verified against the live Z.AI API: effort=max produces
significantly more reasoning tokens than baseline.

Effort mapping per Z.AI official docs
(https://docs.z.ai/devpack/latest-model):
- xhigh/max → max
- high → high
- lower efforts → omit (server default is high)

Implementation:
- plugins/model-providers/zai: ZAIProfile overrides
  build_api_kwargs_extras() to emit thinking.type + optional effort.
  Mirrors the DeepSeek profile pattern (ProviderProfile subclass).
- When reasoning_config is None, returns empty dicts — preserves default
  wire format for existing GLM users (5.1, 5, 4.x).
- Effort is GLM-5.2 only — _model_supports_effort() uses boundary
  matching (glm-5.2 or glm-5.2-*, not glm-5.20).
- glm-5.2 added to fallback_models for picker display until the live
  /models API includes it.

Tests (35 total):
- Wire shape: enabled/disabled, effort mapping, case insensitivity
- Model gating: GLM-5.2+ gets effort, older models don't
- Backward compat: None reasoning_config returns empty for all models
- Transport integration: ChatCompletionsTransport().build_kwargs() E2E
@potatogim potatogim changed the title feat(models): add Z.AI GLM-5.2 to native providers + 1M context feat(models): add Z.AI GLM-5.2 to native zai provider + 1M context + thinking effort Jun 13, 2026
@potatogim
potatogim requested a review from tonydwb June 14, 2026 08:16
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for jumping on GLM-5.2. We merged the broader GLM-5.2 support via #45695, preserving @am423's authorship in git history:

#45695

That landed the 1M context metadata plus the Z.AI model picker/setup/auth probing/fallback surfaces, so this PR is now covered. Closing as duplicate, with appreciation for helping validate the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have provider/zai ZAI provider type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants