Skip to content

The agent that grows with you

perf(prompt): move the profile line out of the stable cache tier

teknium1f29163388c0d
diff --git a/agent/system_prompt.py b/agent/system_prompt.py
index f8e7a3c789a..07d33c87d6e 100644
--- a/agent/system_prompt.py
+++ b/agent/system_prompt.py
@@ -696,7 +696,7 @@ def _coding_parts(agent: Any) -> Tuple[List[str], List[str], List[str]]:
def _post_workspace_parts(agent: Any) -> List[str]:
"""Blocks that follow the worktree-specific context: environment probe
(config.yaml agent.environment_probe; one line, nothing when clean, skipped
- for remote backends), bot-mode protocol, profile line, platform hint."""
+ for remote backends), bot-mode protocol, platform hint."""
parts: List[str] = []
if getattr(agent, "_environment_probe", True):
try:
@@ -706,7 +706,7 @@ def _post_workspace_parts(agent: Any) -> List[str]:
pass # Probe failure must never block prompt build.
if getattr(agent, "_bot_mode_protocol", True):
parts.extend(_bot_mode_parts(agent))
- parts += [_active_profile_line(agent), platform_hint(agent)]
+ parts.append(platform_hint(agent))
return parts
@@ -784,6 +784,9 @@ def build_system_prompt_parts(agent: Any, system_message: Optional[str] = None)
# Plugin sections are confined to one coarse anchor in the volatile tail so
# a resumed process can reconstruct the stable prefix without re-running plugins.
volatile_parts.extend(_plugin_section_blocks(_frozen_plugin_prompt_sections(agent), "after_memory"))
+ # The profile line names this home's path, so it rides in the volatile tier: the stable
+ # prefix then stays byte-identical across every profile (and home) on the host.
+ volatile_parts.append(_active_profile_line(agent))
volatile_parts.append(_timestamp_line(agent))
# Keep the renderer-owned runtime anchor after all user/plugin prose so quoted
# host examples cannot shadow it during persisted-prompt validation.
diff --git a/tests/agent/test_system_prompt.py b/tests/agent/test_system_prompt.py
index 3b15d19c9fd..466ab7c03ad 100644
--- a/tests/agent/test_system_prompt.py
+++ b/tests/agent/test_system_prompt.py
@@ -483,6 +483,23 @@ class TestNamedProfileHintIntegration:
assert f"under {root}/profiles/<name>/." in prompt
+def test_stable_tier_is_identical_across_homes(tmp_path, monkeypatch):
+ """The profile line names the home path, so it must live outside the stable tier:
+ every home/profile on a host then shares one cacheable stable prefix."""
+ monkeypatch.delenv("TERMINAL_CWD", raising=False)
+ tiers = []
+ for name in ("a", "b"):
+ root = tmp_path / name / ".hermes"
+ root.mkdir(parents=True)
+ monkeypatch.setattr(Path, "home", lambda root=root: root.parent)
+ monkeypatch.setenv("HERMES_HOME", str(root))
+ with patch("agent.coding_context._coding_mode", return_value="off"):
+ parts = _prompt_parts(_make_agent(valid_tool_names=["read_file"]))
+ assert f"under {root}/profiles/<name>/." in parts["volatile"]
+ tiers.append(parts["stable"])
+ assert tiers[0] == tiers[1]
+
+
def test_build_system_prompt_records_stable_prefix():
agent = _make_agent()
with (