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§
- Truncation
Policy - 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
contenttopolicyif 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 documentedcl100k_basefallback. - truncate_
middle - Keep the head and tail of
contentwithinbyte_budgetbytes, 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.