Skip to content

Graphorin API reference v0.4.0


Graphorin API reference / @graphorin/memory / / truncateToTokens

Function: truncateToTokens()

ts
function truncateToTokens(
   text, 
   maxTokens, 
   counter): Promise<{
  text: string;
  tokens: number;
  truncated: boolean;
}>;

Defined in: packages/memory/src/context-engine/token-budget.ts:110

Truncate text to fit maxTokens, preserving the leading portion and replacing the trailing portion with the literal [...truncated] marker. The token estimate is computed via the supplied counter; truncation falls back to character-based trimming when the estimate is non-monotonic.

Parameters

ParameterType
textstring
maxTokensnumber
counterContextTokenCounter

Returns

Promise<{ text: string; tokens: number; truncated: boolean; }>

Stable