You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adding a simple token counter would allow a number of quality of life improvements in Crush and other applications using Fantasy:
Pre-flight validation to avoid context errors.
Tool call / result warnings, such as alerting when MCP tool outputs are large.
Opening the door to different summarization/compaction patterns.
Proposal
This requires a simple token counter - although, in theory, we could also use something like github.com/tiktoken-go/tokenizer.
In practice, we simply don't need to be that accurate. Additionally, creating a very simple approach in Fantasy allows for easily evolving to more accurate approaches in the future.
// tokens.go// TokenEstimator provides fast approximate token counts.typeTokenEstimatorstruct{}
// NewTokenEstimator creates a new token estimator.funcNewTokenEstimator() *TokenEstimator {
return&TokenEstimator{}
}
// Estimate returns an approximate token count for the given text.// Uses ~4 bytes per token heuristic, not runes, scales better for foreign languages func (e*TokenEstimator) EstimateTokens(textstring) int {
return (len(text) +3) /4
}
Could be interfaced with:
typeTokenEstimatorinterface {
EstimateTokens(textstring) int
}
Why Fantasy versus Crush
Since this is a general LLM utility, it seems more correct to put it on Fantasy itself. Besides, I can envision making small additions to this over time to make its estimates more accurate.
Alternatives
The alternative would be to use github.com/pkoukk/tiktoken-go but, in my view, this just isn't necessary and is an unnecessary dependency.
Opencode itself does something similar to this.
Summarization / Compaction
In Crush, if we can estimate tokens, we can potentially follow different compaction patterns, allowing conversation turns over 80% context or allowing the user to configure when summarization / compaction begins.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Adding a simple token counter would allow a number of quality of life improvements in Crush and other applications using Fantasy:
Proposal
This requires a simple token counter - although, in theory, we could also use something like github.com/tiktoken-go/tokenizer.
In practice, we simply don't need to be that accurate. Additionally, creating a very simple approach in Fantasy allows for easily evolving to more accurate approaches in the future.
Could be interfaced with:
Why Fantasy versus Crush
Since this is a general LLM utility, it seems more correct to put it on Fantasy itself. Besides, I can envision making small additions to this over time to make its estimates more accurate.
Alternatives
The alternative would be to use github.com/pkoukk/tiktoken-go but, in my view, this just isn't necessary and is an unnecessary dependency.
Opencode itself does something similar to this.
Summarization / Compaction
In Crush, if we can estimate tokens, we can potentially follow different compaction patterns, allowing conversation turns over 80% context or allowing the user to configure when summarization / compaction begins.
Beta Was this translation helpful? Give feedback.
All reactions