Skip to main content

Module truncate

Module truncate 

Source
Expand description

Bounded tool output.

Tool results enter conversation history verbatim today, so one verbose command can fill the context window in a single iteration. This module truncates output once, at ingest, middle-out: the head and tail of the output are kept because that is where a command’s intent and its outcome live, and a warning header states what was removed so the model can ask for the rest.

The policy shape and the header text follow Codex CLI’s utils/output-truncation (Apache-2.0). The implementation is UAR’s own and counts tokens through TokenService so budgets agree with the rest of the runtime.

Enums§

TruncationPolicy
How much of a tool result may enter history.

Constants§

DEFAULT_OUTPUT_BYTE_BUDGET
Default byte budget for a tool result when the tool declares none.
WARNING_HEADER_PREFIX
Start of the header every truncated result carries.

Functions§

formatted_truncate
Truncate content to policy if needed, prefixing a warning header that states the original token count and total line count. Output already within the policy is returned unchanged.
formatted_truncate_for_model
Truncate tool output against the resolved model’s tokenizer. An empty or unknown model uses TokenService’s documented cl100k_base fallback.
truncate_middle
Keep the head and tail of content within byte_budget bytes, replacing the middle with a marker that states how many bytes were removed. Cuts land on character boundaries so the result is always valid UTF-8.