Skip to main content

Module compress

Module compress 

Source

Functions§

compress_tool_result
Proxy compression funnel: routes a tool result to the right compressor.
compress_tool_result_for
compress_tool_result_gateway
compress_tool_result for the /v1/compress gateway contract (#702): identical compression, but a lossy result advertises its retrieval hash in LiteLLM’s regex-locked hash=<24hex> form, so a gateway running the headroom-guardrail CCR loop (BerriAI/litellm#31681) can inject its retrieve tool and resolve the original via GET /v1/retrieve/{hash}.
compress_tool_result_gateway_for
compress_tool_result_gateway_with_policy
Gateway variant of compress_tool_result_with_policy.
compress_tool_result_with_policy
Compresses a tool result under a task-aware policy.
is_filtering_command
True when command already selects the lines its output shows: a verbatim command of the engine’s classifier (shell::compress::is_verbatim_output: head/tail, sed/awk, jq, wc, file viewers, as the whole command or its last stage), or a filter — the grep family, head/tail, sed -n, awk, cut, wc, jq/yq, sort, uniq — as the leading command or the last pipeline stage of any segment of a compound command.
shape_command_output
Shape the output of a host-native shell command whose exact command line is known (ctx_shape, fed by a host mod after the native tool ran). Unlike the wire funnel, the real command reaches the engine, so its command-gated policies (protected/verbatim commands, build/test guards, per-tool patterns) apply exactly as for ctx_shell. With a known exit_code the outcome-aware path runs (success compresses, failure keeps its diagnostics); without one the engine’s unknown-outcome guard applies. Lossy results carry the same deterministic CCR recovery handle (#482, #498).
shape_tool_output
compress_tool_result for a caller that is no request of this proxy: the output of a host-native tool handed in after it ran (ctx_shape, every tool whose command line is not known).
with_tool_command
Run f — a compression of one tool result — knowing the command line of the tool call that produced it: the command input of the matching tool_use (Bash and other shell tools). A result of a filtering command (is_filtering_command) is then not pruned again: the caller already chose the lines it wants. The previous scope is restored afterwards, also on unwind.