Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(hermes): reduce new-bot startup and excessive tool context (#478)

Ruben Lütke1be6d1525957
diff --git a/jarvis/agent_runtimes/base.py b/jarvis/agent_runtimes/base.py
index d16ceaf3b3..42e2e282a9 100644
--- a/jarvis/agent_runtimes/base.py
+++ b/jarvis/agent_runtimes/base.py
@@ -256,7 +256,16 @@ def runtimes_root() -> Path:
def agent_home(runtime: str, agent_id: str) -> Path:
"""The runtime's own state folder for one agent (created on demand)."""
safe = re.sub(r"[^A-Za-z0-9_.-]", "_", agent_id) or "agent"
- home = runtimes_root() / runtime / safe
+ root = runtimes_root() / runtime
+ home = root / safe
+ legacy_profile = any((home / name).is_file() for name in ("config.yaml", "state.db", "SOUL.md"))
+ if runtime == "hermes" and not legacy_profile:
+ # Hermes treats an arbitrary HERMES_HOME as a separate installation:
+ # every new bot otherwise rebuilds Python dependencies before ACP can
+ # answer. Native profile layout shares only the installation while
+ # keeping config, credentials and conversations in separate homes.
+ # Existing homes retain their state and native session identifiers.
+ home = root / "profiles" / safe
home.mkdir(parents=True, exist_ok=True)
return home
diff --git a/jarvis/agent_runtimes/hermes.py b/jarvis/agent_runtimes/hermes.py
index 14aab216d9..e103804d78 100644
--- a/jarvis/agent_runtimes/hermes.py
+++ b/jarvis/agent_runtimes/hermes.py
@@ -190,10 +190,10 @@ class HermesRuntime:
},
"skills": {"creation_nudge_interval": 0, "project_discovery": False},
"curator": {"enabled": False},
- # Jarvis' tools are what make this a Jarvis agent: offered directly,
- # never deferred behind Hermes' tool search, where smaller models
- # fail to find them (seen live with a 9B model, 2026-10-06).
- "tools": {"tool_search": False},
+ # Connected accounts can expose hundreds of tools. Keep their
+ # schemas out of every greeting; Hermes discovers and dispatches
+ # them through the same MCP server, including its approval gates.
+ "tools": {"tool_search": {"enabled": "on", "listing_max_tokens": 2000}},
"auxiliary": {
"background_review": {"enabled": False},
"title_generation": {"enabled": False},
@@ -264,8 +264,20 @@ class HermesRuntime:
)
def _write_profile(self, home: Path, turn: RuntimeTurn) -> None:
+ from jarvis.agent_runtimes.tool_snapshot import refresh_tool_search_cache
+
+ refresh_tool_search_cache(home, turn.resume)
write_json_if_changed(home / "config.yaml", self.config_for(turn))
- write_if_changed(home / "SOUL.md", persona_text(turn.agent_name))
+ write_if_changed(
+ home / "SOUL.md",
+ persona_text(turn.agent_name)
+ + "Jarvis MCP tools are available through tool_search, tool_describe and "
+ "tool_call. For a task that needs Jarvis or a connected account, use "
+ "tool_search with the service and action, read the returned schema, "
+ "then invoke its exact tool name through tool_call. Search before "
+ "concluding a capability is missing. For a greeting or ordinary "
+ "conversation, reply directly without searching for tools.\n",
+ )
def _restore_key_aliases(base_url: str, api_key: str | None) -> dict[str, str]:
diff --git a/jarvis/agent_runtimes/tool_snapshot.py b/jarvis/agent_runtimes/tool_snapshot.py
new file mode 100644
index 0000000000..910801477b
--- /dev/null
+++ b/jarvis/agent_runtimes/tool_snapshot.py
@@ -0,0 +1,63 @@
+"""Discard obsolete eager tool snapshots when a Hermes conversation resumes."""
+
+from __future__ import annotations
+
+import json
+import logging
+import sqlite3
+from contextlib import closing
+from pathlib import Path
+
+log = logging.getLogger(__name__)
+
+
+def refresh_tool_search_cache(home: Path, session_id: str | None) -> bool:
+ """Invalidate only the resumed session's compiled tool catalog, not history.
+
+ Hermes pins tool schemas across resumes, including tools now deferred by
+ configuration. Keeping that eager pin alongside the discovery tools defeats
+ tool search. Both the older inline name list and the content-addressed
+ snapshot are caches; a NULL pin makes Hermes rebuild from its current config.
+ Call while the runtime's profile slot is held, before starting its process.
+ An unfamiliar native schema degrades to the existing cache, never a lost chat.
+ """
+ database = home / "state.db"
+ if not session_id or not database.is_file():
+ return False
+ try:
+ with closing(sqlite3.connect(database.resolve().as_uri() + "?mode=rw", uri=True,
+ timeout=1.0)) as connection, connection:
+ row = connection.execute(
+ "SELECT tool_names FROM sessions WHERE id = ?", (session_id,)
+ ).fetchone()
+ if not row or not row[0]:
+ return False
+ saved = row[0]
+ if saved.lstrip().startswith(("[", "{")):
+ snapshot = json.loads(saved)
+ else:
+ cached = connection.execute(
+ "SELECT prompt FROM system_prompts WHERE hash = ?", (saved,)
+ ).fetchone()
+ if not cached:
+ return False
+ snapshot = json.loads(cached[0])
+ tools = snapshot.get("tools", []) if isinstance(snapshot, dict) else snapshot
+ if not isinstance(tools, list):
+ return False
+ names = [
+ tool if isinstance(tool, str) else tool.get("function", {}).get("name", "")
+ for tool in tools if isinstance(tool, (str, dict))
+ ]
+ if not any(str(name).startswith("mcp__jarvis__") for name in names):
+ return False
+ changed = connection.execute(
+ "UPDATE sessions SET tool_names = NULL WHERE id = ? AND tool_names = ?",
+ (session_id, saved),
+ ).rowcount
+ if changed:
+ log.info("Hermes: discarded the resumed conversation's eager tool cache")
+ return bool(changed)
+ except (sqlite3.Error, ValueError, TypeError, AttributeError):
+ log.warning("Hermes: could not refresh the native tool cache; retaining it", exc_info=True)
+ return False
diff --git a/tests/unit/agent_runtimes/test_hermes_tool_cache.py b/tests/unit/agent_runtimes/test_hermes_tool_cache.py
new file mode 100644
index 0000000000..17fc599c68
--- /dev/null
+++ b/tests/unit/agent_runtimes/test_hermes_tool_cache.py
@@ -0,0 +1,48 @@
+"""Existing native conversations adopt tool discovery without losing history."""
+
+import json
+import sqlite3
+
+import pytest
+
+from jarvis.agent_runtimes.tool_snapshot import refresh_tool_search_cache
+
+
[email protected]("hashed", [False, True])
+def test_only_the_selected_eager_cache_is_invalidated(tmp_path, hashed):
+ snapshot = json.dumps({"tools": [
+ {"function": {"name": "mcp__jarvis__society_ask_user"}},
+ {"function": {"name": "tool_search"}},
+ ]}) if hashed else json.dumps(["mcp__jarvis__society_ask_user", "tool_search"])
+ pin = "snapshot-hash" if hashed else snapshot
+ with sqlite3.connect(tmp_path / "state.db") as db:
+ db.executescript("""
+ CREATE TABLE sessions (id TEXT PRIMARY KEY, tool_names TEXT, system_prompt TEXT);
+ CREATE TABLE system_prompts (hash TEXT PRIMARY KEY, prompt TEXT);
+ CREATE TABLE messages (session_id TEXT, content TEXT);
+ """)
+ db.executemany("INSERT INTO sessions VALUES (?, ?, ?)", [
+ ("selected", pin, "Keep my identity"), ("other", pin, "Other identity"),
+ ])
+ db.execute("INSERT INTO system_prompts VALUES (?, ?)", ("snapshot-hash", snapshot))
+ db.execute("INSERT INTO messages VALUES (?, ?)", ("selected", "Completed action"))
+ assert refresh_tool_search_cache(tmp_path, "selected")
+ assert not refresh_tool_search_cache(tmp_path, "selected")
+ with sqlite3.connect(tmp_path / "state.db") as db:
+ assert db.execute("SELECT * FROM sessions ORDER BY id").fetchall() == [
+ ("other", pin, "Other identity"), ("selected", None, "Keep my identity"),
+ ]
+ assert db.execute("SELECT * FROM messages").fetchall() == [("selected", "Completed action")]
+ assert db.execute("SELECT prompt FROM system_prompts").fetchone() == (snapshot,)
+ compact = json.dumps(["terminal", "tool_search", "tool_call", "tool_describe"])
+ db.execute("UPDATE sessions SET tool_names = ? WHERE id = 'selected'", (compact,))
+ assert not refresh_tool_search_cache(tmp_path, "selected")
+
+
+def test_missing_or_unfamiliar_native_store_is_retained(tmp_path, caplog):
+ assert not refresh_tool_search_cache(tmp_path, "missing")
+ assert not (tmp_path / "state.db").exists()
+ with sqlite3.connect(tmp_path / "state.db") as db:
+ db.execute("CREATE TABLE future_native_layout (value TEXT)")
+ assert not refresh_tool_search_cache(tmp_path, "unknown")
+ assert "retaining it" in caplog.text
diff --git a/tests/unit/agent_runtimes/test_runtime_configs.py b/tests/unit/agent_runtimes/test_runtime_configs.py
index 3b823fcd5c..302dc2e561 100644
--- a/tests/unit/agent_runtimes/test_runtime_configs.py
+++ b/tests/unit/agent_runtimes/test_runtime_configs.py
@@ -103,9 +103,47 @@ def test_hermes_self_learning_extras_stay_off(tmp_path):
assert config["skills"]["creation_nudge_interval"] == 0
-def test_hermes_offers_jarvis_tools_directly(tmp_path):
- """Never deferred behind Hermes' tool search (a 9B model missed them live)."""
- assert HermesRuntime().config_for(_turn(tmp_path))["tools"]["tool_search"] is False
+def test_hermes_discovers_connected_tools_with_explicit_persona_guidance(tmp_path):
+ """Large catalogs stay lazy, and the persona explains how to reach them."""
+ runtime = HermesRuntime()
+ turn = _turn(tmp_path)
+ runtime._write_profile(tmp_path, turn)
+ config = json.loads((tmp_path / "config.yaml").read_text(encoding="utf-8"))
+ search = config["tools"]["tool_search"]
+ assert search["enabled"] == "on"
+ assert search["listing_max_tokens"] <= 2000
+ persona = (tmp_path / "SOUL.md").read_text(encoding="utf-8")
+ assert "tool_search" in persona and "tool_describe" in persona and "tool_call" in persona
+ assert "reply directly without searching" in persona
+ assert "Search before concluding a capability is missing" in persona
+
+
+def test_hermes_profiles_share_installation_but_keep_agent_state_separate(tmp_path, monkeypatch):
+ from jarvis.agent_runtimes import base
+
+ monkeypatch.setattr(base, "runtimes_root", lambda: tmp_path)
+ first = base.agent_home("hermes", "first")
+ second = base.agent_home("hermes", "second")
+ routine = base.agent_home("hermes", base.home_key("first", "society:first:routine:1"))
+ assert first.parent == second.parent == routine.parent == tmp_path / "hermes" / "profiles"
+ assert len({first, second, routine}) == 3
+ (first / "state.db").write_bytes(b"private conversation")
+ assert not (second / "state.db").exists()
+ assert not (routine / "state.db").exists()
+ assert base.agent_home("hermes", "first") == first
+ assert base.agent_home("hermes", "profiles") == first.parent / "profiles"
+
+
+def test_existing_runtime_homes_keep_their_native_sessions(tmp_path, monkeypatch):
+ from jarvis.agent_runtimes import base
+
+ monkeypatch.setattr(base, "runtimes_root", lambda: tmp_path)
+ legacy = tmp_path / "hermes" / "existing"
+ legacy.mkdir(parents=True)
+ (legacy / "state.db").write_bytes(b"existing session")
+ assert base.agent_home("hermes", "existing") == legacy
+ assert (legacy / "state.db").read_bytes() == b"existing session"
+ assert base.agent_home("openclaw", "first") == tmp_path / "openclaw" / "first"
def test_hermes_always_asks_jarvis_and_never_the_guardian(tmp_path):