From f0bfacab1fc124fa59d155c709b6f59d680c84e5 Mon Sep 17 00:00:00 2001 From: David Secretary Date: Sun, 19 Apr 2026 12:00:50 +0900 Subject: [PATCH] feat: add lazy skill loading option (skills.loading: lazy/eager) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When skills.loading is set to 'lazy' in config.yaml, the full skill listing is omitted from the system prompt. Instead, a short hint tells the agent to call skills_list() on demand, then load relevant skills with skill_view(name). This saves ~1,500-2,000 system-prompt tokens per turn when many skills are installed — especially beneficial for messaging platform users who pay per-token through API proxies without prompt caching. Changes: - hermes_cli/config.py: add skills.loading default 'eager' - agent/prompt_builder.py: add lazy parameter + on-demand hint - run_agent.py: read config and pass lazy flag to prompt builder Closes #2045 --- agent/prompt_builder.py | 16 ++++++++++++++++ hermes_cli/config.py | 3 +++ run_agent.py | 2 ++ 3 files changed, 21 insertions(+) diff --git a/agent/prompt_builder.py b/agent/prompt_builder.py index 3e042f65dfa43..6e9edbe498c1e 100644 --- a/agent/prompt_builder.py +++ b/agent/prompt_builder.py @@ -583,9 +583,14 @@ def _skill_should_show( def build_skills_system_prompt( available_tools: "set[str] | None" = None, available_toolsets: "set[str] | None" = None, + lazy: bool = False, ) -> str: """Build a compact skill index for the system prompt. + When *lazy* is ``True``, the full skill listing is omitted from the prompt. + Instead a short hint tells the agent to call ``skills_list`` on demand. This + saves ~1,500–2,000 system-prompt tokens when many skills are installed. + Two-layer cache: 1. In-process LRU dict keyed by (skills_dir, tools, toolsets) 2. Disk snapshot (``.skills_prompt_snapshot.json``) validated by @@ -604,6 +609,17 @@ def build_skills_system_prompt( if not skills_dir.exists() and not external_dirs: return "" + # ── Lazy loading: short hint instead of full listing ──────────────── + if lazy: + return ( + "## Skills (on-demand)\n" + "A skills catalog is available. Call skills_list() when you think a " + "specialized skill might help with your task, then load it with " + "skill_view(name). If a skill has issues, fix it with " + "skill_manage(action='patch'). After difficult/iterative tasks, " + "offer to save as a skill." + ) + # ── Layer 1: in-process LRU cache ───────────────────────────────── # Include the resolved platform so per-platform disabled-skill lists # produce distinct cache entries (gateway serves multiple platforms). diff --git a/hermes_cli/config.py b/hermes_cli/config.py index d53899b135e06..259c3c6e26736 100644 --- a/hermes_cli/config.py +++ b/hermes_cli/config.py @@ -689,6 +689,9 @@ def _ensure_hermes_home_managed(home: Path): # always goes to ~/.hermes/skills/. "skills": { "external_dirs": [], # e.g. ["~/.agents/skills", "/shared/team-skills"] + # "eager" (default): inject full skill listing into system prompt every turn. + # "lazy": omit listing from system prompt; agent calls skills_list() on demand. + "loading": "eager", }, # Honcho AI-native memory -- reads ~/.honcho/config.json as single source of truth. diff --git a/run_agent.py b/run_agent.py index c87bd35152845..b3fec9c5d1ec4 100644 --- a/run_agent.py +++ b/run_agent.py @@ -1405,6 +1405,7 @@ def __init__( try: skills_config = _agent_cfg.get("skills", {}) self._skill_nudge_interval = int(skills_config.get("creation_nudge_interval", 10)) + self._skills_loading = str(skills_config.get("loading", "eager")).lower() except Exception: pass @@ -3772,6 +3773,7 @@ def _build_system_prompt(self, system_message: str = None) -> str: skills_prompt = build_skills_system_prompt( available_tools=self.valid_tool_names, available_toolsets=avail_toolsets, + lazy=getattr(self, "_skills_loading", "eager") == "lazy", ) else: skills_prompt = ""