Files
hermes-agent/agent/context_compressor_prompt_rules.py
Teknium 73bfb9ce7e feat(compression): keep uncertain claims labelled UNVERIFIED through compaction
Summaries shed qualifier words first, so "I suspect X" either hardens into
"X" (a fact the resumed agent acts on) or drops out entirely. The summarizer
prompt now asks for each uncertain claim as an explicit labelled line
("UNVERIFIED: <claim> — <basis>") under a new "## Unverified / Working
Hypotheses" section, on both the first-compaction and iterative-update paths.

The text lives in the new agent/context_compressor_prompt_rules.py sibling
(which also takes _today_for_prompt off the facade); the facade only
interpolates it. Summarizer prompt only: system prompt, cached
prefix and the persisted handoff prefix are unchanged. Cost: +288 chars per
summary call (~+79 prompt tokens measured live), down from +756 in the
first version of this change.
2026-11-04 21:31:47 -08:00

35 lines
1.8 KiB
Python

"""Rule text and helpers for the compaction summarizer prompt.
Epistemic stance: compression sheds qualifier words first ("probably", "I suspect", "unconfirmed"),
which either hardens an untested hypothesis into a fact the resumed agent acts on, or drops it and
loses the investigative thread. Asking for stance as an explicit labelled field rather than an inline aside
keeps it through compression (arXiv:2608.06953). Both strings are interpolated into the summarizer
prompt only (never the system prompt or the persisted handoff prefix), so the cached prefix is
untouched; f-string interpolation does not re-parse them, so braces in them are safe.
"""
UNVERIFIED_SECTION_HEADING = "## Unverified / Working Hypotheses"
EPISTEMIC_STANCE_RULE = (
"Never restate an uncertain claim (suspicion, hypothesis, unverified inference) as fact: list "
f'each under {UNVERIFIED_SECTION_HEADING} as "UNVERIFIED: <claim> — <basis>". '
)
UNVERIFIED_HYPOTHESES_SECTION = f"""
{UNVERIFIED_SECTION_HEADING}
[UNVERIFIED: <claim> — <basis so far>, one per line. If none, write "None."]"""
def _today_for_prompt() -> str:
"""Date-only (user tz) for temporal anchoring; "" when the clock fails. Cache-safe: the summary is outside the prefix."""
try:
# Date-only granularity matches system_prompt.py:337 (PR #20451) and the user's configured timezone
# via hermes_time.now(). The compaction summary is a mid-conversation message that is NOT part of
# the cached prefix, so a date here never affects prompt-cache stability. Resolved defensively — a
# clock failure must never block compaction.
from hermes_time import now as _hermes_now
return _hermes_now().strftime("%Y-%m-%d")
except Exception: # pragma: no cover - clock resolution is best-effort
return ""