diff --git a/agent/turn_context.py b/agent/turn_context.py index fc06b4b4acf5..80dd7ee2060d 100644 --- a/agent/turn_context.py +++ b/agent/turn_context.py @@ -36,6 +36,7 @@ from agent.conversation_compression import ( PREFLIGHT_COMPRESSION_STATUS_TEMPLATE, conversation_history_after_compression, ) +from agent.context_engine import automatic_compaction_status_message from agent.iteration_budget import IterationBudget from agent.memory_manager import build_memory_context_block from agent.model_metadata import ( @@ -772,12 +773,20 @@ def build_turn_context( agent.model, f"{_compressor.context_length:,}", ) - agent._emit_status( - PREFLIGHT_COMPRESSION_STATUS_TEMPLATE.format( + _preflight_status = automatic_compaction_status_message( + _compressor, + phase="preflight", + default_message=PREFLIGHT_COMPRESSION_STATUS_TEMPLATE.format( tokens=_preflight_tokens, threshold=_compressor.threshold_tokens, - ) + ), + approx_tokens=_preflight_tokens, + threshold_tokens=_compressor.threshold_tokens, + context_length=_compressor.context_length, + model=agent.model, ) + if _preflight_status: + agent._emit_status(_preflight_status) # Preflight passes honor the same configured per-turn cap # (compression.max_attempts) as the loop's compression sites; # default 3 preserves the prior hardcoded behavior. diff --git a/tests/run_agent/test_413_compression.py b/tests/run_agent/test_413_compression.py index 7abb9469d4b1..9332f2dc44c7 100644 --- a/tests/run_agent/test_413_compression.py +++ b/tests/run_agent/test_413_compression.py @@ -907,6 +907,7 @@ class TestPreflightCompression: return 114_000 if _rough_calls["n"] == 1 else 40_000 with ( + patch("agent.turn_context.estimate_request_tokens_rough", side_effect=_rough_estimate), patch("agent.conversation_loop.estimate_request_tokens_rough", side_effect=_rough_estimate), patch.object(agent, "_compress_context") as mock_compress, patch.object(agent, "_persist_session"), @@ -957,6 +958,7 @@ class TestPreflightCompression: return 114_000 if _rough_calls["n"] == 1 else 40_000 with ( + patch("agent.turn_context.estimate_request_tokens_rough", side_effect=_rough_estimate), patch("agent.conversation_loop.estimate_request_tokens_rough", side_effect=_rough_estimate), patch.object(agent, "_compress_context") as mock_compress, patch.object(agent, "_persist_session"),