fix(gateway): honor configured goal turn budget

This commit is contained in:
paul-tian 2026-05-04 09:56:09 +10:00 committed by Teknium
parent 0efc547962
commit 4d4807585a
2 changed files with 85 additions and 18 deletions

View file

@ -8331,6 +8331,27 @@ class GatewayRunner:
# ────────────────────────────────────────────────────────────────
# /goal — persistent cross-turn goals (Ralph-style loop)
# ────────────────────────────────────────────────────────────────
def _goal_max_turns_from_config(self) -> int:
"""Resolve the configured /goal turn budget for gateway sessions.
GatewayRunner.config is a GatewayConfig dataclass, not the full
user config mapping. Top-level config blocks such as ``goals`` are
therefore only available through hermes_cli.config.load_config().
"""
try:
goals_cfg = (
(self.config or {}).get("goals", {})
if isinstance(self.config, dict)
else getattr(self.config, "goals", {}) or {}
)
if not goals_cfg:
from hermes_cli.config import load_config
goals_cfg = (load_config() or {}).get("goals") or {}
return int(goals_cfg.get("max_turns", 20) or 20)
except Exception:
return 20
def _get_goal_manager_for_event(self, event: "MessageEvent"):
"""Return a GoalManager bound to the session for this gateway event.
@ -8350,15 +8371,7 @@ class GatewayRunner:
sid = getattr(session_entry, "session_id", None) or ""
if not sid:
return None, None
try:
goals_cfg = (
(self.config or {}).get("goals", {})
if isinstance(self.config, dict)
else getattr(self.config, "goals", {}) or {}
)
max_turns = int(goals_cfg.get("max_turns", 20) or 20)
except Exception:
max_turns = 20
max_turns = self._goal_max_turns_from_config()
return GoalManager(session_id=sid, default_max_turns=max_turns), session_entry
async def _handle_goal_command(self, event: "MessageEvent") -> str:
@ -8458,15 +8471,7 @@ class GatewayRunner:
if not sid:
return
try:
goals_cfg = (
(self.config or {}).get("goals", {})
if isinstance(self.config, dict)
else getattr(self.config, "goals", {}) or {}
)
max_turns = int(goals_cfg.get("max_turns", 20) or 20)
except Exception:
max_turns = 20
max_turns = self._goal_max_turns_from_config()
mgr = GoalManager(session_id=sid, default_max_turns=max_turns)
if not mgr.is_active():