Skip to main content

Module prose

Module prose 

Source
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-text parts of a Gemini parts array. functionCall, functionResponse and inlineData parts 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). Returns true if it was rewritten.
compress_system_value
Compress an Anthropic top-level system field, 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 a cache_control breakpoint are skipped so client cache anchors survive. Returns the number of blocks rewritten.
estimate_tokens
Rough token estimate for a JSON value (chars / 4).
value_has_cache_control
true if a system value (string or array of blocks) carries any cache_control breakpoint. 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 places cache_control on blocks), so it is safe.