MCPcopy Index your code
hub / github.com/docker/docker-agent / ShouldCompact

Function ShouldCompact

pkg/compaction/compaction.go:27–32  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

25// (input + output + addedTokens) exceeds [contextThreshold] (90%) of
26// contextLimit.
27func 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

Callers 3

runStreamLoopMethod · 0.92
compactIfNeededMethod · 0.92
TestShouldCompactFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestShouldCompactFunction · 0.68