Hermes Agent context engine: the main model writes the compaction handoff on its cached prompt prefix
Size the prepended user row as Hermes sends it
Elevatormusic9a700cdef3a5
diff --git a/evidence/plugin-integration.json b/evidence/plugin-integration.jsonindex b83c13c..8c651ac 100644--- a/evidence/plugin-integration.json+++ b/evidence/plugin-integration.json@@ -1,6 +1,6 @@{"check": "standalone warm_compaction plugin on unpatched Hermes Agent",- "started_utc": "2026-10-06T16:12:49Z",+ "started_utc": "2026-10-06T16:27:26Z","hermes": {"commit": "45871e100feceb89769536c88e5e6e265226a409","clean": true@@ -10,10 +10,10 @@"plugin_files_sha256": {"warm_compaction/__init__.py": "11e038f05813627b2d1d8b82b3b775ecfe41015746c8e90ed6d452cfdaec65a6","warm_compaction/capture.py": "387a5bda2c97530c6e9114e810ac062199e3731c12a582d75598d2bdb95e8c57",- "warm_compaction/engine.py": "aa7d4abc93dad256a14ccca91cc4f9498940a8c99149b3d6c5f3ed4c6a41ade5",+ "warm_compaction/engine.py": "c46e5ac2041599bb48983a7cfe990412cc1669ba9f2f834d9d71b55db31064a4","warm_compaction/fallback.py": "f4cf08186f38fc9a46f47af2bedf22584b6ede4f11de1c3abd0fd598aec2f8a4","warm_compaction/handoff.py": "9afea62ec2f8ef46cbeefd70b1071bb6c7111fa6fd1cd073e1fb2c7eae30f3c2",- "warm_compaction/layout.py": "21a280ec25c581e732e8d0c528f19b72102d685bd0da91bc622b6e01cd0fbb06",+ "warm_compaction/layout.py": "02ddc09b79e15fb1a81d09369f6deed3a1068cda6907ab59aae71b8cc98c3b49","warm_compaction/plugin.yaml": "d67560fd4625ec80d9e26f3e6d712763e77474f68d469c7e48f09fd3506ccc71","warm_compaction/rows.py": "1eb0a043c060322769ad0e2533b3f1b30d5258f125502752d18b8a94c1006347","warm_compaction/warm.py": "fe1f1b2e065f7198586979455ab54ed7dfd20d144b3751c3451d3cf6a70480e4"@@ -76,7 +76,7 @@"threshold_tokens": 100000,"context_length": 200000},- "compress_seconds": 0.097,+ "compress_seconds": 0.102,"warm_last": {"path": "warm","reason": "accepted",@@ -88,11 +88,10 @@"final_session_id": "wc-enable_manual_warm","continuation_keeps_custom_system_text": false,"fence_denied": {- "child_process_blocked": 4,- "network_host_blocked": 1+ "network_host_blocked": 1,+ "child_process_blocked": 3},"fence_blocked_programs": [- "git","pip","python","python3"@@ -101,7 +100,6 @@"hermes-assets.nousresearch.com"],"fence_blocked_callers": [- "child_process_blocked from hermes_cli/source_check.py:_git_run < hermes_cli/source_check.py:_git_stdout < hermes_cli/source_check.py:_read_checkout","child_process_blocked from tools/env_probe.py:_run < tools/env_probe.py:_py_out < tools/env_probe.py:_pip_python_version","child_process_blocked from tools/env_probe.py:_run < tools/env_probe.py:_py_out < tools/env_probe.py:_python_version_of","network_host_blocked from hermes_cli/release_channels.py:read < hermes_cli/release_channels.py:read_bytes < hermes_cli/release_channels.py:read_record"@@ -189,7 +187,7 @@"install","run"],- "process_seconds": 56.281+ "process_seconds": 53.772},{"scenario": "manual_fallback",@@ -248,11 +246,11 @@"threshold_tokens": 100000,"context_length": 200000},- "compress_seconds": 0.264,+ "compress_seconds": 0.248,"warm_last": {"path": "fallback","reason": "provider_error",- "elapsed_s": 0.141,+ "elapsed_s": 0.109,"prompt_tokens": null,"cached_tokens": null},@@ -361,7 +359,7 @@"install","run"],- "process_seconds": 33.064+ "process_seconds": 32.85},{"scenario": "manual_fixed",@@ -419,11 +417,11 @@"threshold_tokens": 100000,"context_length": 200000},- "compress_seconds": 0.271,+ "compress_seconds": 0.239,"warm_last": {"path": "fixed","reason": "provider_error",- "elapsed_s": 0.141,+ "elapsed_s": 0.11,"prompt_tokens": null,"cached_tokens": null},@@ -431,7 +429,7 @@"final_session_id": "wc-manual_fixed","continuation_keeps_custom_system_text": false,"fence_denied": {- "child_process_blocked": 6,+ "child_process_blocked": 4,"network_host_blocked": 1},"fence_blocked_programs": [@@ -532,7 +530,7 @@"install","run"],- "process_seconds": 30.49+ "process_seconds": 30.447},{"scenario": "auto_tool_loop",@@ -620,21 +618,21 @@"warm_last_1": {"path": "warm","reason": "accepted",- "elapsed_s": 0.015,+ "elapsed_s": 0.016,"prompt_tokens": 35209,"cached_tokens": 17604},"warm_last_2": {"path": "warm","reason": "accepted",- "elapsed_s": 0.016,+ "elapsed_s": 0.0,"prompt_tokens": 19504,"cached_tokens": 9752},"compression_count": 2,"fence_denied": {- "child_process_blocked": 8,- "network_host_blocked": 1+ "network_host_blocked": 1,+ "child_process_blocked": 7},"fence_blocked_programs": ["git",@@ -648,7 +646,6 @@"fence_blocked_callers": ["child_process_blocked from hermes_cli/local_runtime/processes.py:spawn_server < hermes_cli/_subprocess_compat.py:bounded_probe_run < hermes_cli/_subprocess_compat.py:bounded_git_probe","child_process_blocked from hermes_cli/local_runtime/processes.py:spawn_server < hermes_cli/_subprocess_compat.py:bounded_probe_run < hermes_cli/_subprocess_compat.py:noninteractive_repo_git_env",- "child_process_blocked from hermes_cli/source_check.py:_git_run < hermes_cli/source_check.py:_git_stdout < hermes_cli/source_check.py:_read_checkout","child_process_blocked from tools/env_probe.py:_run < tools/env_probe.py:_py_out < tools/env_probe.py:_pip_python_version","child_process_blocked from tools/env_probe.py:_run < tools/env_probe.py:_py_out < tools/env_probe.py:_python_version_of","network_host_blocked from hermes_cli/release_channels.py:read < hermes_cli/release_channels.py:read_bytes < hermes_cli/release_channels.py:read_record"@@ -737,7 +734,7 @@"install","run"],- "process_seconds": 33.176+ "process_seconds": 33.594},{"scenario": "rollback",@@ -787,11 +784,11 @@"threshold_tokens": 100000,"context_length": 200000},- "compress_seconds": 0.158,+ "compress_seconds": 0.136,"warm_last": {"path": "warm","reason": "accepted",- "elapsed_s": 0.015,+ "elapsed_s": 0.016,"prompt_tokens": 33882,"cached_tokens": 16941},@@ -799,7 +796,7 @@"final_session_id": "wc-rollback","continuation_keeps_custom_system_text": false,"fence_denied": {- "child_process_blocked": 4,+ "child_process_blocked": 5,"network_host_blocked": 1},"fence_blocked_programs": [@@ -950,8 +947,7 @@"stored": 30},"fence_denied": {- "child_process_blocked": 5,- "network_host_blocked": 1+ "child_process_blocked": 5},"fence_blocked_programs": ["git",@@ -959,9 +955,7 @@"python","python3"],- "fence_blocked_hosts": [- "hermes-assets.nousresearch.com"- ]+ "fence_blocked_hosts": []},"exit": [0,@@ -973,10 +967,10 @@"run","rollback"],- "process_seconds": 40.153+ "process_seconds": 38.756}],- "finished_utc": "2026-10-06T16:16:02Z",+ "finished_utc": "2026-10-06T16:30:35Z","passed": true,"run_folder": "outside repository"}diff --git a/tests/test_wc_layout.py b/tests/test_wc_layout.pyindex 15392e0..a70b654 100644--- a/tests/test_wc_layout.py+++ b/tests/test_wc_layout.py@@ -168,6 +168,15 @@ class AttachmentAndPrependTest(unittest.TestCase):prefixes=PREFIXES, end_marker=END, copy_tokens=105)self.assertNotIn("older ask", new[1]["content"])+ def test_the_prepended_row_counts_in_the_copy_budget_as_hermes_sends_it(self):+ # Hermes sends api_content in place of content: the stored display text does not use the copy budget.+ rows = [user("older ask"), assistant("a"), user("shown " + "d" * 4_000, api_content="do it " + "x" * 400),+ assistant("", [("c1", "f", "{}")]), tool("c1", "r")]+ prepend = {"role": "user", "content": rows[2]["content"], "api_content": rows[2]["api_content"]}+ new = build(rows, "S", start=3, prepend=prepend, copy_chars=10_000, header_prefix="[HERMES PREFIX]",+ prefixes=PREFIXES, end_marker=END, copy_tokens=1_000)+ self.assertIn("> older ask", new[1]["content"])+class BoundTailTest(unittest.TestCase):def test_a_newest_unit_larger_than_the_tail_is_cut(self):diff --git a/warm_compaction/engine.py b/warm_compaction/engine.pyindex 9db1896..d48dc3b 100644--- a/warm_compaction/engine.py+++ b/warm_compaction/engine.py@@ -11,7 +11,7 @@ from agent.context_engine import ContextEnginefrom . import fallback, handoff, layout, warmfrom .capture import CaptureStore-from .rows import SendPolicy, api_content, attr, estimate_tokens, hermes_value, sent_rows+from .rows import SendPolicy, api_content, attr, estimate_tokens, hermes_value, sent_rows, sent_tokenslogger = logging.getLogger(__name__)@@ -281,7 +281,7 @@ class WarmCompactionEngine(ContextEngine):cut: list = []if prepend is not None and room is not None:allowed = room if overhead is not None else 0- if estimate_tokens(prepend) > allowed:+ if sent_tokens(prepend, policy) > allowed:if record["path"] != "fixed":# A model summary had the whole row (in the warm request, or in the fallback transcript).prepend = layout.fit_user_row(prepend, allowed)@@ -290,7 +290,7 @@ class WarmCompactionEngine(ContextEngine):# summary as a quote. The room keeps space for that quote.prepend = layout.fit_user_row(prepend, allowed - fallback.CUT_QUOTE_CHARS // 4, cut)summary = fallback.fixed_summary([*messages[:start], *removed, *cut], prefixes)- prepend_tokens = estimate_tokens(prepend) if prepend is not None else 0+ prepend_tokens = sent_tokens(prepend, policy) if prepend is not None else 0tail_tokens = self._tail_cap(estimate_tokens(summary), overhead, reserve, prepend_tokens)if record["path"] == "fixed":# The fixed summary quotes what the tail cuts: cut and quote at the same cap. A larger summary makes adiff --git a/warm_compaction/layout.py b/warm_compaction/layout.pyindex 579c5fd..1e4ec40 100644--- a/warm_compaction/layout.py+++ b/warm_compaction/layout.py@@ -382,7 +382,8 @@ def build(messages: list, summary_text: str, *, start: int, prepend: dict[str, Alast = max((index for index, row in enumerate(earlier) if is_real_user(row, prefixes)), default=len(earlier))earlier = earlier[:last]if copy_tokens is not None:- copy_tokens = max(copy_tokens - estimate_tokens(prepend), 0)+ # As Hermes sends it: api_content in place of the stored display text.+ copy_tokens = max(copy_tokens - sent_tokens(prepend, policy), 0)copies = copied_user_messages(earlier, copy_chars, prefixes, copy_tokens)body = summary_body(summary_text, copies, end_marker)tail = [_tail_row(row, marker) for row in messages[start:]]