The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): do not reject a preambled real summary as a refusal
kshitijk4poor94fbc155ec2e
diff --git a/agent/context_compressor.py b/agent/context_compressor.pyindex ae9a8a8fefc..8b947a5cbc2 100644--- a/agent/context_compressor.py+++ b/agent/context_compressor.py@@ -181,6 +181,10 @@ def _is_summary_refusal(content: str) -> bool:normalized = " ".join(content.split())if not _SUMMARY_REFUSAL_PREFIX_RE.match(normalized):return False+ # A refusal-only body never carries the template's "## " section headings; a real summary+ # that merely opens with a hedging preamble ("I cannot see earlier turns, but here is...") does.+ if re.search(r"(?m)^##\s", content):+ return False# Limit the search to the opener so a structured checkpoint that records a# historical refusal elsewhere is not rejected. Stems catch summary/summarize/summarise.return any(term in normalized[:400].casefold() for term in ("summar", "checkpoint"))diff --git a/tests/agent/test_compressor_truncated_summary_guard.py b/tests/agent/test_compressor_truncated_summary_guard.pyindex 03a8e4ae5d6..28ca402ad06 100644--- a/tests/agent/test_compressor_truncated_summary_guard.py+++ b/tests/agent/test_compressor_truncated_summary_guard.py@@ -80,6 +80,16 @@ class TestSummaryRefusalGuard:summary = "## Goal\nPreserve the user's task.\n\n## Completed Actions\n1. Recorded that a provider refused an earlier request."assert _is_summary_refusal(summary) is False+ def test_narrowing_and_heading_exemption(self):+ # Narrow by design: a refusal that never mentions the summary/checkpoint is not ours to judge.+ assert _is_summary_refusal("I can't help with that request.") is False+ # A hedging preamble in front of a real templated summary is not a refusal.+ preamble = (+ "I cannot see the earlier turns, but here is the summary:\n"+ "## Goal\nFinish the task.\n\n## Completed Actions\n1. Did X."+ )+ assert _is_summary_refusal(preamble) is False+class TestGenerateSummaryTruncationGuard:def test_length_stop_is_rejected_and_aborts(self):