Skip to main content

TokenCounter

Trait TokenCounter 

Source
pub trait TokenCounter: Send + Sync {
    // Required method
    fn count_tokens(&self, message: &AgentMessage) -> usize;
}
Expand description

Pluggable token counting strategy.

Implement this trait to replace the built-in chars / 4 heuristic with tiktoken, a provider-native tokenizer, or any other counting scheme.

Required Methods§

Source

fn count_tokens(&self, message: &AgentMessage) -> usize

Return the estimated token count for a single message.

Implementors§