Skip to content

fix(agent): enable reasoning_content for Z.AI/GLM models - #16592

Open
vominh1919 wants to merge 1 commit into
NousResearch:mainfrom
vominh1919:fix/zai-reasoning-content
Open

fix(agent): enable reasoning_content for Z.AI/GLM models#16592
vominh1919 wants to merge 1 commit into
NousResearch:mainfrom
vominh1919:fix/zai-reasoning-content

Conversation

@vominh1919

Copy link
Copy Markdown
Contributor

Fixes #16533

Problem

Z.AI/GLM models (glm-5.1, glm-4.7, etc.) never return reasoning_content — even on questions that clearly trigger chain-of-thought when the same model is hit directly via cURL.

Root Cause

Z.AI's API uses the thinking parameter (same format as Kimi) to enable reasoning:

extra_body["thinking"] = {"type": "enabled"}

But Hermes only injected the OpenRouter-style reasoning extra_body, which Z.AI silently ignores. There was no Z.AI-specific handling in the reasoning pipeline.

Fix

Three changes across 2 files:

  1. run_agent.py — Add _is_zai URL detection for z.ai and open.bigmodel.cn hosts, pass is_zai flag to transport
  2. run_agent.py — Add "z-ai/" to OpenRouter reasoning_model_prefixes so Z.AI models get reasoning via OpenRouter
  3. chat_completions.py — Add Z.AI thinking extra_body injection, mirroring the existing Kimi pattern

Files Changed

  • run_agent.py — 8 lines added (Z.AI detection + OpenRouter prefix)
  • agent/transports/chat_completions.py — 11 lines added (thinking extra_body)

Z.AI/GLM models use the thinking parameter (same format as Kimi) to
enable chain-of-thought reasoning. The existing code only injected the
OpenRouter-style reasoning extra_body, which Z.AI silently ignores.

- Add _is_zai URL detection for z.ai and open.bigmodel.cn
- Add is_zai parameter to chat_completions transport
- Add Z.AI thinking extra_body injection (mirrors Kimi pattern)
- Add z-ai/ to OpenRouter reasoning_model_prefixes

Fixes NousResearch#16533
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/zai ZAI provider labels Apr 27, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #11494 — both add preserved thinking support for Z.AI/GLM models via extra_body.thinking parameter injection.

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the focused Z.AI investigation. Current main has already superseded the direct-endpoint portion through the provider-profile path, but the OpenRouter portion remains a narrow candidate for salvage.

Problems

  • The changed direct Z.AI branch is no longer the live registered-provider path: agent/chat_completion_helpers.py:849-888 resolves zai to a provider profile, and plugins/model-providers/zai/__init__.py:94-108 now emits extra_body.thinking.
  • run_agent.py:5362-5373 still omits z-ai/ from the OpenRouter reasoning gate. Since plugins/model-providers/openrouter/__init__.py:122-160 emits reasoning only when that gate is true, this PR's OpenRouter objective is not present on current main.
  • Please add coverage through the current OpenRouter profile/transport path; existing direct-Z.AI coverage is at tests/plugins/model_providers/test_zai_profile.py:209-249.

Suggested changes

  • Retain only the OpenRouter prefix change in the current gate and test the resulting extra_body.reasoning payload for z-ai/glm-*.
  • Do not restore the legacy is_zai transport branch; direct Z.AI behavior belongs in ZaiProfile.

Automated hermes-sweeper review.

"type": "enabled" if _kimi_thinking_enabled else "disabled",
}

# Z.AI (GLM) extra_body.thinking — same format as Kimi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Current main no longer applies registered-provider behavior through this legacy branch: agent/chat_completion_helpers.py:849-888 resolves zai to ZaiProfile, which owns the direct Z.AI wire payload at plugins/model-providers/zai/__init__.py:94-108. Please keep direct Z.AI behavior in that profile rather than add this transport flag.

@teknium1 teknium1 added 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 12, 2026
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 P2 Medium — degraded but workaround exists provider/zai ZAI provider sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/bug Something isn't working

Projects

None yet

3 participants