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.