Hermes Agent context engine: the main model writes the compaction handoff on its cached prompt prefix
Keep both ends of long copied messages and send no name on tool rows
Elevatormusicf62f3142f471
diff --git a/evidence/plugin-integration.json b/evidence/plugin-integration.jsonindex 3479b10..2a637b0 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-06T09:00:36Z",+ "started_utc": "2026-10-06T09:14:35Z","hermes": {"commit": "45871e100feceb89769536c88e5e6e265226a409","clean": true@@ -11,12 +11,12 @@"warm_compaction/__init__.py": "11e038f05813627b2d1d8b82b3b775ecfe41015746c8e90ed6d452cfdaec65a6","warm_compaction/capture.py": "9d6414ec2dc552a01d7ba0ab84009ee30a363d57b9a061c2b5d9bc699c0efb75","warm_compaction/engine.py": "83e2434a172a540e7e21053fd8da6d7204bc8eacadab1809213095821b362b96",- "warm_compaction/fallback.py": "5997b3c96ad7bbdaa4f505ffb470aa850c7c7afd33630f02823b3fdda6c46339",+ "warm_compaction/fallback.py": "b5ccd56550381fc8033351156cbf2dcf0a7e667f8f9bbf0d15bb2101f3abb97e","warm_compaction/handoff.py": "2fcdc2af2eba2d36eaabfef912ce0dd6d64bccc7849849e6411869a0025a06c2",- "warm_compaction/layout.py": "fd4d260380ce2cc44aa846758762a05bb4737c10677bceec0b17fd3c59c943f5",+ "warm_compaction/layout.py": "84673bd98710416599b3718071dcc24e0c230e4845cdbffb47fd743b2a21f423","warm_compaction/plugin.yaml": "d67560fd4625ec80d9e26f3e6d712763e77474f68d469c7e48f09fd3506ccc71",- "warm_compaction/rows.py": "c0c0b7cfc5bebfa9caa58e9621ff3eda0db108c7976ca769da159be13574874b",- "warm_compaction/warm.py": "536c9b208a5540bf7309a2f4bdf366faebc01b4045c6b63a2191e84762259dc5"+ "warm_compaction/rows.py": "cc2a8a3d0561559f24fc40881453441d938ea9d7803e1df81a107a5e05e5f00a",+ "warm_compaction/warm.py": "f765fb622ac9b6558eafc9b14179abffbd862a9fa42e542a2908ec2a862e8019"},"privacy": "metadata only: names, counts, codes, booleans, and times; no message text","scenarios": [@@ -75,11 +75,11 @@"threshold_tokens": 100000,"context_length": 200000},- "compress_seconds": 0.113,+ "compress_seconds": 0.099,"warm_last": {"path": "warm","reason": "accepted",- "elapsed_s": 0.023,+ "elapsed_s": 0.02,"prompt_tokens": 33883,"cached_tokens": 16941},@@ -87,10 +87,11 @@"final_session_id": "wc-enable_manual_warm","continuation_keeps_custom_system_text": false,"fence_denied": {- "network_host_blocked": 1,- "child_process_blocked": 3+ "child_process_blocked": 4,+ "network_host_blocked": 1},"fence_blocked_programs": [+ "git","pip","python","python3"@@ -99,6 +100,7 @@"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"@@ -186,7 +188,7 @@"install","run"],- "process_seconds": 82.046+ "process_seconds": 54.25},{"scenario": "manual_fallback",@@ -245,11 +247,11 @@"threshold_tokens": 100000,"context_length": 200000},- "compress_seconds": 0.274,+ "compress_seconds": 0.245,"warm_last": {"path": "fallback","reason": "provider_error",- "elapsed_s": 0.125,+ "elapsed_s": 0.093,"prompt_tokens": null,"cached_tokens": null},@@ -257,11 +259,10 @@"final_session_id": "wc-manual_fallback","continuation_keeps_custom_system_text": false,"fence_denied": {- "child_process_blocked": 5,- "network_host_blocked": 1+ "network_host_blocked": 1,+ "child_process_blocked": 3},"fence_blocked_programs": [- "git","pip","python","python3"@@ -270,7 +271,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"@@ -358,7 +358,7 @@"install","run"],- "process_seconds": 60.664+ "process_seconds": 32.746},{"scenario": "manual_fixed",@@ -416,11 +416,11 @@"threshold_tokens": 100000,"context_length": 200000},- "compress_seconds": 0.258,+ "compress_seconds": 0.243,"warm_last": {"path": "fixed","reason": "provider_error",- "elapsed_s": 0.094,+ "elapsed_s": 0.125,"prompt_tokens": null,"cached_tokens": null},@@ -428,7 +428,7 @@"final_session_id": "wc-manual_fixed","continuation_keeps_custom_system_text": false,"fence_denied": {- "child_process_blocked": 5,+ "child_process_blocked": 4,"network_host_blocked": 1},"fence_blocked_programs": [@@ -529,7 +529,7 @@"install","run"],- "process_seconds": 34.137+ "process_seconds": 29.783},{"scenario": "auto_tool_loop",@@ -615,21 +615,21 @@"warm_last_1": {"path": "warm","reason": "accepted",- "elapsed_s": 0.032,- "prompt_tokens": 35205,- "cached_tokens": 17602+ "elapsed_s": 0.0,+ "prompt_tokens": 35201,+ "cached_tokens": 17600},"warm_last_2": {"path": "warm","reason": "accepted",- "elapsed_s": 0.0,- "prompt_tokens": 18211,- "cached_tokens": 9105+ "elapsed_s": 0.016,+ "prompt_tokens": 18206,+ "cached_tokens": 9103},"compression_count": 2,"fence_denied": {- "network_host_blocked": 1,- "child_process_blocked": 7+ "child_process_blocked": 8,+ "network_host_blocked": 1},"fence_blocked_programs": ["git",@@ -643,6 +643,7 @@"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"@@ -731,7 +732,7 @@"install","run"],- "process_seconds": 35.194+ "process_seconds": 33.775},{"scenario": "rollback",@@ -781,7 +782,7 @@"threshold_tokens": 100000,"context_length": 200000},- "compress_seconds": 0.156,+ "compress_seconds": 0.151,"warm_last": {"path": "warm","reason": "accepted",@@ -967,10 +968,10 @@"run","rollback"],- "process_seconds": 40.061+ "process_seconds": 38.191}],- "finished_utc": "2026-10-06T09:04:48Z",+ "finished_utc": "2026-10-06T09:17:44Z","passed": true,"run_folder": "outside repository"}diff --git a/tests/test_wc_layout.py b/tests/test_wc_layout.pyindex 782a60a..26ae98b 100644--- a/tests/test_wc_layout.py+++ b/tests/test_wc_layout.py@@ -70,7 +70,14 @@ class TailTest(unittest.TestCase):class CopyTest(unittest.TestCase):def test_copies_the_newest_messages_in_order_and_cuts_each(self):rows = [user("a" * 10), user("b" * (COPY_EACH + 50)), assistant("x"), user("c" * 10)]- self.assertEqual(copied_user_messages(rows, COPY_EACH + 15, PREFIXES), ["b" * COPY_EACH, "c" * 10])+ copies = copied_user_messages(rows, COPY_EACH + 15, PREFIXES)+ self.assertEqual((len(copies[0]), copies[1]), (COPY_EACH, "c" * 10))++ def test_a_long_copy_keeps_its_start_and_its_end(self):+ text = "start " + "x" * 5_000 + " the real question"+ [copy] = copied_user_messages([user(text)], 24_000, PREFIXES)+ self.assertTrue(copy.startswith("start ") and copy.endswith(" the real question"))+ self.assertLessEqual(len(copy), COPY_EACH)def test_copies_stay_inside_the_token_budget(self):# Six 4,000-character CJK messages are about 24,000 tokens. A 5,000-token budget keeps one.diff --git a/tests/test_wc_warm.py b/tests/test_wc_warm.pyindex ec39cce..c9f2629 100644--- a/tests/test_wc_warm.py+++ b/tests/test_wc_warm.py@@ -85,8 +85,10 @@ class WireRowTest(unittest.TestCase):row = assistant(None, [("c1", "read", {"path": "a b"})], reasoning="r", _db_persisted=True)self.assertEqual(wire_row(row), {"role": "assistant", "content": None, "tool_calls": [{"id": "c1", "type": "function", "function": {"name": "read", "arguments": "{\"path\":\"a b\"}"}}]})+ # The Hermes transport removes the name from tool rows; strict providers reject it there.self.assertEqual(wire_row(tool("c1", "out", name="read")),- {"role": "tool", "content": "out", "tool_call_id": "c1", "name": "read"})+ {"role": "tool", "content": "out", "tool_call_id": "c1"})+ self.assertEqual(wire_row(user("hi", name="alice")), {"role": "user", "content": "hi", "name": "alice"})def test_sends_the_api_content_of_user_and_assistant_rows(self):self.assertEqual(wire_row(user("hi", api_content="ctx\n\nhi")), {"role": "user", "content": "ctx\n\nhi"})diff --git a/warm_compaction/fallback.py b/warm_compaction/fallback.pyindex 583333d..7a83fb3 100644--- a/warm_compaction/fallback.py+++ b/warm_compaction/fallback.py@@ -8,7 +8,8 @@ from typing import Any, Iterablefrom .handoff import END_MARKER, LEGACY_PREFIX, extras, gatefrom .layout import is_real_user, is_summary-from .rows import (+from .rows import ( # noqa: F401 - MIDDLE_MARK is part of this module's names.+ MIDDLE_MARK, cut_middle as _cut_middle,api_content, attr, compact_json, estimate_tokens, plain_text, strip_think, tool_calls_of, visible_text,)@@ -25,7 +26,6 @@ TOOL_CHARS = 1_000ARGUMENT_CHARS = 300CUT_MARK = " [cut]"ROW_CHARS = 4_000-MIDDLE_MARK = " [cut] "MIN_PART_CHARS = 200# Token limits for dense text (CJK text, emoji): the character limits divided by 4. ASCII text meets the two# limits at about the same point; dense text meets the token limit first, so a small fallback model can read it.@@ -72,17 +72,6 @@ def _cut(text: str, limit: int) -> str:return text if len(text) <= limit else text[:limit] + CUT_MARK-def _cut_middle(text: str, limit: int) -> str:- """Return at most limit characters: the start (two thirds) and the end of the text, with a mark between."""- if len(text) <= limit:- return text- keep = limit - len(MIDDLE_MARK)- if keep < 2:- return text[:max(limit, 0)]- head = keep * 2 // 3- return text[:head] + MIDDLE_MARK + text[len(text) - (keep - head):]--def _bound(text: str, chars: int, tokens: int, middle: bool = False) -> str:"""Cut the text to at most chars characters and about tokens estimated tokens. A character is at mostone estimated token, so a cut to tokens characters meets the token limit."""diff --git a/warm_compaction/layout.py b/warm_compaction/layout.pyindex 2d6cb11..477e5cd 100644--- a/warm_compaction/layout.py+++ b/warm_compaction/layout.py@@ -7,7 +7,7 @@ import functoolsfrom typing import Any, Iterablefrom .handoff import END_MARKER, LEGACY_PREFIX-from .rows import api_content, attr, estimate_tokens, hermes_value, plain_text, visible_text+from .rows import api_content, attr, cut_middle, estimate_tokens, hermes_value, plain_text, visible_textHEADER_TEXT = "The summary of the earlier turns follows."COPY_HEADING = "## Copied user messages"@@ -143,15 +143,16 @@ def tail_start(messages: list, tail_tokens: int, prefixes: Iterable[str]) -> tupdef copied_user_messages(messages: list, total_chars: int, prefixes: Iterable[str],max_tokens: int | None = None) -> list[str]:"""Return the newest real user messages that fit in total_chars and in max_tokens (estimated), each cut- to COPY_EACH characters. Each copy is the text that Hermes sent (api_content when the row has it). The token- limit counts the quoted form and keeps dense text, such as CJK text, inside the window."""+ to COPY_EACH characters (its start and its end). Each copy is the text that Hermes sent (api_content when+ the row has it). The token limit counts the quoted form and keeps dense text, such as CJK text, inside the+ window."""prefixes = tuple(prefixes)chosen: list[str] = []used = tokens = 0for row in reversed(messages):if not is_real_user(row, prefixes):continue- text = visible_text(api_content(row)).strip()[:COPY_EACH]+ text = cut_middle(visible_text(api_content(row)).strip(), COPY_EACH)cost = estimate_tokens(quote(text))if used + len(text) > total_chars or (max_tokens is not None and tokens + cost > max_tokens):breakdiff --git a/warm_compaction/rows.py b/warm_compaction/rows.pyindex 9c498fc..960d2ca 100644--- a/warm_compaction/rows.py+++ b/warm_compaction/rows.py@@ -96,6 +96,21 @@ def visible_text(content: Any) -> str:return "\n".join(lines)+MIDDLE_MARK = " [cut] "+++def cut_middle(text: str, limit: int) -> str:+ """Return at most limit characters: the start (two thirds) and the end of the text, with a mark between.+ The end of a long text often has the result, the question, or the output rules."""+ if len(text) <= limit:+ return text+ keep = limit - len(MIDDLE_MARK)+ if keep < 2:+ return text[:max(limit, 0)]+ head = keep * 2 // 3+ return text[:head] + MIDDLE_MARK + text[len(text) - (keep - head):]++def strip_think(text: str) -> str:"""Remove one leading <think>...</think> block and the white space around it."""return THINK_BLOCK.sub("", text, count=1)diff --git a/warm_compaction/warm.py b/warm_compaction/warm.pyindex 2f4f75e..571f3c1 100644--- a/warm_compaction/warm.py+++ b/warm_compaction/warm.py@@ -223,7 +223,8 @@ def wire_row(row: Any, reasoning_echo: bool = False, model: Any = None, base_urlwire: dict[str, Any] = {"role": attr(row, "role"), "content": copy.deepcopy(api_content(row))}for key in ("tool_call_id", "name"):value = attr(row, key)- if value is not None:+ # The Hermes transport removes the name from tool rows; strict providers reject it there.+ if value is not None and not (key == "name" and attr(row, "role") == "tool"):wire[key] = valuecalls = tool_calls_of(row)if calls: