fix(agent): enable reasoning_content for Z.AI/GLM models - #16592
fix(agent): enable reasoning_content for Z.AI/GLM models#16592vominh1919 wants to merge 1 commit into
Conversation
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
|
Likely duplicate of #11494 — both add preserved thinking support for Z.AI/GLM models via extra_body.thinking parameter injection. |
teknium1
left a comment
There was a problem hiding this comment.
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-888resolveszaito a provider profile, andplugins/model-providers/zai/__init__.py:94-108now emitsextra_body.thinking. run_agent.py:5362-5373still omitsz-ai/from the OpenRouter reasoning gate. Sinceplugins/model-providers/openrouter/__init__.py:122-160emitsreasoningonly 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.reasoningpayload forz-ai/glm-*. - Do not restore the legacy
is_zaitransport branch; direct Z.AI behavior belongs inZaiProfile.
Automated hermes-sweeper review.
| "type": "enabled" if _kimi_thinking_enabled else "disabled", | ||
| } | ||
|
|
||
| # Z.AI (GLM) extra_body.thinking — same format as Kimi |
There was a problem hiding this comment.
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.
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
thinkingparameter (same format as Kimi) to enable reasoning:But Hermes only injected the OpenRouter-style
reasoningextra_body, which Z.AI silently ignores. There was no Z.AI-specific handling in the reasoning pipeline.Fix
Three changes across 2 files:
run_agent.py— Add_is_zaiURL detection forz.aiandopen.bigmodel.cnhosts, passis_zaiflag to transportrun_agent.py— Add"z-ai/"to OpenRouterreasoning_model_prefixesso Z.AI models get reasoning via OpenRouterchat_completions.py— Add Z.AIthinkingextra_body injection, mirroring the existing Kimi patternFiles Changed
run_agent.py— 8 lines added (Z.AI detection + OpenRouter prefix)agent/transports/chat_completions.py— 11 lines added (thinking extra_body)