Files
hermes-agent/tests/agent/test_refine_focus.py
Teknium 8f2712725a feat: /refine — run the memory/skill self-improvement review on demand
/refine [focus] fires the existing background review fork
(AIAgent._spawn_background_review) immediately instead of waiting for
the automatic 10-turn memory / 10-iteration skill nudge counters.
Optional focus instructions are appended to the review prompt so the
fork prioritizes what the user asked for (e.g. '/refine save the
deploy workflow as a skill').

- New optional focus parameter threaded through
  _spawn_background_review -> spawn_background_review_thread.
  Automatic post-turn reviews pass None and their prompts are
  byte-identical to before.
- CLI handler snapshots conversation_history; gateway handler pulls
  the idle session's cached AIAgent from _agent_cache (rejected while
  the agent is running).
- Review runs in a daemon thread against the snapshot — live
  conversation, message alternation, and prompt cache untouched.
- Slack stays under the 50-slash cap via /hermes refine.

Adapted from the /refine concept in Prime Intellect's Prime-Agent
(Continual Harness); Hermes' equivalent durable state is the
memory + skill stores, so the review fork is the natural target.
2026-08-05 22:40:51 -07:00

57 lines
1.8 KiB
Python

"""Tests for the /refine focus parameter on spawn_background_review_thread."""
from unittest.mock import MagicMock
from agent.background_review import (
_COMBINED_REVIEW_PROMPT,
_MEMORY_REVIEW_PROMPT,
spawn_background_review_thread,
)
def _bare_agent():
agent = MagicMock()
# Ensure getattr(agent, "_COMBINED_REVIEW_PROMPT", default) hits the default.
del agent._COMBINED_REVIEW_PROMPT
del agent._MEMORY_REVIEW_PROMPT
del agent._SKILL_REVIEW_PROMPT
return agent
def test_no_focus_prompt_is_byte_identical():
agent = _bare_agent()
_target, prompt = spawn_background_review_thread(
agent, [], review_memory=True, review_skills=True
)
assert prompt == _COMBINED_REVIEW_PROMPT
_target, prompt = spawn_background_review_thread(
agent, [], review_memory=True, review_skills=True, focus=None
)
assert prompt == _COMBINED_REVIEW_PROMPT
_target, prompt = spawn_background_review_thread(
agent, [], review_memory=True, review_skills=True, focus=" "
)
assert prompt == _COMBINED_REVIEW_PROMPT
def test_focus_is_appended_to_prompt():
agent = _bare_agent()
_target, prompt = spawn_background_review_thread(
agent, [], review_memory=True, review_skills=True,
focus="save the deploy workflow as a skill",
)
assert prompt.startswith(_COMBINED_REVIEW_PROMPT)
assert "save the deploy workflow as a skill" in prompt
assert "explicitly requested" in prompt
def test_focus_works_with_memory_only_prompt():
agent = _bare_agent()
_target, prompt = spawn_background_review_thread(
agent, [], review_memory=True, review_skills=False, focus="remember my timezone",
)
assert prompt.startswith(_MEMORY_REVIEW_PROMPT)
assert "remember my timezone" in prompt