ShouldCompact reports whether a session's context usage has crossed the compaction threshold. It returns true when the total token count (input + output + addedTokens) exceeds [contextThreshold] (90%) of contextLimit.
(inputTokens, outputTokens, addedTokens, contextLimit int64)
| 25 | // (input + output + addedTokens) exceeds [contextThreshold] (90%) of |
| 26 | // contextLimit. |
| 27 | func ShouldCompact(inputTokens, outputTokens, addedTokens, contextLimit int64) bool { |
| 28 | if contextLimit <= 0 { |
| 29 | return false |
| 30 | } |
| 31 | return (inputTokens + outputTokens + addedTokens) > int64(float64(contextLimit)*contextThreshold) |
| 32 | } |
| 33 | |
| 34 | // EstimateMessageTokens returns a rough token-count estimate for a single |
| 35 | // chat message based on its text length. This is intentionally conservative |
no outgoing calls