Skip to content
Français

truncateToolResults

import { truncateToolResults } from "@elie-laloum/outpost/harness";

Create a context strategy that cuts older tool results to maxCharacters, appending a truncation marker, and leaves the keepRecent most recent tool-result messages intact. It returns nothing while no older result exceeds the limit.

Complete example and detailed rules.

  • optionsOptional
    TruncateToolResultsOptions | undefined
    Number of recent tool results kept intact and the length older results are cut to.
  • options.keepRecentOptional
    number | undefined
    Number of most recent tool-result messages kept intact, default 4.
  • options.maxCharactersOptional
    number | undefined
    Length older tool results are cut to, default 2000 characters.

Templates below preserve the English text sent to the model. ${…} marks runtime substitutions, not brief template syntax.

When an older tool result exceeds maxCharacters, its content is replaced with:

${retainedContent}
[earlier output truncated from ${originalLength} characters]

retainedContent is the first maxCharacters JavaScript string code units; originalLength is the original string’s length. This is a marker in the tool result, not a separate model request. Its wording is fixed. Change maxCharacters or keepRecent to control truncation, or supply a custom context strategy to use another transformation.

Implementation: context.ts.

HarnessContextStrategy

export declare function truncateToolResults(
  options?: TruncateToolResultsOptions,
): HarnessContextStrategy;