Skip to content

The agent that grows with you

feat: enforce safe defaults at bare agent construction

Teknium1eeac867b187
diff --git a/agent/agent_init.py b/agent/agent_init.py
index 535eb47940b..7e2548ae5b0 100644
--- a/agent/agent_init.py
+++ b/agent/agent_init.py
@@ -2232,6 +2232,13 @@ def init_agent(
skip_context_files: skip SOUL.md/.hermes.md/AGENTS.md/CLAUDE.md/.cursorrules injection;
load_soul_identity keeps ~/.hermes/SOUL.md as identity regardless.
"""
+ from agent.safe_worker_policy import safe_worker_enabled
+
+ if safe_worker_enabled():
+ skip_context_files = skip_memory = skip_background_review = True
+ load_soul_identity = False
+ prefill_messages = []
+ fallback_model = {}
_install_safe_stdio()
_params = locals()
diff --git a/agent/background_review.py b/agent/background_review.py
index 9ed654f0986..749e23da02e 100644
--- a/agent/background_review.py
+++ b/agent/background_review.py
@@ -187,6 +187,10 @@ def _review_input_token_budget(task_cfg: Optional[Dict[str, Any]] = None) -> Opt
def load_background_review_settings() -> tuple[bool, Dict[str, Any]]:
"""Single config read -> ``(enabled, task_cfg)``. Fail-open (``enabled=True``) so a broken
config never silently disables reviews — but WARN so the cost is visible."""
+ from agent.safe_worker_policy import safe_worker_enabled
+
+ if safe_worker_enabled():
+ return False, {}
try:
from hermes_cli.config import load_config_readonly
from utils import is_truthy_value
diff --git a/agent/skill_utils.py b/agent/skill_utils.py
index fe0b06c69f8..abd7c3d25a3 100644
--- a/agent/skill_utils.py
+++ b/agent/skill_utils.py
@@ -222,6 +222,11 @@ def _config_cache_key(config_path: Path) -> Optional[Tuple[str, int, int]]:
def _load_raw_config() -> Dict[str, Any]:
"""Read config.yaml with an mtime+size keyed cache (no hermes_cli.config import)."""
+ from agent.safe_worker_policy import worker_config_snapshot
+
+ snapshot = worker_config_snapshot()
+ if snapshot is not None:
+ return snapshot
config_path = get_config_path()
if not config_path.exists():
return {}
diff --git a/tests/agent/test_safe_worker_policy.py b/tests/agent/test_safe_worker_policy.py
index b5ec89ffe76..e6667fe228b 100644
--- a/tests/agent/test_safe_worker_policy.py
+++ b/tests/agent/test_safe_worker_policy.py
@@ -219,3 +219,42 @@ def test_safe_worker_bypasses_rule_readers_even_without_cli_flags(tmp_path, mode
assert "SUB_SENTINEL" in result["hints"]
assert {"AGENTS.md", "SOUL.md", "SKILL.md", "MEMORY.md"} <= set(result["reads"])
assert result["engines"] == ["sentinel"] and result["memory"]
+
+
[email protected]("mode", ["safe", "config", "ordinary"])
+def test_bare_agent_constructor_cannot_restore_safe_customizations(tmp_path, mode):
+ result = run_worker(tmp_path, r"""
+ import json, os, sys
+ from pathlib import Path
+ mode = os.environ["PROBE_MODE"]
+ home = Path(os.environ["HERMES_HOME"])
+ (home / "SOUL.md").write_text("IDENTITY_SENTINEL")
+ if mode != "ordinary":
+ from agent.safe_worker_policy import _bind_safe_worker_policy
+ _bind_safe_worker_policy(safe_mode=mode == "safe", ignore_user_config=True,
+ config={"agent": {"environment_probe": False}})
+ reads = []
+ def audit(event, args):
+ if event == "open" and str(args[0]).endswith("config.yaml") and args[1] != "w":
+ reads.append(str(args[0]))
+ sys.addaudithook(audit)
+ from run_agent import AIAgent
+ agent = AIAgent(model="safe-fixture", provider="custom", base_url="http://127.0.0.1:9/v1",
+ api_key="fixture", enabled_toolsets=[], quiet_mode=True, skip_context_files=False,
+ load_soul_identity=True, skip_background_review=False,
+ prefill_messages=[{"role": "user", "content": "PREFILL_SENTINEL"}],
+ save_trajectories=False)
+ from agent.background_review import load_background_review_settings
+ flags = [agent.skip_context_files, agent.load_soul_identity, agent.skip_background_review]
+ print(json.dumps({"flags": flags, "prefill": agent.prefill_messages,
+ "review": load_background_review_settings()[0], "reads": reads}))
+ """, mode)
+ if mode == "safe":
+ assert result == {"flags": [True, False, True], "prefill": [], "review": False, "reads": []}
+ else:
+ assert result["flags"] == [False, True, False]
+ assert result["prefill"] and result["review"]
+ if mode == "ordinary":
+ assert result["reads"]
+ else:
+ assert result["reads"] == []