Module token_estimator

Module token_estimator 

Source
Expand description

Fast heuristic token estimation for context window management.

Uses character-based heuristics rather than a full tokenizer to avoid heavy dependencies. Accuracy is ±20% which is sufficient for deciding when to truncate or compact conversation history.

Functions§

estimate_message_tokens
Estimate token count for a single message.
estimate_messages_tokens
Estimate total token count for a slice of messages.
estimate_tokens
Estimate token count for a text string.
estimate_tool_tokens
Estimate total token count for tool descriptors.