mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-09 13:21:42 +00:00
feat(providers): GLM-5.2 native reasoning_effort controls (#58884)
Port from Kilo-Org/kilocode#11555: GLM-5.2 exposes a native reasoning_effort knob with two enabled levels (high / max) on its OpenAI-compatible endpoints. Previously the zai profile (direct Z.AI /api/paas/v4) used the base ProviderProfile and emitted nothing, and the OpenCode Go profile only handled Kimi K2 / DeepSeek — so a user's effort preference for GLM-5.2 was silently dropped on both routes. - zai: ZaiProfile maps effort onto high/max (xhigh/max -> max, lower -> high) - opencode-go: same mapping for GLM-5.2, alongside existing Kimi/DeepSeek - alias spellings recognized (glm-5.2 / glm-5-2 / glm-5p2, vendor-prefixed) - disabled / no effort leaves the server default untouched
This commit is contained in:
parent
ba31699091
commit
a6079dd350
4 changed files with 242 additions and 10 deletions
|
|
@ -122,13 +122,68 @@ class TestOpenCodeGoDeepSeekThinking:
|
|||
assert top_level == {"reasoning_effort": "max"}
|
||||
|
||||
|
||||
class TestOpenCodeGoGLM52Reasoning:
|
||||
"""GLM-5.2 uses its native high/max reasoning_effort knob on OpenCode Go."""
|
||||
|
||||
def test_high_maps_to_high(self, opencode_go_profile):
|
||||
extra_body, top_level = opencode_go_profile.build_api_kwargs_extras(
|
||||
reasoning_config={"enabled": True, "effort": "high"},
|
||||
model="glm-5.2",
|
||||
)
|
||||
assert extra_body == {}
|
||||
assert top_level == {"reasoning_effort": "high"}
|
||||
|
||||
def test_low_and_medium_clamp_up_to_high(self, opencode_go_profile):
|
||||
for effort in ("low", "medium", "minimal"):
|
||||
extra_body, top_level = opencode_go_profile.build_api_kwargs_extras(
|
||||
reasoning_config={"enabled": True, "effort": effort},
|
||||
model="glm-5.2",
|
||||
)
|
||||
assert extra_body == {}
|
||||
assert top_level == {"reasoning_effort": "high"}
|
||||
|
||||
def test_xhigh_and_max_map_to_max(self, opencode_go_profile):
|
||||
for effort in ("xhigh", "max"):
|
||||
extra_body, top_level = opencode_go_profile.build_api_kwargs_extras(
|
||||
reasoning_config={"enabled": True, "effort": effort},
|
||||
model="z-ai/glm-5.2",
|
||||
)
|
||||
assert extra_body == {}
|
||||
assert top_level == {"reasoning_effort": "max"}
|
||||
|
||||
def test_disabled_leaves_server_default(self, opencode_go_profile):
|
||||
extra_body, top_level = opencode_go_profile.build_api_kwargs_extras(
|
||||
reasoning_config={"enabled": False, "effort": "high"},
|
||||
model="glm-5.2",
|
||||
)
|
||||
assert extra_body == {}
|
||||
assert top_level == {}
|
||||
|
||||
def test_no_config_leaves_server_default(self, opencode_go_profile):
|
||||
extra_body, top_level = opencode_go_profile.build_api_kwargs_extras(
|
||||
reasoning_config=None,
|
||||
model="glm-5.2",
|
||||
)
|
||||
assert extra_body == {}
|
||||
assert top_level == {}
|
||||
|
||||
@pytest.mark.parametrize("model", ["glm-5-2", "glm-5p2"])
|
||||
def test_alias_spellings_recognized(self, opencode_go_profile, model):
|
||||
extra_body, top_level = opencode_go_profile.build_api_kwargs_extras(
|
||||
reasoning_config={"enabled": True, "effort": "max"},
|
||||
model=model,
|
||||
)
|
||||
assert top_level == {"reasoning_effort": "max"}
|
||||
|
||||
|
||||
class TestOpenCodeGoModelGating:
|
||||
"""Other OpenCode Go models must not receive Kimi/DeepSeek controls."""
|
||||
"""Other OpenCode Go models must not receive Kimi/DeepSeek/GLM controls."""
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"model",
|
||||
[
|
||||
"glm-5.1",
|
||||
"glm-5",
|
||||
"qwen3.6-plus",
|
||||
"minimax-m2.7",
|
||||
"deepseek-v3.1",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
"""Unit tests for the Z.AI / GLM provider profile's thinking-mode wiring.
|
||||
"""Unit tests for the Z.AI / GLM provider profile's reasoning wiring.
|
||||
|
||||
Z.AI's GLM-4.5-and-later chat models default to thinking-mode ON when the
|
||||
request omits ``thinking``. Before the profile emitted the parameter,
|
||||
|
|
@ -6,6 +6,10 @@ request omits ``thinking``. Before the profile emitted the parameter,
|
|||
Z.AI route — users who turned thinking off kept burning thinking tokens on
|
||||
every turn (the desktop "thinking reverts to medium" report).
|
||||
|
||||
GLM-5.2 additionally exposes a native ``reasoning_effort`` knob with two
|
||||
enabled levels (high / max) on the OpenAI-compatible ``/api/paas/v4``
|
||||
endpoint; the Hermes effort scale is collapsed onto those.
|
||||
|
||||
These tests pin the profile's wire-shape contract so Z.AI requests stay
|
||||
correctly shaped without going live.
|
||||
"""
|
||||
|
|
@ -61,12 +65,102 @@ class TestZaiThinkingWireShape:
|
|||
assert top_level == {}
|
||||
|
||||
def test_no_effort_levels_leak_to_top_level(self, zai_profile):
|
||||
"""GLM has no effort knob — never emit ``reasoning_effort``."""
|
||||
"""Non-5.2 GLM models have no effort knob — never emit
|
||||
``reasoning_effort`` for them (GLM-5.2 is the exception, below)."""
|
||||
for effort in ("minimal", "low", "medium", "high", "xhigh"):
|
||||
_, top_level = zai_profile.build_api_kwargs_extras(
|
||||
reasoning_config={"enabled": True, "effort": effort}, model="glm-5.2"
|
||||
)
|
||||
assert top_level == {}
|
||||
for model in ("glm-5", "glm-5.1", "glm-4.6"):
|
||||
_, top_level = zai_profile.build_api_kwargs_extras(
|
||||
reasoning_config={"enabled": True, "effort": effort}, model=model
|
||||
)
|
||||
assert top_level == {}
|
||||
|
||||
|
||||
class TestZaiGLM52ReasoningEffort:
|
||||
"""GLM-5.2's native ``reasoning_effort`` knob (two enabled levels)."""
|
||||
|
||||
def test_high_maps_to_high(self, zai_profile):
|
||||
extra_body, top_level = zai_profile.build_api_kwargs_extras(
|
||||
reasoning_config={"enabled": True, "effort": "high"},
|
||||
model="glm-5.2",
|
||||
)
|
||||
assert extra_body == {"thinking": {"type": "enabled"}}
|
||||
assert top_level == {"reasoning_effort": "high"}
|
||||
|
||||
@pytest.mark.parametrize("effort", ["low", "medium", "minimal"])
|
||||
def test_lower_efforts_clamp_up_to_high(self, zai_profile, effort):
|
||||
"""GLM-5.2's minimum thinking level is high — lower Hermes levels
|
||||
clamp onto it."""
|
||||
extra_body, top_level = zai_profile.build_api_kwargs_extras(
|
||||
reasoning_config={"enabled": True, "effort": effort},
|
||||
model="glm-5.2",
|
||||
)
|
||||
assert extra_body == {"thinking": {"type": "enabled"}}
|
||||
assert top_level == {"reasoning_effort": "high"}
|
||||
|
||||
@pytest.mark.parametrize("effort", ["xhigh", "max"])
|
||||
def test_strong_efforts_map_to_max(self, zai_profile, effort):
|
||||
extra_body, top_level = zai_profile.build_api_kwargs_extras(
|
||||
reasoning_config={"enabled": True, "effort": effort},
|
||||
model="glm-5.2",
|
||||
)
|
||||
assert extra_body == {"thinking": {"type": "enabled"}}
|
||||
assert top_level == {"reasoning_effort": "max"}
|
||||
|
||||
def test_disabled_sends_no_effort(self, zai_profile):
|
||||
"""Disabled reasoning still sends the thinking-off marker but never
|
||||
an effort level."""
|
||||
extra_body, top_level = zai_profile.build_api_kwargs_extras(
|
||||
reasoning_config={"enabled": False, "effort": "high"},
|
||||
model="glm-5.2",
|
||||
)
|
||||
assert extra_body == {"thinking": {"type": "disabled"}}
|
||||
assert top_level == {}
|
||||
|
||||
def test_no_config_leaves_server_default(self, zai_profile):
|
||||
extra_body, top_level = zai_profile.build_api_kwargs_extras(
|
||||
reasoning_config=None,
|
||||
model="glm-5.2",
|
||||
)
|
||||
assert extra_body == {}
|
||||
assert top_level == {}
|
||||
|
||||
def test_no_effort_sends_no_effort_level(self, zai_profile):
|
||||
"""Enabled but no effort preference → thinking marker only; the
|
||||
server picks its default effort."""
|
||||
extra_body, top_level = zai_profile.build_api_kwargs_extras(
|
||||
reasoning_config={"enabled": True},
|
||||
model="glm-5.2",
|
||||
)
|
||||
assert extra_body == {"thinking": {"type": "enabled"}}
|
||||
assert top_level == {}
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"model",
|
||||
[
|
||||
"z-ai/glm-5.2",
|
||||
"glm-5-2",
|
||||
"glm-5p2",
|
||||
"accounts/fireworks/models/glm-5p2",
|
||||
"zai-org-glm-5-2",
|
||||
],
|
||||
)
|
||||
def test_alias_spellings_recognized(self, zai_profile, model):
|
||||
_, top_level = zai_profile.build_api_kwargs_extras(
|
||||
reasoning_config={"enabled": True, "effort": "max"},
|
||||
model=model,
|
||||
)
|
||||
assert top_level == {"reasoning_effort": "max"}
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"model",
|
||||
["glm-5.1", "glm-5", "glm-4.7", "glm-4-9b", "", None],
|
||||
)
|
||||
def test_non_glm_5_2_models_get_no_effort(self, zai_profile, model):
|
||||
_, top_level = zai_profile.build_api_kwargs_extras(
|
||||
reasoning_config={"enabled": True, "effort": "high"},
|
||||
model=model,
|
||||
)
|
||||
assert top_level == {}
|
||||
|
||||
|
||||
class TestZaiModelGating:
|
||||
|
|
@ -110,7 +204,7 @@ class TestZaiModelGating:
|
|||
|
||||
|
||||
class TestZaiFullKwargsIntegration:
|
||||
"""End-to-end: the transport's full kwargs carry the thinking marker."""
|
||||
"""End-to-end: the transport's full kwargs carry the reasoning wiring."""
|
||||
|
||||
def test_disabled_reaches_the_wire(self, zai_profile):
|
||||
from agent.transports.chat_completions import ChatCompletionsTransport
|
||||
|
|
@ -139,3 +233,18 @@ class TestZaiFullKwargsIntegration:
|
|||
provider_name="zai",
|
||||
)
|
||||
assert "thinking" not in kwargs.get("extra_body", {})
|
||||
|
||||
def test_glm_5_2_effort_reaches_top_level(self, zai_profile):
|
||||
from agent.transports.chat_completions import ChatCompletionsTransport
|
||||
|
||||
kwargs = ChatCompletionsTransport().build_kwargs(
|
||||
model="glm-5.2",
|
||||
messages=[{"role": "user", "content": "ping"}],
|
||||
tools=None,
|
||||
provider_profile=zai_profile,
|
||||
reasoning_config={"enabled": True, "effort": "max"},
|
||||
base_url="https://api.z.ai/api/paas/v4",
|
||||
provider_name="zai",
|
||||
)
|
||||
assert kwargs["reasoning_effort"] == "max"
|
||||
assert kwargs["extra_body"]["thinking"] == {"type": "enabled"}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue