Polyman Documentation - v3.1.0
    Preparing search index...

    Function trimContext

    • Returns the messages to send so they fit in budgetTokens, with the system prompt counted:

      1. Under budget: the same array.
      2. Else, from the oldest, tool results are cut to one short line.
      3. Still over: the oldest whole turns are dropped, and a note goes first.

      The last 4 user turns (a user message and everything after it until the next one) are never touched. Whole turns are dropped, so a tool call is never split from its result.

      Parameters

      • messages: Message[]
      • budgetTokens: number
      • system: string

      Returns Message[]