fix(agent): refresh skills prompt cache when disabled skills change
This commit is contained in:
@@ -613,12 +613,14 @@ def build_skills_system_prompt(
|
|||||||
or get_session_env("HERMES_SESSION_PLATFORM")
|
or get_session_env("HERMES_SESSION_PLATFORM")
|
||||||
or ""
|
or ""
|
||||||
)
|
)
|
||||||
|
disabled = get_disabled_skill_names()
|
||||||
cache_key = (
|
cache_key = (
|
||||||
str(skills_dir.resolve()),
|
str(skills_dir.resolve()),
|
||||||
tuple(str(d) for d in external_dirs),
|
tuple(str(d) for d in external_dirs),
|
||||||
tuple(sorted(str(t) for t in (available_tools or set()))),
|
tuple(sorted(str(t) for t in (available_tools or set()))),
|
||||||
tuple(sorted(str(ts) for ts in (available_toolsets or set()))),
|
tuple(sorted(str(ts) for ts in (available_toolsets or set()))),
|
||||||
_platform_hint,
|
_platform_hint,
|
||||||
|
tuple(sorted(disabled)),
|
||||||
)
|
)
|
||||||
with _SKILLS_PROMPT_CACHE_LOCK:
|
with _SKILLS_PROMPT_CACHE_LOCK:
|
||||||
cached = _SKILLS_PROMPT_CACHE.get(cache_key)
|
cached = _SKILLS_PROMPT_CACHE.get(cache_key)
|
||||||
@@ -626,8 +628,6 @@ def build_skills_system_prompt(
|
|||||||
_SKILLS_PROMPT_CACHE.move_to_end(cache_key)
|
_SKILLS_PROMPT_CACHE.move_to_end(cache_key)
|
||||||
return cached
|
return cached
|
||||||
|
|
||||||
disabled = get_disabled_skill_names()
|
|
||||||
|
|
||||||
# ── Layer 2: disk snapshot ────────────────────────────────────────
|
# ── Layer 2: disk snapshot ────────────────────────────────────────
|
||||||
snapshot = _load_skills_snapshot(skills_dir)
|
snapshot = _load_skills_snapshot(skills_dir)
|
||||||
|
|
||||||
|
|||||||
@@ -354,6 +354,24 @@ class TestBuildSkillsSystemPrompt:
|
|||||||
assert "web-search" in result
|
assert "web-search" in result
|
||||||
assert "old-tool" not in result
|
assert "old-tool" not in result
|
||||||
|
|
||||||
|
def test_rebuilds_prompt_when_disabled_skills_change(self, monkeypatch, tmp_path):
|
||||||
|
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
||||||
|
skill_dir = tmp_path / "skills" / "tools" / "cached-skill"
|
||||||
|
skill_dir.mkdir(parents=True)
|
||||||
|
(skill_dir / "SKILL.md").write_text(
|
||||||
|
"---\nname: cached-skill\ndescription: Cached skill\n---\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
first = build_skills_system_prompt()
|
||||||
|
assert "cached-skill" in first
|
||||||
|
|
||||||
|
(tmp_path / "config.yaml").write_text(
|
||||||
|
"skills:\n disabled: [cached-skill]\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
second = build_skills_system_prompt()
|
||||||
|
assert "cached-skill" not in second
|
||||||
|
|
||||||
def test_includes_setup_needed_skills(self, monkeypatch, tmp_path):
|
def test_includes_setup_needed_skills(self, monkeypatch, tmp_path):
|
||||||
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
||||||
monkeypatch.delenv("MISSING_API_KEY_XYZ", raising=False)
|
monkeypatch.delenv("MISSING_API_KEY_XYZ", raising=False)
|
||||||
|
|||||||
Reference in New Issue
Block a user