Skip to main content

Module token

Module token 

Source
Expand description

Token counting and message trimming utilities.

Provides TokenCounter trait for pluggable token counting, CharTokenCounter for test approximation, and trim_messages for context window management.

Based on Group 16.6 and Group 19 of the pre-plan.

Structs§

CharTokenCounter
Approximate token counter using character count / 4.
TrimOptions
Options for trim_messages.

Enums§

MessageRole
Which message roles are acceptable at window boundaries.
TrimStrategy
Strategy for which messages to keep when trimming.

Traits§

TokenCounter
How messages should be counted for trimming.

Functions§

trim_messages
Trim a message list to fit within a token budget.