Skip to content

The agent that grows with you

refactor(agent): move retryable_user_text to context_compressor_retry

Tekniumf528f92160ba
diff --git a/agent/context_compressor.py b/agent/context_compressor.py
index 404ae2af827..e8f04361ef1 100644
--- a/agent/context_compressor.py
+++ b/agent/context_compressor.py
@@ -34,6 +34,7 @@ from agent.auxiliary_client import (
from agent.context_engine import ContextEngine, sanitize_memory_context
from agent.context_compressor_prellm import PreLlmSkipMixin
from agent.context_compressor_summary import SummaryDispatchMixin
+from agent.context_compressor_retry import retryable_user_text # noqa: F401 — public re-export
from agent.error_classifier import FailoverReason, classify_api_error
from agent.micro_compaction import MicroCompactionMixin
from agent.prompt_builder import STEER_DISPLAY_KIND
@@ -5894,30 +5895,6 @@ def history_before_user_originated_turn(
return prefix, live_view
-def retryable_user_text(content: Any) -> str:
- """Lossless retry text, or raise before destructive mutation (media/unknown parts fail closed: no replay protocol)."""
- if not isinstance(content, (str, list)):
- raise ValueError("retry does not support non-text content")
- chunks: list[str] = []
- for part in [content] if isinstance(content, str) else content:
- if isinstance(part, str):
- chunks.append(part)
- continue
- if not isinstance(part, dict):
- raise ValueError("retry does not support non-text content")
- if part.get("type") not in {"text", "input_text", "output_text"}:
- raise ValueError("retry does not support media or unknown content parts")
- if set(part) - {"type", "text"}:
- raise ValueError("retry cannot losslessly flatten annotated text parts")
- if not isinstance(part.get("text"), str):
- raise ValueError("retry text parts must contain text")
- chunks.append(part["text"])
- text = "".join(chunks)
- if not text.strip():
- raise ValueError("retry found no text to send")
- return text
-
-
def _handoff_carries_live_user_content(message: Any) -> bool:
"""True when a summary-bearing row still carries a live user ask (pre-filter with ``is_compaction_summary_message``)."""
return isinstance(message, dict) and ContextCompressor._strip_context_summary_handoff_message(message) is not None
diff --git a/agent/context_compressor_retry.py b/agent/context_compressor_retry.py
new file mode 100644
index 00000000000..c35b62f30e2
--- /dev/null
+++ b/agent/context_compressor_retry.py
@@ -0,0 +1,29 @@
+"""Lossless /retry text extraction for a user-originated turn's live content."""
+
+from __future__ import annotations
+
+from typing import Any
+
+
+def retryable_user_text(content: Any) -> str:
+ """Lossless retry text, or raise before destructive mutation (media/unknown parts fail closed: no replay protocol)."""
+ if not isinstance(content, (str, list)):
+ raise ValueError("retry does not support non-text content")
+ chunks: list[str] = []
+ for part in [content] if isinstance(content, str) else content:
+ if isinstance(part, str):
+ chunks.append(part)
+ continue
+ if not isinstance(part, dict):
+ raise ValueError("retry does not support non-text content")
+ if part.get("type") not in {"text", "input_text", "output_text"}:
+ raise ValueError("retry does not support media or unknown content parts")
+ if set(part) - {"type", "text"}:
+ raise ValueError("retry cannot losslessly flatten annotated text parts")
+ if not isinstance(part.get("text"), str):
+ raise ValueError("retry text parts must contain text")
+ chunks.append(part["text"])
+ text = "".join(chunks)
+ if not text.strip():
+ raise ValueError("retry found no text to send")
+ return text