mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-16 19:04:08 +03:00
54a95b679c
A flattened [USER]: transcript lets tool output that prints a fake user turn pass for the user, so the summary carries a forged approval forward as the user's (arXiv:2610.29869, #146750). Lean mode now sends real user turns as role=user, assistant tool calls as tool_calls and tool output as role=tool messages (pairing repaired, no tools param), with the instructions in the system slot and a final user pointer. The summary-input sampler moves to context_compressor_sampling.py (unchanged) to keep context_compressor.py under its line ratchet; it now also reports which record runs it kept so the typed builder sends exactly the sampled records.
66 lines
2.7 KiB
Python
66 lines
2.7 KiB
Python
"""Task-snapshot heading identity across the summarizer prompt, the template, and grounding.
|
|
|
|
The iterative-update instruction, the emitted template, and ``_ground_historical_task_snapshot`` must agree on
|
|
one heading. A leftover ``## Active Task`` section is not disclaimed by SUMMARY_PREFIX and reads as live work,
|
|
so grounding must replace it (and any duplicate task section) rather than prepend a second one.
|
|
"""
|
|
|
|
from unittest.mock import patch
|
|
|
|
from agent.context_compressor import ContextCompressor, HISTORICAL_TASK_HEADING
|
|
|
|
_LEGACY_ACTIVE_TASK_HEADING = "## Active Task"
|
|
|
|
|
|
def _headings(text: str) -> list[str]:
|
|
return [line for line in text.splitlines() if line.startswith("## ")]
|
|
|
|
|
|
|
|
|
|
def test_grounding_collapses_alias_and_duplicate_task_sections():
|
|
"""A summarizer that emits the legacy alias, or both headings, ends up with exactly one grounded section."""
|
|
body = (
|
|
f"{HISTORICAL_TASK_HEADING}\nUser asked: 'stale canonical'\n\n"
|
|
"## Goal\nthing\n\n"
|
|
f"{_LEGACY_ACTIVE_TASK_HEADING}\nUser asked: 'stale alias'\n\n"
|
|
"## Constraints & Preferences\n- none\n"
|
|
)
|
|
grounded = ContextCompressor._ground_historical_task_snapshot.__func__(
|
|
ContextCompressor, body, [{"role": "user", "content": "fresh ask"}]
|
|
)
|
|
|
|
headings = _headings(grounded)
|
|
assert headings.count(HISTORICAL_TASK_HEADING) == 1
|
|
assert _LEGACY_ACTIVE_TASK_HEADING not in headings
|
|
assert headings[1:] == ["## Goal", "## Constraints & Preferences"]
|
|
assert "fresh ask" in grounded
|
|
assert "stale" not in grounded
|
|
|
|
|
|
def test_long_user_request_is_not_quoted_by_summary_model():
|
|
"""Long quotes stall Codex output; the postprocessor preserves source wording."""
|
|
with patch("agent.context_compressor.get_model_context_length", return_value=100000):
|
|
compressor = ContextCompressor(model="test", quiet_mode=True)
|
|
section = "\n".join(m["content"] for m in compressor._build_summary_prompt(
|
|
"A long user request", 500, None, "", True
|
|
))
|
|
assert "summarize it in your own words rather than copying long" in section
|
|
for removed_directive in (
|
|
"input verbatim — the exact words",
|
|
"<exact latest user request>",
|
|
"write the reverse signal verbatim",
|
|
):
|
|
assert removed_directive not in section
|
|
|
|
latest_request = "Please check this issue carefully. " * 20
|
|
generated = (
|
|
f"{HISTORICAL_TASK_HEADING}\nUser asked for an issue check\n\n"
|
|
"## Goal\nCheck an issue"
|
|
)
|
|
grounded = ContextCompressor._ground_historical_task_snapshot(
|
|
generated, [{"role": "user", "content": latest_request}]
|
|
)
|
|
assert latest_request.strip() in grounded
|
|
assert "## Goal\nCheck an issue" in grounded
|