mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
Merge c6ec3e91f3 into 00c3d848d8
This commit is contained in:
commit
4b95eb05e3
2 changed files with 87 additions and 14 deletions
|
|
@ -650,7 +650,6 @@ class GatewayRunner:
|
|||
self._ephemeral_system_prompt = self._load_ephemeral_system_prompt()
|
||||
self._reasoning_config = self._load_reasoning_config()
|
||||
self._service_tier = self._load_service_tier()
|
||||
self._show_reasoning = self._load_show_reasoning()
|
||||
self._busy_input_mode = self._load_busy_input_mode()
|
||||
self._restart_drain_timeout = self._load_restart_drain_timeout()
|
||||
self._provider_routing = self._load_provider_routing()
|
||||
|
|
@ -1414,15 +1413,23 @@ class GatewayRunner:
|
|||
return None
|
||||
|
||||
@staticmethod
|
||||
def _load_show_reasoning() -> bool:
|
||||
"""Load show_reasoning toggle from config.yaml display section."""
|
||||
def _load_show_reasoning(platform_key: str = "") -> bool:
|
||||
"""Load show_reasoning toggle — resolves per-platform then global.
|
||||
|
||||
Delegates to resolve_display_setting() so the resolution order
|
||||
(platform override → global → default) stays in one place.
|
||||
"""
|
||||
try:
|
||||
from gateway.display_config import resolve_display_setting
|
||||
import yaml as _y
|
||||
cfg_path = _hermes_home / "config.yaml"
|
||||
user_cfg = {}
|
||||
if cfg_path.exists():
|
||||
with open(cfg_path, encoding="utf-8") as _f:
|
||||
cfg = _y.safe_load(_f) or {}
|
||||
return bool(cfg.get("display", {}).get("show_reasoning", False))
|
||||
user_cfg = _y.safe_load(_f) or {}
|
||||
return bool(resolve_display_setting(
|
||||
user_cfg, platform_key, "show_reasoning", False
|
||||
))
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
|
|
@ -4687,10 +4694,10 @@ class GatewayRunner:
|
|||
_load_gateway_config(),
|
||||
_platform_config_key(source.platform),
|
||||
"show_reasoning",
|
||||
getattr(self, "_show_reasoning", False),
|
||||
False,
|
||||
)
|
||||
except Exception:
|
||||
_show_reasoning_effective = getattr(self, "_show_reasoning", False)
|
||||
_show_reasoning_effective = False
|
||||
if _show_reasoning_effective and response:
|
||||
last_reasoning = agent_result.get("last_reasoning")
|
||||
if last_reasoning:
|
||||
|
|
@ -6834,7 +6841,7 @@ class GatewayRunner:
|
|||
args = event.get_command_args().strip().lower()
|
||||
config_path = _hermes_home / "config.yaml"
|
||||
self._reasoning_config = self._load_reasoning_config()
|
||||
self._show_reasoning = self._load_show_reasoning()
|
||||
_pk = _platform_config_key(event.source.platform)
|
||||
|
||||
def _save_config_key(key_path: str, value):
|
||||
"""Save a dot-separated key to config.yaml."""
|
||||
|
|
@ -6865,7 +6872,17 @@ class GatewayRunner:
|
|||
level = "none (disabled)"
|
||||
else:
|
||||
level = rc.get("effort", "medium")
|
||||
display_state = "on ✓" if self._show_reasoning else "off"
|
||||
try:
|
||||
from gateway.display_config import resolve_display_setting as _rds
|
||||
_show_reasoning = bool(_rds(
|
||||
_load_gateway_config(),
|
||||
_pk,
|
||||
"show_reasoning",
|
||||
False,
|
||||
))
|
||||
except Exception:
|
||||
_show_reasoning = False
|
||||
display_state = "on ✓" if _show_reasoning else "off"
|
||||
return (
|
||||
"🧠 **Reasoning Settings**\n\n"
|
||||
f"**Effort:** `{level}`\n"
|
||||
|
|
@ -6876,7 +6893,6 @@ class GatewayRunner:
|
|||
# Display toggle (per-platform)
|
||||
platform_key = _platform_config_key(event.source.platform)
|
||||
if args in ("show", "on"):
|
||||
self._show_reasoning = True
|
||||
_save_config_key(f"display.platforms.{platform_key}.show_reasoning", True)
|
||||
return (
|
||||
"🧠 ✓ Reasoning display: **ON**\n"
|
||||
|
|
@ -6884,7 +6900,6 @@ class GatewayRunner:
|
|||
)
|
||||
|
||||
if args in ("hide", "off"):
|
||||
self._show_reasoning = False
|
||||
_save_config_key(f"display.platforms.{platform_key}.show_reasoning", False)
|
||||
return f"🧠 ✓ Reasoning display: **OFF** for **{platform_key}**"
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ def _make_runner():
|
|||
runner._ephemeral_system_prompt = ""
|
||||
runner._prefill_messages = []
|
||||
runner._reasoning_config = None
|
||||
runner._show_reasoning = False
|
||||
runner._provider_routing = {}
|
||||
runner._fallback_model = None
|
||||
runner._running_agents = {}
|
||||
|
|
@ -90,14 +89,73 @@ class TestReasoningCommand:
|
|||
|
||||
runner = _make_runner()
|
||||
runner._reasoning_config = {"enabled": True, "effort": "xhigh"}
|
||||
runner._show_reasoning = False
|
||||
|
||||
result = await runner._handle_reasoning_command(_make_event("/reasoning"))
|
||||
|
||||
assert "**Effort:** `none (disabled)`" in result
|
||||
assert "**Display:** on ✓" in result
|
||||
assert runner._reasoning_config == {"enabled": False}
|
||||
assert runner._show_reasoning is True
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_load_show_reasoning_resolves_per_platform(self, tmp_path, monkeypatch):
|
||||
"""Per-platform show_reasoning overrides global setting."""
|
||||
hermes_home = tmp_path / "hermes"
|
||||
hermes_home.mkdir()
|
||||
(hermes_home / "config.yaml").write_text(
|
||||
"display:\n"
|
||||
" show_reasoning: false\n"
|
||||
" platforms:\n"
|
||||
" wecom:\n"
|
||||
" show_reasoning: true\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
monkeypatch.setattr(gateway_run, "_hermes_home", hermes_home)
|
||||
|
||||
# Per-platform: wecom should pick up the override
|
||||
assert gateway_run.GatewayRunner._load_show_reasoning("wecom") is True
|
||||
# Per-platform: telegram has no override → falls back to global (false)
|
||||
assert gateway_run.GatewayRunner._load_show_reasoning("telegram") is False
|
||||
# No platform key → global (false)
|
||||
assert gateway_run.GatewayRunner._load_show_reasoning("") is False
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_load_show_reasoning_global_fallback(self, tmp_path, monkeypatch):
|
||||
"""Global show_reasoning is used when no per-platform override exists."""
|
||||
hermes_home = tmp_path / "hermes"
|
||||
hermes_home.mkdir()
|
||||
(hermes_home / "config.yaml").write_text(
|
||||
"display:\n"
|
||||
" show_reasoning: true\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
monkeypatch.setattr(gateway_run, "_hermes_home", hermes_home)
|
||||
|
||||
assert gateway_run.GatewayRunner._load_show_reasoning("wecom") is True
|
||||
assert gateway_run.GatewayRunner._load_show_reasoning("telegram") is True
|
||||
assert gateway_run.GatewayRunner._load_show_reasoning("") is True
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_reasoning_command_per_platform_status(self, tmp_path, monkeypatch):
|
||||
"""The /reasoning status display reflects per-platform config."""
|
||||
hermes_home = tmp_path / "hermes"
|
||||
hermes_home.mkdir()
|
||||
(hermes_home / "config.yaml").write_text(
|
||||
"display:\n"
|
||||
" show_reasoning: false\n"
|
||||
" platforms:\n"
|
||||
" wecom:\n"
|
||||
" show_reasoning: true\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
monkeypatch.setattr(gateway_run, "_hermes_home", hermes_home)
|
||||
|
||||
runner = _make_runner()
|
||||
runner._reasoning_config = None
|
||||
# Simulate a WeCom message
|
||||
event = _make_event(text="/reasoning", platform=Platform.WECOM)
|
||||
result = await runner._handle_reasoning_command(event)
|
||||
|
||||
assert "**Display:** on ✓" in result
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_handle_reasoning_command_updates_config_and_cache(self, tmp_path, monkeypatch):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue