mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-28 06:51:16 +08:00
fix: unify reasoning_effort to config.yaml only, remove HERMES_REASONING_EFFORT env var
Gateway and cron had inconsistent reasoning_effort resolution: - CLI: config.yaml only (correct) - Gateway: config.yaml first, env var fallback - Cron: env var first, config.yaml fallback All three now read exclusively from agent.reasoning_effort in config.yaml. Removed HERMES_REASONING_EFFORT env var support entirely — .env is for secrets only, not behavioral config.
This commit is contained in:
@@ -585,11 +585,9 @@ def run_job(job: dict) -> tuple[bool, str, str, Optional[str]]:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning("Job '%s': failed to load config.yaml, using defaults: %s", job_id, e)
|
logger.warning("Job '%s': failed to load config.yaml, using defaults: %s", job_id, e)
|
||||||
|
|
||||||
# Reasoning config from env or config.yaml
|
# Reasoning config from config.yaml
|
||||||
from hermes_constants import parse_reasoning_effort
|
from hermes_constants import parse_reasoning_effort
|
||||||
effort = os.getenv("HERMES_REASONING_EFFORT", "")
|
effort = str(_cfg.get("agent", {}).get("reasoning_effort", "")).strip()
|
||||||
if not effort:
|
|
||||||
effort = str(_cfg.get("agent", {}).get("reasoning_effort", "")).strip()
|
|
||||||
reasoning_config = parse_reasoning_effort(effort)
|
reasoning_config = parse_reasoning_effort(effort)
|
||||||
|
|
||||||
# Prefill messages from env or config.yaml
|
# Prefill messages from env or config.yaml
|
||||||
|
|||||||
@@ -921,12 +921,11 @@ class GatewayRunner:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _load_reasoning_config() -> dict | None:
|
def _load_reasoning_config() -> dict | None:
|
||||||
"""Load reasoning effort from config with env fallback.
|
"""Load reasoning effort from config.yaml.
|
||||||
|
|
||||||
Checks agent.reasoning_effort in config.yaml first, then
|
Reads agent.reasoning_effort from config.yaml. Valid: "xhigh",
|
||||||
HERMES_REASONING_EFFORT as a fallback. Valid: "xhigh", "high",
|
"high", "medium", "low", "minimal", "none". Returns None to use
|
||||||
"medium", "low", "minimal", "none". Returns None to use default
|
default (medium).
|
||||||
(medium).
|
|
||||||
"""
|
"""
|
||||||
from hermes_constants import parse_reasoning_effort
|
from hermes_constants import parse_reasoning_effort
|
||||||
effort = ""
|
effort = ""
|
||||||
@@ -939,8 +938,6 @@ class GatewayRunner:
|
|||||||
effort = str(cfg.get("agent", {}).get("reasoning_effort", "") or "").strip()
|
effort = str(cfg.get("agent", {}).get("reasoning_effort", "") or "").strip()
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
if not effort:
|
|
||||||
effort = os.getenv("HERMES_REASONING_EFFORT", "")
|
|
||||||
result = parse_reasoning_effort(effort)
|
result = parse_reasoning_effort(effort)
|
||||||
if effort and effort.strip() and result is None:
|
if effort and effort.strip() and result is None:
|
||||||
logger.warning("Unknown reasoning_effort '%s', using default (medium)", effort)
|
logger.warning("Unknown reasoning_effort '%s', using default (medium)", effort)
|
||||||
|
|||||||
@@ -87,7 +87,6 @@ class TestReasoningCommand:
|
|||||||
)
|
)
|
||||||
|
|
||||||
monkeypatch.setattr(gateway_run, "_hermes_home", hermes_home)
|
monkeypatch.setattr(gateway_run, "_hermes_home", hermes_home)
|
||||||
monkeypatch.delenv("HERMES_REASONING_EFFORT", raising=False)
|
|
||||||
|
|
||||||
runner = _make_runner()
|
runner = _make_runner()
|
||||||
runner._reasoning_config = {"enabled": True, "effort": "xhigh"}
|
runner._reasoning_config = {"enabled": True, "effort": "xhigh"}
|
||||||
@@ -108,7 +107,6 @@ class TestReasoningCommand:
|
|||||||
config_path.write_text("agent:\n reasoning_effort: medium\n", encoding="utf-8")
|
config_path.write_text("agent:\n reasoning_effort: medium\n", encoding="utf-8")
|
||||||
|
|
||||||
monkeypatch.setattr(gateway_run, "_hermes_home", hermes_home)
|
monkeypatch.setattr(gateway_run, "_hermes_home", hermes_home)
|
||||||
monkeypatch.delenv("HERMES_REASONING_EFFORT", raising=False)
|
|
||||||
|
|
||||||
runner = _make_runner()
|
runner = _make_runner()
|
||||||
runner._reasoning_config = {"enabled": True, "effort": "medium"}
|
runner._reasoning_config = {"enabled": True, "effort": "medium"}
|
||||||
@@ -138,7 +136,6 @@ class TestReasoningCommand:
|
|||||||
"api_key": "test-key",
|
"api_key": "test-key",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
monkeypatch.delenv("HERMES_REASONING_EFFORT", raising=False)
|
|
||||||
fake_run_agent = types.ModuleType("run_agent")
|
fake_run_agent = types.ModuleType("run_agent")
|
||||||
fake_run_agent.AIAgent = _CapturingAgent
|
fake_run_agent.AIAgent = _CapturingAgent
|
||||||
monkeypatch.setitem(sys.modules, "run_agent", fake_run_agent)
|
monkeypatch.setitem(sys.modules, "run_agent", fake_run_agent)
|
||||||
@@ -170,55 +167,6 @@ class TestReasoningCommand:
|
|||||||
assert _CapturingAgent.last_init is not None
|
assert _CapturingAgent.last_init is not None
|
||||||
assert _CapturingAgent.last_init["reasoning_config"] == {"enabled": True, "effort": "low"}
|
assert _CapturingAgent.last_init["reasoning_config"] == {"enabled": True, "effort": "low"}
|
||||||
|
|
||||||
def test_run_agent_prefers_config_over_stale_reasoning_env(self, tmp_path, monkeypatch):
|
|
||||||
hermes_home = tmp_path / "hermes"
|
|
||||||
hermes_home.mkdir()
|
|
||||||
(hermes_home / "config.yaml").write_text("agent:\n reasoning_effort: none\n", encoding="utf-8")
|
|
||||||
|
|
||||||
monkeypatch.setattr(gateway_run, "_hermes_home", hermes_home)
|
|
||||||
monkeypatch.setattr(gateway_run, "_env_path", hermes_home / ".env")
|
|
||||||
monkeypatch.setattr(gateway_run, "load_dotenv", lambda *args, **kwargs: None)
|
|
||||||
monkeypatch.setattr(
|
|
||||||
gateway_run,
|
|
||||||
"_resolve_runtime_agent_kwargs",
|
|
||||||
lambda: {
|
|
||||||
"provider": "openrouter",
|
|
||||||
"api_mode": "chat_completions",
|
|
||||||
"base_url": "https://openrouter.ai/api/v1",
|
|
||||||
"api_key": "test-key",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
monkeypatch.setenv("HERMES_REASONING_EFFORT", "low")
|
|
||||||
fake_run_agent = types.ModuleType("run_agent")
|
|
||||||
fake_run_agent.AIAgent = _CapturingAgent
|
|
||||||
monkeypatch.setitem(sys.modules, "run_agent", fake_run_agent)
|
|
||||||
|
|
||||||
_CapturingAgent.last_init = None
|
|
||||||
runner = _make_runner()
|
|
||||||
|
|
||||||
source = SessionSource(
|
|
||||||
platform=Platform.LOCAL,
|
|
||||||
chat_id="cli",
|
|
||||||
chat_name="CLI",
|
|
||||||
chat_type="dm",
|
|
||||||
user_id="user-1",
|
|
||||||
)
|
|
||||||
|
|
||||||
result = asyncio.run(
|
|
||||||
runner._run_agent(
|
|
||||||
message="ping",
|
|
||||||
context_prompt="",
|
|
||||||
history=[],
|
|
||||||
source=source,
|
|
||||||
session_id="session-1",
|
|
||||||
session_key="agent:main:local:dm",
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
assert result["final_response"] == "ok"
|
|
||||||
assert _CapturingAgent.last_init is not None
|
|
||||||
assert _CapturingAgent.last_init["reasoning_config"] == {"enabled": False}
|
|
||||||
|
|
||||||
def test_run_agent_includes_enabled_mcp_servers_in_gateway_toolsets(self, tmp_path, monkeypatch):
|
def test_run_agent_includes_enabled_mcp_servers_in_gateway_toolsets(self, tmp_path, monkeypatch):
|
||||||
hermes_home = tmp_path / "hermes"
|
hermes_home = tmp_path / "hermes"
|
||||||
hermes_home.mkdir()
|
hermes_home.mkdir()
|
||||||
|
|||||||
Reference in New Issue
Block a user