The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): catch "can not" and "summarise" in the summary-refusal detector
kshitijk4poord5159aa31d24
diff --git a/agent/context_compressor.py b/agent/context_compressor.pyindex 09e887dc290..ae9a8a8fefc 100644--- a/agent/context_compressor.py+++ b/agent/context_compressor.py@@ -169,7 +169,7 @@ _TRUNCATED_SUMMARY_MARKER = "finish_reason=length"_SUMMARY_REFUSAL_PREFIX_RE = re.compile(r"^\s*(?:(?:sorry|i(?:['’]m| am)\s+sorry|i\s+apologi[sz]e|as\s+an\s+ai)"r"\s*[,;:]?\s*(?:but\s+)?)?(?:i|we)\s+"- r"(?:can(?:not|['’]t)|could\s*not|couldn['’]t|won['’]t|will\s+not|must\s+decline|"+ r"(?:can(?:\s*not|['’]t)|could\s*not|couldn['’]t|won['’]t|will\s+not|must\s+decline|"r"refuse\s+to|am\s+unable\s+to|am\s+not\s+able\s+to)\b"r"|^\s*(?:i['’]?m|i\s+am)\s+(?:unable|not\s+able)\b",re.IGNORECASE,@@ -182,8 +182,8 @@ def _is_summary_refusal(content: str) -> bool:if not _SUMMARY_REFUSAL_PREFIX_RE.match(normalized):return False# Limit the search to the opener so a structured checkpoint that records a- # historical refusal elsewhere is not rejected.- return any(term in normalized[:400].casefold() for term in ("summary", "summarize", "checkpoint"))+ # historical refusal elsewhere is not rejected. Stems catch summary/summarize/summarise.+ return any(term in normalized[:400].casefold() for term in ("summar", "checkpoint"))def _response_refusal_text(response: Any) -> str:diff --git a/tests/agent/test_compressor_truncated_summary_guard.py b/tests/agent/test_compressor_truncated_summary_guard.pyindex 3cff864dc83..03a8e4ae5d6 100644--- a/tests/agent/test_compressor_truncated_summary_guard.py+++ b/tests/agent/test_compressor_truncated_summary_guard.py@@ -69,6 +69,8 @@ class TestSummaryRefusalGuard:"I’m sorry, but I can’t provide the requested summary.","I apologize, but I cannot create a summary of this conversation.","As an AI, I cannot provide the requested context checkpoint.",+ "I can not provide a summary of this conversation.",+ "I can't summarise this conversation for you.",],)def test_rejects_refusal_body(self, content):