From ae4ddca9f429d2e92aebc3cc22dd2bd218a847bd Mon Sep 17 00:00:00 2001 From: vominh1919 Date: Mon, 27 Apr 2026 21:26:31 +0700 Subject: [PATCH] fix(agent): enable reasoning_content for Z.AI/GLM models 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/hermes-agent#16533 --- agent/transports/chat_completions.py | 11 +++++++++++ run_agent.py | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/agent/transports/chat_completions.py b/agent/transports/chat_completions.py index 34d5caa88a96..72bb987b3232 100644 --- a/agent/transports/chat_completions.py +++ b/agent/transports/chat_completions.py @@ -188,6 +188,7 @@ def build_kwargs( anthropic_max_out = params.get("anthropic_max_output") is_nvidia_nim = params.get("is_nvidia_nim", False) is_kimi = params.get("is_kimi", False) + is_zai = params.get("is_zai", False) reasoning_config = params.get("reasoning_config") if ephemeral is not None and max_tokens_fn: @@ -240,6 +241,16 @@ def build_kwargs( "type": "enabled" if _kimi_thinking_enabled else "disabled", } + # Z.AI (GLM) extra_body.thinking — same format as Kimi + if is_zai: + _zai_thinking_enabled = True + if reasoning_config and isinstance(reasoning_config, dict): + if reasoning_config.get("enabled") is False: + _zai_thinking_enabled = False + extra_body["thinking"] = { + "type": "enabled" if _zai_thinking_enabled else "disabled", + } + # Reasoning if params.get("supports_reasoning", False): if is_github_models: diff --git a/run_agent.py b/run_agent.py index 8c5c79bb14e3..8eaaf1f748bc 100644 --- a/run_agent.py +++ b/run_agent.py @@ -7721,6 +7721,10 @@ def _build_api_kwargs(self, api_messages: list) -> dict: or base_url_host_matches(self.base_url, "moonshot.ai") or base_url_host_matches(self.base_url, "moonshot.cn") ) + _is_zai = ( + base_url_host_matches(self._base_url_lower, "z.ai") + or base_url_host_matches(self._base_url_lower, "open.bigmodel.cn") + ) # Temperature: _fixed_temperature_for_model may return OMIT_TEMPERATURE # sentinel (temperature omitted entirely), a numeric override, or None. @@ -7792,6 +7796,7 @@ def _build_api_kwargs(self, api_messages: list) -> dict: is_github_models=_is_gh, is_nvidia_nim=_is_nvidia, is_kimi=_is_kimi, + is_zai=_is_zai, is_custom_provider=self.provider == "custom", ollama_num_ctx=self._ollama_num_ctx, provider_preferences=_prefs or None, @@ -7837,6 +7842,7 @@ def _supports_reasoning_extra_body(self) -> bool: "anthropic/", "openai/", "x-ai/", + "z-ai/", "google/gemini-2", "qwen/qwen3", )