The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(compression): avoid long verbatim task quotes in summaries
Charan Rathoref7be32556dc8
diff --git a/agent/context_compressor.py b/agent/context_compressor.pyindex 0e7a6a9f938..fef4269ec14 100644--- a/agent/context_compressor.py+++ b/agent/context_compressor.py@@ -1996,8 +1996,12 @@ _SECTION_INSTRUCTIONS: Dict[bool, Dict[str, str]] = {"Write the summary in the same language the user was using in the ""conversation — do not translate or switch to English. "),- "historical_task": """[THE SINGLE MOST IMPORTANT FIELD. Capture the user's most recent unfulfilled-input verbatim — the exact words they used. This includes:+ "historical_task": """[THE SINGLE MOST IMPORTANT FIELD. Identify the user's most recent unfulfilled+input precisely, but summarize it in your own words rather than copying long+passages from the transcript. The compressor inserts a bounded, redacted+snapshot of the real latest user turn after generation, so the model must not+reproduce it.+This includes:- Explicit task assignments ("<specific user task>")- Questions awaiting an answer ("<specific user question>")- Decisions awaiting input ("<option A or B?>")@@ -2009,14 +2013,14 @@ rare case where the last exchange was fully resolved and the user saidsomething like "thanks, that's all".If multiple items are outstanding, list only the ones NOT yet completed.This historical snapshot must identify the latest unresolved user input precisely. Examples:-"User asked: '<exact latest user request>'"-"User asked: '<exact latest user question>' — needs investigation + answer"+"User asked for <specific task and constraints>"+"User asked <specific question> — needs investigation + answer""User chose <option>; awaiting implementation of <specific next step>"If the user's most recent message was a reverse signal (stop, undo, rollback, never mind, just verify, change of topic) that supersedes earlier-work, write the reverse signal verbatim and DO NOT carry forward the-cancelled task. Example: "User asked: '<exact reverse signal>' — earlier-in-flight work is cancelled."+work, describe the reverse signal accurately and DO NOT carry forward the+cancelled task. The compressor inserts the source-grounded snapshot afterward.+Example: "User asked to stop the prior task — earlier work is cancelled."If no outstanding task exists, write "None."]""","goal": "[What the user is trying to accomplish overall]","constraints": (diff --git a/tests/agent/test_context_compressor_task_heading.py b/tests/agent/test_context_compressor_task_heading.pyindex bc6774b9195..1cbc34db74b 100644--- a/tests/agent/test_context_compressor_task_heading.py+++ b/tests/agent/test_context_compressor_task_heading.py@@ -35,3 +35,27 @@ def test_grounding_collapses_alias_and_duplicate_task_sections():assert headings[1:] == ["## Goal", "## Constraints & Preferences"]assert "fresh ask" in groundedassert "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."""+ from unittest.mock import patch++ with patch("agent.context_compressor.get_model_context_length", return_value=100000):+ compressor = ContextCompressor(model="test", quiet_mode=True)+ section = compressor._build_summary_prompt(+ "A long user request", 500, None, "", True+ )+ assert "summarize it in your own words rather than copying long" in section+ assert "input verbatim — the exact words" 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.__func__(+ ContextCompressor, generated, [{"role": "user", "content": latest_request}]+ )+ assert latest_request.strip() in grounded+ assert "## Goal\nCheck an issue" in grounded