pub struct HeuristicTokenCounter;Expand description
Default token counter: ~4 chars per token (heuristic for English text).
Good enough for context budgeting and compaction threshold decisions. Use a model-specific tokenizer (e.g., tiktoken) for precision.
Trait Implementations§
Source§impl TokenCounter for HeuristicTokenCounter
impl TokenCounter for HeuristicTokenCounter
Source§fn estimate_text(&self, text: &str) -> usize
fn estimate_text(&self, text: &str) -> usize
Estimate tokens for a raw text string.
Source§fn estimate_content(&self, content: &[Content]) -> usize
fn estimate_content(&self, content: &[Content]) -> usize
Estimate tokens for a slice of Content blocks.
Source§fn estimate_message(&self, msg: &AgentMessage) -> usize
fn estimate_message(&self, msg: &AgentMessage) -> usize
Estimate tokens for a single message.
Source§fn estimate_messages(&self, msgs: &[AgentMessage]) -> usize
fn estimate_messages(&self, msgs: &[AgentMessage]) -> usize
Estimate total tokens for a message list.
Auto Trait Implementations§
impl Freeze for HeuristicTokenCounter
impl RefUnwindSafe for HeuristicTokenCounter
impl Send for HeuristicTokenCounter
impl Sync for HeuristicTokenCounter
impl Unpin for HeuristicTokenCounter
impl UnsafeUnpin for HeuristicTokenCounter
impl UnwindSafe for HeuristicTokenCounter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more