Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix: GLM-5.3 llm思考深度默认配置为low

renquanjia13ac0275a10e
diff --git a/jiuwenswarm/agents/harness/common/rails/model_routing/model_routing_rail.py b/jiuwenswarm/agents/harness/common/rails/model_routing/model_routing_rail.py
index 2230fe8493..f17cf557ff 100644
--- a/jiuwenswarm/agents/harness/common/rails/model_routing/model_routing_rail.py
+++ b/jiuwenswarm/agents/harness/common/rails/model_routing/model_routing_rail.py
@@ -1,6 +1,5 @@
"""model_routing.rail — ModelRoutingRail."""
from __future__ import annotations
-from copy import deepcopy
from dataclasses import asdict
from datetime import datetime, timezone
from typing import Any, Optional
@@ -39,15 +38,13 @@ _MODE_THINKING_MAP: dict[str, str] = MODE_THINKING_MAP
# 四档查找优先命中此标,避免撞到用户自定义的同名模型;无标则退回第一个同名。
_MODE_PREFERRED_PROVIDER = MODE_PREFERRED_PROVIDER
-# 思考深度 → 直接注入的 llm_call_kwargs(不经 vendor 白名单 / 语义适配层,短路)。
-# off → extra_body.thinking.type=disabled(DeepSeek/GLM 通用“关闭思考”)
-# medium → extra_body.thinking.type=enabled(开启思考,默认深度)
-# deep → extra_body.thinking.type=enabled + reasoning_effort=high(思考开到最高)
-# 核心 allowlist 直接透传 extra_body / reasoning_effort。
-_THINKING_KWARGS: dict[str, dict[str, Any]] = {
- "off": {"extra_body": {"thinking": {"type": "disabled"}}},
- "medium": {"extra_body": {"thinking": {"type": "enabled"}}},
- "deep": {"extra_body": {"thinking": {"type": "enabled"}}, "reasoning_effort": "high"},
+# 四档附带的思考语义 → 产品 depth(再经 vendor_map 按模型族翻译)。
+# 具体模型 / default:仅 GLM-5.3 族自动注入产品默认 depth(当前 low);其余 no-op。
+_GEAR_THINKING_TO_DEPTH: dict[str, str] = {
+ "off": "off",
+ "medium": "medium",
+ "deep": "high",
+ "default": "default",
}
@@ -219,26 +216,42 @@ class ModelRoutingRail(DeepAgentRail):
logger.warning("[ModelRouting] before_invoke failed: %s", exc, exc_info=True)
async def before_model_call(self, ctx: AgentCallbackContext) -> None:
- """按请求档位直接注入思考深度(fast=off / balanced=medium / extreme=deep / auto=medium)。
+ """按请求档位 / 模型族注入思考参数(经 vendor_map)。
- 具体模型(skip 分支)时 ``_request_thinking`` 保持 default,本方法 no-op。
- 直接写 ``ctx.extra["llm_call_kwargs"]``,由 ReActAgent 每次 model call 消费
- (pop 后合入调用 kwargs)。不经 vendor 白名单:off 用 DeepSeek/GLM 通用的
- ``extra_body.thinking.type=disabled``,medium 用 ``thinking.type=enabled``,
- deep 用 ``thinking.type=enabled`` + ``reasoning_effort=high``(核心 allowlist 直接透传)。
+ - 四档:fast=off / balanced|auto=medium / extreme=deep→high
+ - 具体模型:``_request_thinking=default`` → 仅 GLM-5.3 族注入产品默认 depth(low)
+ 写 ``ctx.extra["llm_call_kwargs"]``,由 ReActAgent 每次 model call 消费。
+ 不支持思考控制的模型:adapt 降级为空 kwargs,本方法不写入。
"""
- kwargs = _THINKING_KWARGS.get(self._request_thinking)
- if kwargs is None:
- return
+ from jiuwenswarm.common.thinking.adapter import adapt_thinking
+ from jiuwenswarm.common.thinking.types import thaw_llm_call_kwargs
+
+ depth = _GEAR_THINKING_TO_DEPTH.get(
+ self._request_thinking, self._request_thinking or "default"
+ )
+ model_name = _agent_model_name(ctx)
+ used_cap = None
+ extra_probe = getattr(ctx, "extra", None)
+ if isinstance(extra_probe, dict):
+ used_cap = extra_probe.get("_model_routing_used_cap")
+ if used_cap is not None:
+ cap_name = getattr(used_cap, "model_name", None)
+ if isinstance(cap_name, str) and cap_name.strip():
+ model_name = cap_name.strip()
try:
+ profile = adapt_thinking(depth, model_name=model_name)
+ if not profile.injected or not profile.llm_call_kwargs:
+ return
extra = getattr(ctx, "extra", None)
if not isinstance(extra, dict):
return
- extra["llm_call_kwargs"] = deepcopy(kwargs)
+ kwargs = thaw_llm_call_kwargs(profile.llm_call_kwargs)
+ extra["llm_call_kwargs"] = kwargs
logger.info(
- "[ModelRouting] thinking inject mode=%s thinking=%s kwargs=%r",
+ "[ModelRouting] thinking inject mode=%s thinking=%s model=%r kwargs=%r",
self._request_mode or "(none)",
- self._request_thinking,
+ profile.thinking,
+ model_name,
kwargs,
)
except Exception as exc:
diff --git a/jiuwenswarm/agents/harness/common/tools/deepresearch/tools.py b/jiuwenswarm/agents/harness/common/tools/deepresearch/tools.py
index d20141dc5d..b9b6c75142 100644
--- a/jiuwenswarm/agents/harness/common/tools/deepresearch/tools.py
+++ b/jiuwenswarm/agents/harness/common/tools/deepresearch/tools.py
@@ -528,9 +528,42 @@ def _build_deepresearch_config(source: dict[str, str]) -> dict[str, str]:
os.environ.get("SEARCH_SERVICE_ALLOW_UNSAFE_URL", "true"),
)
)
+ _attach_deepresearch_thinking_config(config)
return config
+def _attach_deepresearch_thinking_config(config: dict[str, str]) -> None:
+ """Pass auto-default thinking depth into the isolated DeepResearch child.
+
+ SDK defaults to ``llm_thinking_enabled=False`` (injects ``thinking.type=disabled``),
+ which breaks GLM-5.3. Parent resolves vendor-mapped kwargs (currently only
+ GLM-5.3 family on ``default``) and ships them as ``LLM_EXTENSION`` +
+ ``LLM_THINKING_ENABLED`` for the runner to apply.
+ """
+ model_name = str(config.get("LLM_MODEL_NAME", "") or "").strip()
+ if not model_name:
+ return
+ try:
+ from jiuwenswarm.common.thinking.adapter import adapt_thinking
+ from jiuwenswarm.common.thinking.types import thaw_llm_call_kwargs
+ from jiuwenswarm.common.thinking.vendor_map import (
+ llm_call_kwargs_to_extension,
+ )
+ except ImportError:
+ return
+ profile = adapt_thinking("default", model_name=model_name)
+ if not profile.injected or not profile.llm_call_kwargs:
+ return
+ extension = llm_call_kwargs_to_extension(
+ thaw_llm_call_kwargs(profile.llm_call_kwargs)
+ )
+ if not extension:
+ return
+ config["LLM_EXTENSION"] = json.dumps(extension, ensure_ascii=False)
+ # Never ask the SDK to disable thinking when we ship an explicit depth profile.
+ config["LLM_THINKING_ENABLED"] = "true"
+
+
def _build_deepresearch_request_config(
*,
interactive_ask: bool,
@@ -574,15 +607,34 @@ def _build_styled_export_llm_config(
raise ValueError("styled HTML LLM configuration is invalid")
if model_type not in {"openai", "siliconflow"}:
model_type = "openai"
+ # Prefer GLM-5.3 auto-default depth (vendor-mapped). Fall back to disable
+ # when adapt does not inject — never disable GLM-5.3 when it does inject.
+ extension: dict[str, object] = {
+ "extra_body": {"thinking": {"type": "disabled"}},
+ }
+ try:
+ from jiuwenswarm.common.thinking.adapter import adapt_thinking
+ from jiuwenswarm.common.thinking.types import thaw_llm_call_kwargs
+ from jiuwenswarm.common.thinking.vendor_map import (
+ llm_call_kwargs_to_extension,
+ )
+
+ profile = adapt_thinking("default", model_name=model_name)
+ if profile.injected and profile.llm_call_kwargs:
+ mapped = llm_call_kwargs_to_extension(
+ thaw_llm_call_kwargs(profile.llm_call_kwargs)
+ )
+ if mapped:
+ extension = mapped
+ except ImportError:
+ pass
return {
"general": {
"model_name": model_name,
"model_type": model_type,
"base_url": base_url,
"api_key": api_key,
- "extension": {
- "extra_body": {"thinking": {"type": "disabled"}},
- },
+ "extension": extension,
}
}
diff --git a/jiuwenswarm/common/thinking/__init__.py b/jiuwenswarm/common/thinking/__init__.py
index bca88f0e24..6a540674a1 100644
--- a/jiuwenswarm/common/thinking/__init__.py
+++ b/jiuwenswarm/common/thinking/__init__.py
@@ -1,21 +1,24 @@
# Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
-"""Subagent thinking control: semantic thinking → vendor kwargs."""
+"""Thinking control: semantic depth / toggle → vendor kwargs."""
from __future__ import annotations
-from jiuwenswarm.common.thinking.adapter import adapt_thinking
+from jiuwenswarm.common.thinking.adapter import adapt_thinking, resolve_effective_depth
from jiuwenswarm.common.thinking.rail import ThinkingInjectRail
from jiuwenswarm.common.thinking.types import (
THINKING_VALUES,
ThinkingProfile,
normalize_thinking,
)
+from jiuwenswarm.common.thinking.vendor_map import DEFAULT_THINKING_DEPTH
__all__ = [
+ "DEFAULT_THINKING_DEPTH",
"THINKING_VALUES",
"ThinkingInjectRail",
"ThinkingProfile",
"adapt_thinking",
"normalize_thinking",
+ "resolve_effective_depth",
]
diff --git a/jiuwenswarm/common/thinking/adapter.py b/jiuwenswarm/common/thinking/adapter.py
index 09a2359ea4..52cc401a19 100644
--- a/jiuwenswarm/common/thinking/adapter.py
+++ b/jiuwenswarm/common/thinking/adapter.py
@@ -1,6 +1,6 @@
# Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
-"""Adapt semantic thinking (default|off|on) to frozen vendor kwargs."""
+"""Adapt semantic thinking (default|off|on|low|medium|high) to frozen vendor kwargs."""
from __future__ import annotations
@@ -11,9 +11,17 @@ from jiuwenswarm.common.thinking.types import (
freeze_llm_call_kwargs,
normalize_thinking,
)
-from jiuwenswarm.common.thinking.vendor_map import match_vendor_style, style_to_kwargs
+from jiuwenswarm.common.thinking.vendor_map import (
+ DEFAULT_THINKING_DEPTH,
+ depth_to_kwargs,
+ match_vendor_style,
+)
from jiuwenswarm.common.utils import logger
+# Temporary auto-inject style: only GLM-5.3 family maps ``default`` → product depth.
+# Broader default-depth layering is deferred; do not expand this set casually.
+_AUTO_DEFAULT_DEPTH_STYLES = frozenset({"glm53_reasoning_effort"})
+
def _resolve_model_name(model: Any) -> str:
"""Best-effort model name from openjiuwen Model / config objects."""
@@ -35,8 +43,34 @@ def _resolve_model_name(model: Any) -> str:
return ""
-def adapt_thinking(thinking: str | None, model: Any = None, *, model_name: str = "") -> ThinkingProfile:
- """Build a frozen ThinkingProfile for one subagent lifetime.
+def resolve_effective_depth(thinking: str | None) -> tuple[str, bool]:
+ """Normalize thinking; leave ``default`` as ``default``.
+
+ Auto-inject call sites (GLM-5.3) map ``default`` →
+ :data:`DEFAULT_THINKING_DEPTH` inside :func:`adapt_thinking`.
+
+ Returns:
+ (effective_depth, was_invalid)
+ """
+ level, invalid = normalize_thinking(thinking)
+ if invalid:
+ return "default", True
+ return level, False
+
+
+def adapt_thinking(
+ thinking: str | None,
+ model: Any = None,
+ *,
+ model_name: str = "",
+) -> ThinkingProfile:
+ """Build a frozen ThinkingProfile for one call / subagent lifetime.
+
+ ``default`` / empty is a no-op for most models (leave vendor config as-is).
+ Temporary exception: GLM-5.3 family (``glm53_reasoning_effort``, including
+ names like ``glm-5.3-test``) auto-injects :data:`DEFAULT_THINKING_DEPTH`
+ (currently ``low``). Explicit ``off|on|low|medium|high`` still inject for
+ all allowlisted styles.
Never raises: unsupported / invalid → empty kwargs + degraded flag.
Nested kwargs are deep-copied before freeze so later inject mutations
@@ -44,34 +78,40 @@ def adapt_thinking(thinking: str | None, model: Any = None, *, model_name: str =
"""
name = (model_name or "").strip() or _resolve_model_name(model)
try:
- level, invalid = normalize_thinking(thinking)
+ level, invalid = resolve_effective_depth(thinking)
if invalid:
return ThinkingProfile.empty(
- thinking="default",
+ thinking=level,
degraded=True,
reason="invalid_value",
model_name=name,
)
- if level == "default":
- return ThinkingProfile.empty(thinking="default", model_name=name)
style = match_vendor_style(name)
+
+ if level == "default":
+ if style not in _AUTO_DEFAULT_DEPTH_STYLES:
+ return ThinkingProfile.empty(thinking="default", model_name=name)
+ effective = DEFAULT_THINKING_DEPTH
+ else:
+ effective = level
+
if style is None:
logger.info(
- "[Thinking] unsupported model for thinking toggle model=%r thinking=%s",
+ "[Thinking] unsupported model for thinking depth model=%r thinking=%s",
name,
- level,
+ effective,
)
return ThinkingProfile.empty(
- thinking=level,
+ thinking=effective,
degraded=True,
reason="unsupported_model",
model_name=name,
)
- kwargs = style_to_kwargs(style, enabled=(level == "on"))
+ kwargs = depth_to_kwargs(style, effective)
return ThinkingProfile(
- thinking=level,
+ thinking=effective,
llm_call_kwargs=freeze_llm_call_kwargs(kwargs),
injected=True,
degraded=False,
diff --git a/jiuwenswarm/common/thinking/register_hook.py b/jiuwenswarm/common/thinking/register_hook.py
index f14dab2edd..98edeb1e0d 100644
--- a/jiuwenswarm/common/thinking/register_hook.py
+++ b/jiuwenswarm/common/thinking/register_hook.py
@@ -3,8 +3,10 @@
"""Register TaskTool subagent thinking hook with openjiuwen core.
Core TaskTool calls ``apply_subagent_thinking`` after ``create_subagent``.
-When this host hook is registered, semantic ``thinking`` (default|off|on) is
-adapted to vendor kwargs and attached via :class:`ThinkingInjectRail`.
+When this host hook is registered, semantic ``thinking``
+(default|off|on|low|medium|high) is adapted to vendor kwargs and attached via
+:class:`ThinkingInjectRail`. ``default`` is no-op except GLM-5.3 family
+(auto-inject product default depth).
"""
from __future__ import annotations
@@ -19,10 +21,10 @@ _REGISTERED = False
def _on_subagent_thinking(subagent: Any, *, thinking: str, model: Any = None) -> None:
- """Attach ThinkingInjectRail when thinking is explicitly off/on."""
+ """Attach ThinkingInjectRail when vendor-mapped kwargs are available."""
profile = adapt_thinking(thinking, model=model)
if not getattr(profile, "injected", False):
- # default / unsupported / invalid → leave subagent model config as-is
+ # default (non-GLM-5.3) / unsupported / invalid → leave as-is
if getattr(profile, "degraded", False):
logger.info(
"[Thinking] skip inject degraded reason=%s thinking=%r model=%r",
diff --git a/jiuwenswarm/common/thinking/types.py b/jiuwenswarm/common/thinking/types.py
index af0f16509c..0a212b980d 100644
--- a/jiuwenswarm/common/thinking/types.py
+++ b/jiuwenswarm/common/thinking/types.py
@@ -11,8 +11,12 @@ from typing import Any, Mapping
from jiuwenswarm.common.utils import logger
-# Public contract for spawn/fork tool parameter ``thinking``.
-THINKING_VALUES = frozenset({"", "default", "off", "on"})
+# Public contract for spawn/fork / depth parameter ``thinking``.
+# ``default`` is usually a no-op; GLM-5.3 family maps it to
+# :data:`DEFAULT_THINKING_DEPTH` at adapt time (temporary scope).
+# Depth tiers ``low|medium|high`` are product semantics (vendor-mapped).
+# Legacy toggle ``off|on`` remains for subagent / DisableThinkingMixin.
+THINKING_VALUES = frozenset({"", "default", "off", "on", "low", "medium", "high"})
def _deep_freeze(obj: Any) -> Any:
@@ -77,7 +81,7 @@ class ThinkingProfile:
def normalize_thinking(raw: Any) -> tuple[str, bool]:
- """Normalize tool input to default|off|on.
+ """Normalize tool input to default|off|on|low|medium|high.
Returns:
(normalized_value, was_invalid)
@@ -94,7 +98,7 @@ def normalize_thinking(raw: Any) -> tuple[str, bool]:
value = raw.strip().lower()
if value in ("", "default"):
return "default", False
- if value in ("off", "on"):
+ if value in ("off", "on", "low", "medium", "high"):
return value, False
logger.warning(
"[Thinking] invalid thinking=%r; treat as default",
diff --git a/jiuwenswarm/common/thinking/vendor_map.py b/jiuwenswarm/common/thinking/vendor_map.py
index 290d868bec..72303a9a73 100644
--- a/jiuwenswarm/common/thinking/vendor_map.py
+++ b/jiuwenswarm/common/thinking/vendor_map.py
@@ -2,21 +2,44 @@
"""Vendor match table for thinking control (no skill/role knowledge).
-Only explicitly allowlisted model families participate in thinking toggle.
-Currently: GLM-5 / GLM-5.1 / GLM-5.2 / DeepSeek (keyword match, all versions).
+Allowlisted families participate in thinking toggle / depth injection.
+
+Styles:
+- ``glm53_reasoning_effort``: GLM-5.3(始终思考)— 只用 ``reasoning_effort``
+ ``low|high|max``,禁止 ``thinking.type=disabled``。
+- ``extra_body_thinking_type``: GLM-5 / 5.1 / 5.2 / DeepSeek — ``thinking.type``
+ 开关;深度档可附带 ``reasoning_effort``。
+
+Product depth semantics (``low|medium|high``) are mapped per style.
+
+:data:`DEFAULT_THINKING_DEPTH` is the depth used when GLM-5.3 family auto-
+injects on ``default`` (temporary; broader layered defaults TBD). Explicit
+``low|medium|high`` still map for every allowlisted style.
"""
from __future__ import annotations
import re
+from typing import Any
+
+# Depth applied when GLM-5.3 auto-injects on ``default`` / omit.
+# Future: layered config; keep a single module-level knob for now.
+DEFAULT_THINKING_DEPTH = "low"
-# Ordered: first match wins. GLM pattern is intentionally narrow to avoid
-# false positives (e.g. glm-4, glm-50, glm-5.3); DeepSeek is matched by
-# keyword across versions (v3.x / v4 / chat) — non-thinking variants rely
-# on the executor's bare-retry fallback for rejected thinking params.
+# Ordered: first match wins. GLM-5.3 must precede the broader GLM-5 pattern.
_VENDOR_PATTERNS: tuple[tuple[re.Pattern[str], str], ...] = (
(
- re.compile(r"(?:^|[^a-z0-9])glm[-_]?5(?:\.(?:1|2))?(?:$|[^0-9.])", re.IGNORECASE),
+ re.compile(
+ r"(?:^|[^a-z0-9])glm[-_]?5\.3(?:$|[^0-9.])",
+ re.IGNORECASE,
+ ),
+ "glm53_reasoning_effort",
+ ),
+ (
+ re.compile(
+ r"(?:^|[^a-z0-9])glm[-_]?5(?:\.(?:1|2))?(?:$|[^0-9.])",
+ re.IGNORECASE,
+ ),
"extra_body_thinking_type",
),
(
@@ -25,6 +48,15 @@ _VENDOR_PATTERNS: tuple[tuple[re.Pattern[str], str], ...] = (
),
)
+# GLM-5.3 vendor effort levels (no medium literal).
+_GLM53_EFFORT = {
+ "off": "low", # cannot disable — fall back to lightest effort
+ "on": "high",
+ "low": "low",
+ "medium": "high",
+ "high": "max",
+}
+
def match_vendor_style(model_name: str) -> str | None:
"""Return vendor style id for model_name, or None if unsupported."""
@@ -37,15 +69,45 @@ def match_vendor_style(model_name: str) -> str | None:
return None
-def style_to_kwargs(style: str, *, enabled: bool) -> dict:
- """Map vendor style + on/off to physical llm_call_kwargs."""
- if style == "extra_body_thinking_type":
+def depth_to_kwargs(style: str, depth: str) -> dict[str, Any]:
+ """Map vendor style + product depth to physical ``llm_call_kwargs``."""
+ level = (depth or DEFAULT_THINKING_DEPTH).strip().lower()
+ if style == "glm53_reasoning_effort":
+ effort = _GLM53_EFFORT.get(level, "low")
return {
- "extra_body": {
- "thinking": {"type": "enabled" if enabled else "disabled"},
- }
+ "extra_body": {"thinking": {"type": "enabled"}},
+ "reasoning_effort": effort,
+ }
+ if style == "extra_body_thinking_type":
+ if level == "off":
+ return {"extra_body": {"thinking": {"type": "disabled"}}}
+ kwargs: dict[str, Any] = {
+ "extra_body": {"thinking": {"type": "enabled"}},
}
+ if level == "low":
+ kwargs["reasoning_effort"] = "low"
+ elif level == "high":
+ kwargs["reasoning_effort"] = "high"
+ # medium / on → enabled without effort (vendor default depth while on)
+ return kwargs
if style == "extra_body_enable_thinking":
- # Kept for forward-compat / tests; not matched by current allowlist.
- return {"extra_body": {"enable_thinking": bool(enabled)}}
+ # Forward-compat / tests; not matched by current allowlist.
+ return {"extra_body": {"enable_thinking": level != "off"}}
raise ValueError(f"unknown thinking vendor style: {style}")
+
+
+def style_to_kwargs(style: str, *, enabled: bool) -> dict[str, Any]:
+ """Map vendor style + on/off to physical llm_call_kwargs (legacy)."""
+ return depth_to_kwargs(style, "on" if enabled else "off")
+
+
+def llm_call_kwargs_to_extension(kwargs: dict[str, Any] | None) -> dict[str, Any]:
+ """Convert ``llm_call_kwargs`` into DeepResearch / Model ``extension`` shape."""
+ raw = dict(kwargs or {})
+ extension: dict[str, Any] = {}
+ extra_body = raw.get("extra_body")
+ if isinstance(extra_body, dict) and extra_body:
+ extension["extra_body"] = dict(extra_body)
+ if "reasoning_effort" in raw:
+ extension["reasoning_effort"] = raw["reasoning_effort"]
+ return extension
diff --git a/jiuwenswarm/server/runtime/skill_turbo/executor.py b/jiuwenswarm/server/runtime/skill_turbo/executor.py
index 5ccc7e07bf..226f431627 100644
--- a/jiuwenswarm/server/runtime/skill_turbo/executor.py
+++ b/jiuwenswarm/server/runtime/skill_turbo/executor.py
@@ -140,11 +140,11 @@ def resolve_skill_turbo_thinking_kwargs(
) -> dict[str, Any]:
"""Optional thinking inject for SkillTurbo LLM calls.
- ``thinking is None`` → empty dict (no adapt, identical to legacy invoke/stream).
- Unsupported / degraded → empty dict (never abort).
+ ``thinking is None`` → ``default`` (GLM-5.3 family → product depth low;
+ other models → no inject). Unsupported / degraded → empty dict (never abort).
"""
if thinking is None:
- return {}
+ thinking = "default"
from jiuwenswarm.common.thinking.adapter import adapt_thinking
from jiuwenswarm.common.thinking.types import kwargs_digest, thaw_llm_call_kwargs
diff --git a/jiuwenswarm/server/runtime/skill_turbo/plan_node.py b/jiuwenswarm/server/runtime/skill_turbo/plan_node.py
index 1bda200190..664b209e3f 100644
--- a/jiuwenswarm/server/runtime/skill_turbo/plan_node.py
+++ b/jiuwenswarm/server/runtime/skill_turbo/plan_node.py
@@ -608,8 +608,9 @@ class PlanNode(ABC):
class DisableThinkingMixin:
"""窄 seam:挂载节点的 call_llm / stream_llm 强制 thinking=\"off\"。
- 仅 opt-in:业务节点显式多重继承本 Mixin 才会注入;默认 PlanNode 仍
- thinking=None(零注入)。stream_llm_collect 经 stream_llm 透传,无需另覆盖。
+ 仅 opt-in:业务节点显式多重继承本 Mixin 才会强制 ``thinking=\"off\"``;
+ 默认 PlanNode 传 ``thinking=None``,由 Executor 按模型族处理(GLM-5.3 → low)。
+ stream_llm_collect 经 stream_llm 透传,无需另覆盖。
不改 ThinkingInjectRail / config;注入失败由 Executor 跳过或裸重试。
"""
diff --git a/jiuwenswarm/server/runtime/skill_turbo/thinking_seam.py b/jiuwenswarm/server/runtime/skill_turbo/thinking_seam.py
index eda7d9c002..ee11079d34 100644
--- a/jiuwenswarm/server/runtime/skill_turbo/thinking_seam.py
+++ b/jiuwenswarm/server/runtime/skill_turbo/thinking_seam.py
@@ -16,12 +16,12 @@ def resolve_skill_turbo_thinking_kwargs(
) -> dict[str, Any]:
"""Optional thinking inject for SkillTurbo LLM calls.
- ``thinking is None`` → empty dict (no adapt, identical to legacy invoke/stream).
- Allowlisted models → vendor kwargs.
+ ``thinking is None`` → ``default`` (GLM-5.3 family → product depth low;
+ other models → no inject). Explicit off/on/depth → vendor kwargs when allowlisted.
Unsupported / degraded / seam failure → empty dict (never abort).
"""
if thinking is None:
- return {}
+ thinking = "default"
try:
from jiuwenswarm.common.thinking.adapter import adapt_thinking
diff --git a/tests/unit_tests/agents/harness/common/rails/test_model_routing_rail.py b/tests/unit_tests/agents/harness/common/rails/test_model_routing_rail.py
index 9f04ec494a..203212e971 100644
--- a/tests/unit_tests/agents/harness/common/rails/test_model_routing_rail.py
+++ b/tests/unit_tests/agents/harness/common/rails/test_model_routing_rail.py
@@ -10,7 +10,8 @@ Covers the written-down four-tier contract:
auto -> deepseek-v4.1-flash 思考 medium
and the skip branch: a concrete model name / empty selection keeps the
-adapter-applied model and never injects thinking kwargs.
+adapter-applied model; ``default`` thinking is no-op except GLM-5.3 family
+(auto-inject product default depth low).
"""
from __future__ import annotations
@@ -108,7 +109,8 @@ async def test_before_invoke_sets_thinking_per_tier(selection, thinking):
@pytest.mark.asyncio
async def test_before_model_call_injects_off_kwargs():
rail = _rail()
- ctx = _ctx("fast")
+ agent = _FakeAgent("deepseek-v4.1-flash")
+ ctx = _ctx("fast", agent=agent)
await rail.before_invoke(ctx)
await rail.before_model_call(ctx)
assert ctx.extra["llm_call_kwargs"] == {"extra_body": {"thinking": {"type": "disabled"}}}
@@ -117,7 +119,8 @@ async def test_before_model_call_injects_off_kwargs():
@pytest.mark.asyncio
async def test_before_model_call_injects_deep_kwargs():
rail = _rail()
- ctx = _ctx("extreme")
+ agent = _FakeAgent("glm-5.2")
+ ctx = _ctx("extreme", agent=agent)
await rail.before_invoke(ctx)
await rail.before_model_call(ctx)
assert ctx.extra["llm_call_kwargs"] == {
@@ -127,14 +130,15 @@ async def test_before_model_call_injects_deep_kwargs():
@pytest.mark.asyncio
-async def test_injected_kwargs_are_isolated_from_class_constant():
+async def test_injected_kwargs_are_isolated_per_call():
rail = _rail()
- ctx = _ctx("balanced")
+ agent = _FakeAgent("deepseek-v4.1-flash")
+ ctx = _ctx("balanced", agent=agent)
await rail.before_invoke(ctx)
await rail.before_model_call(ctx)
- # Mutating the injected dict must not corrupt the shared _THINKING_KWARGS.
+ # Mutating the injected dict must not affect the next call's kwargs.
ctx.extra["llm_call_kwargs"]["extra_body"]["thinking"]["type"] = "disabled"
- ctx2 = _ctx("balanced")
+ ctx2 = _ctx("balanced", agent=_FakeAgent("deepseek-v4.1-flash"))
await rail.before_invoke(ctx2)
await rail.before_model_call(ctx2)
assert ctx2.extra["llm_call_kwargs"]["extra_body"]["thinking"]["type"] == "enabled"
@@ -144,8 +148,8 @@ async def test_injected_kwargs_are_isolated_from_class_constant():
@pytest.mark.asyncio
[email protected]("selection", ["", "gpt-5.4", "deepseek-v4.1-flash"])
-async def test_concrete_or_empty_selection_skips(selection):
[email protected]("selection", ["", "gpt-5.4"])
+async def test_concrete_unsupported_model_skips_thinking_inject(selection):
rail = _rail()
agent = _FakeAgent("gpt-5.4")
ctx = _ctx(selection, agent=agent)
@@ -158,6 +162,28 @@ async def test_concrete_or_empty_selection_skips(selection):
assert ctx.extra["model_routing_decision"]["analysis"]["category"] == "skipped"
+async def test_concrete_non_glm53_allowlisted_skips_default_inject():
+ rail = _rail()
+ agent = _FakeAgent("deepseek-v4.1-flash")
+ ctx = _ctx("deepseek-v4.1-flash", agent=agent)
+ await rail.before_invoke(ctx)
+ await rail.before_model_call(ctx)
+ assert rail._request_thinking == "default"
+ assert "llm_call_kwargs" not in ctx.extra
+
+
+async def test_concrete_glm53_injects_effort_low():
+ rail = _rail()
+ agent = _FakeAgent("glm-5.3-test")
+ ctx = _ctx("glm-5.3-test", agent=agent)
+ await rail.before_invoke(ctx)
+ await rail.before_model_call(ctx)
+ assert ctx.extra["llm_call_kwargs"]["extra_body"]["thinking"]["type"] == "enabled"
+ assert ctx.extra["llm_call_kwargs"]["reasoning_effort"] == "low"
+
+
# ---- switch branch ---- #
diff --git a/tests/unit_tests/common/test_thinking_adapter.py b/tests/unit_tests/common/test_thinking_adapter.py
index 1d4412826d..2ffaeb416d 100644
--- a/tests/unit_tests/common/test_thinking_adapter.py
+++ b/tests/unit_tests/common/test_thinking_adapter.py
@@ -8,7 +8,12 @@ import pytest
from jiuwenswarm.common.thinking.adapter import adapt_thinking
from jiuwenswarm.common.thinking.types import normalize_thinking
-from jiuwenswarm.common.thinking.vendor_map import match_vendor_style, style_to_kwargs
+from jiuwenswarm.common.thinking.vendor_map import (
+ DEFAULT_THINKING_DEPTH,
+ depth_to_kwargs,
+ match_vendor_style,
+ style_to_kwargs,
+)
class TestNormalizeThinking:
@@ -21,8 +26,13 @@ class TestNormalizeThinking:
assert normalize_thinking("OFF") == ("off", False)
assert normalize_thinking(" On ") == ("on", False)
+ def test_depth_tiers(self):
+ assert normalize_thinking("low") == ("low", False)
+ assert normalize_thinking("MEDIUM") == ("medium", False)
+ assert normalize_thinking("high") == ("high", False)
+
def test_invalid(self):
- value, invalid = normalize_thinking("low")
+ value, invalid = normalize_thinking("xhigh")
assert value == "default"
assert invalid is True
@@ -34,6 +44,11 @@ class TestVendorMap:
assert match_vendor_style("glm-5.2") == "extra_body_thinking_type"
assert match_vendor_style("provider/glm_5.1") == "extra_body_thinking_type"
+ def test_match_glm53_effort_style(self):
+ assert match_vendor_style("glm-5.3") == "glm53_reasoning_effort"
+ assert match_vendor_style("glm-5.3-test") == "glm53_reasoning_effort"
+ assert match_vendor_style("GLM-5.3") == "glm53_reasoning_effort"
+
def test_match_deepseek_family(self):
assert match_vendor_style("DeepSeek-V3.2") == "extra_body_thinking_type"
assert match_vendor_style("deepseek-v3.2") == "extra_body_thinking_type"
@@ -48,32 +63,70 @@ class TestVendorMap:
assert match_vendor_style("qwen3-max") is None
assert match_vendor_style("glm-4") is None
assert match_vendor_style("glm-50") is None
- assert match_vendor_style("glm-5.3") is None
# 词边界:无分隔的前缀拼名不命中
assert match_vendor_style("somedeepseek") is None
assert match_vendor_style("") is None
- def test_style_kwargs(self):
+ def test_style_kwargs_legacy(self):
off = style_to_kwargs("extra_body_thinking_type", enabled=False)
assert off["extra_body"]["thinking"]["type"] == "disabled"
on = style_to_kwargs("extra_body_enable_thinking", enabled=True)
assert on["extra_body"]["enable_thinking"] is True
+ def test_glm53_depth_never_disables(self):
+ off = depth_to_kwargs("glm53_reasoning_effort", "off")
+ assert off["extra_body"]["thinking"]["type"] == "enabled"
+ assert off["reasoning_effort"] == "low"
+ low = depth_to_kwargs("glm53_reasoning_effort", "low")
+ assert low["reasoning_effort"] == "low"
+ medium = depth_to_kwargs("glm53_reasoning_effort", "medium")
+ assert medium["reasoning_effort"] == "high"
+ high = depth_to_kwargs("glm53_reasoning_effort", "high")
+ assert high["reasoning_effort"] == "max"
+
+ def test_thinking_type_low_includes_effort(self):
+ low = depth_to_kwargs("extra_body_thinking_type", "low")
+ assert low["extra_body"]["thinking"]["type"] == "enabled"
+ assert low["reasoning_effort"] == "low"
+
class TestAdaptThinking:
- def test_default_no_inject(self):
+ def test_default_no_inject_for_non_glm53(self):
profile = adapt_thinking("", model_name="glm-5")
assert profile.thinking == "default"
assert profile.injected is False
assert dict(profile.llm_call_kwargs) == {}
assert profile.model_name == "glm-5"
+ deepseek = adapt_thinking("default", model_name="deepseek-v4-flash-0731")
+ assert deepseek.injected is False
+ assert deepseek.thinking == "default"
+
+ def test_default_glm53_uses_effort_low(self):
+ assert DEFAULT_THINKING_DEPTH == "low"
+ profile = adapt_thinking("default", model_name="glm-5.3-test")
+ assert profile.injected is True
+ assert profile.vendor_style == "glm53_reasoning_effort"
+ assert profile.thinking == "low"
+ assert profile.llm_call_kwargs["extra_body"]["thinking"]["type"] == "enabled"
+ assert profile.llm_call_kwargs["reasoning_effort"] == "low"
+
+ bare = adapt_thinking("", model_name="glm-5.3")
+ assert bare.injected is True
+ assert bare.llm_call_kwargs["reasoning_effort"] == "low"
+
def test_off_glm(self):
profile = adapt_thinking("off", model_name="glm-5.1")
assert profile.injected is True
assert profile.degraded is False
assert profile.llm_call_kwargs["extra_body"]["thinking"]["type"] == "disabled"
+ def test_off_glm53_falls_back_to_low(self):
+ profile = adapt_thinking("off", model_name="glm-5.3")
+ assert profile.injected is True
+ assert profile.llm_call_kwargs["extra_body"]["thinking"]["type"] == "enabled"
+ assert profile.llm_call_kwargs["reasoning_effort"] == "low"
+
def test_on_deepseek_v32(self):
profile = adapt_thinking("on", model_name="DeepSeek-V3.2")
assert profile.injected is True
@@ -92,10 +145,11 @@ class TestAdaptThinking:
assert profile.reason == "unsupported_model"
def test_invalid_degraded(self):
- profile = adapt_thinking("high", model_name="glm-5")
+ profile = adapt_thinking("xhigh", model_name="glm-5")
assert profile.thinking == "default"
assert profile.degraded is True
assert profile.reason == "invalid_value"
+ assert profile.injected is False
def test_profile_nested_freeze(self):
profile = adapt_thinking("off", model_name="glm-5")
diff --git a/tests/unit_tests/common/test_thinking_register_hook.py b/tests/unit_tests/common/test_thinking_register_hook.py
index 506685ea14..9dff9b34ac 100644
--- a/tests/unit_tests/common/test_thinking_register_hook.py
+++ b/tests/unit_tests/common/test_thinking_register_hook.py
@@ -10,7 +10,7 @@ from jiuwenswarm.common.thinking import register_hook as rh
from jiuwenswarm.common.thinking.adapter import adapt_thinking
-def test_on_subagent_thinking_default_skips_rail(monkeypatch):
+def test_on_subagent_thinking_default_skips_non_glm53_allowlisted():
added: list = []
class FakeSub:
@@ -23,6 +23,34 @@ def test_on_subagent_thinking_default_skips_rail(monkeypatch):
assert added == []
+def test_on_subagent_thinking_default_attaches_rail_for_glm53():
+ added: list = []
+
+ class FakeSub:
+ card = SimpleNamespace(id="a1", name="explore_agent")
+
+ def add_rail(self, rail):
+ added.append(rail)
+
+ rh._on_subagent_thinking(FakeSub(), thinking="default", model="glm-5.3-test")
+ assert len(added) == 1
+ assert added[0].__class__.__name__ == "ThinkingInjectRail"
+ assert added[0]._profile.thinking == "low"
+
+
+def test_on_subagent_thinking_default_skips_unsupported():
+ added: list = []
+
+ class FakeSub:
+ card = SimpleNamespace(id="a1", name="explore_agent")
+
+ def add_rail(self, rail):
+ added.append(rail)
+
+ rh._on_subagent_thinking(FakeSub(), thinking="default", model="qwen3-plus")
+ assert added == []
+
+
def test_on_subagent_thinking_off_attaches_rail(monkeypatch):
added: list = []
diff --git a/tests/unit_tests/server/runtime/skill_turbo/test_skill_turbo_thinking.py b/tests/unit_tests/server/runtime/skill_turbo/test_skill_turbo_thinking.py
index 756764ff96..924eed1067 100644
--- a/tests/unit_tests/server/runtime/skill_turbo/test_skill_turbo_thinking.py
+++ b/tests/unit_tests/server/runtime/skill_turbo/test_skill_turbo_thinking.py
@@ -24,8 +24,22 @@ class _ThinkingProbeNode(DisableThinkingMixin, PlanNode):
class TestResolveSkillTurboThinkingKwargs:
- def test_none_is_zero_inject(self):
- assert resolve_skill_turbo_thinking_kwargs(None, MagicMock()) == {}
+ def test_none_uses_default_low_for_glm53(self):
+ client = MagicMock()
+ client.model_config = MagicMock(model_name="glm-5.3")
+ kwargs = resolve_skill_turbo_thinking_kwargs(None, client)
+ assert kwargs["extra_body"]["thinking"]["type"] == "enabled"
+ assert kwargs["reasoning_effort"] == "low"
+
+ def test_none_no_inject_for_non_glm53_allowlisted(self):
+ client = MagicMock()
+ client.model_config = MagicMock(model_name="glm-5.2")
+ assert resolve_skill_turbo_thinking_kwargs(None, client) == {}
+
+ def test_none_unsupported_empty(self):
+ client = MagicMock()
+ client.model_config = MagicMock(model_name="qwen3-plus")
+ assert resolve_skill_turbo_thinking_kwargs(None, client) == {}
def test_off_glm_uses_allowlist(self):
client = MagicMock()