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

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.

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

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists provider/zai ZAI provider type/bug Something isn't working

Projects

None yet

2 participants