Expand description
Frozen-region prose compression for the proxy (#710).
The proxy already prunes OLD tool-result content at a frozen, cache-aware
boundary (see super::history_prune). This module adds the prose
counterpart: when an operator opts in via [proxy.role_aggressiveness],
system and user free-text is squeezed with a deterministic, anti-inflation
pass. Because the output is a pure function of (text, aggressiveness), a
frozen-region rewrite is byte-identical on every later turn, so the provider
prompt-cache prefix stays valid (#498).
Assistant turns are never passed to this module — the passthrough guarantee lives at the call sites, which only invoke it for system/user roles.
Functions§
- compress_
gemini_ text_ parts - Compress the plain-
textparts of a Geminipartsarray.functionCall,functionResponseandinlineDataparts are never touched (tool I/O and binary), so only natural-language turns are squeezed. Returns segments rewritten. - compress_
message_ content - Compress an OpenAI chat message’s
content, which is either a plain string or an array of{type:"text", text}parts (multimodal). Returns the number of segments rewritten. - compress_
prose - Compress a single prose string at
aggressiveness(0.0–1.0). - compress_
string_ field - Compress a JSON string field in place (e.g. OpenAI message
content). Returnstrueif it was rewritten. - compress_
system_ value - Compress an Anthropic top-level
systemfield, which may be a plain string or an array of text blocks. Returns the number of segments rewritten. - compress_
text_ blocks - Compress every
{ "type": "text", "text": … }block in a content array (Anthropic message content / system blocks). Blocks carrying acache_controlbreakpoint are skipped so client cache anchors survive. Returns the number of blocks rewritten. - value_
has_ cache_ control trueif asystemvalue (string or array of blocks) carries anycache_controlbreakpoint. Then it anchors the client’s prompt cache and the whole field must be left verbatim. A plain string system prompt never carries one (Anthropic placescache_controlon blocks), so it is safe.