TokenWindow

org.llm4s.context.TokenWindow
object TokenWindow

Manages conversation token windows by trimming conversations to fit within token budgets. Always preserves system messages and applies configurable headroom for safety.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def fitsInBudget(conversation: Conversation, tokenCounter: ConversationTokenCounter, budget: TokenBudget, headroomPercent: Double): Boolean

Check if a conversation fits within the budget (including headroom)

Check if a conversation fits within the budget (including headroom)

Attributes

def getUsageInfo(conversation: Conversation, tokenCounter: ConversationTokenCounter, budget: TokenBudget): TokenUsageInfo

Get current token usage information for a conversation

Get current token usage information for a conversation

Attributes

def trimToBudget(conversation: Conversation, tokenCounter: ConversationTokenCounter, budget: TokenBudget, headroomPercent: Double): Result[ConversationWindow]

Trim a conversation to fit within the specified token budget. Always preserves system messages and applies headroom for safety.

Trim a conversation to fit within the specified token budget. Always preserves system messages and applies headroom for safety.

Value parameters

budget

Maximum token budget

conversation

The conversation to trim

headroomPercent

Safety margin (default 8%)

tokenCounter

Token counter for the specific model

Attributes

Returns

Trimmed conversation that fits within budget