MCPcopy Create free account
hub / github.com/Louisym/MiniCC / should_compact

Function should_compact

tutorials/07_auto_compaction.py:146–158  ·  view source on GitHub ↗

判断是否需要压缩。 两个条件都满足时才压缩: 1. 消息数量 > 保留数量(否则没东西可压缩) 2. 预估 token 数 >= 阈值(还没到限制就不压缩) 对应源码: compact.rs:32-35

(session: Session, config: CompactionConfig)

Source from the content-addressed store, hash-verified

144
145
146def should_compact(session: Session, config: CompactionConfig) -> bool:
147 """
148 判断是否需要压缩。
149
150 两个条件都满足时才压缩:
151 1. 消息数量 > 保留数量(否则没东西可压缩)
152 2. 预估 token 数 >= 阈值(还没到限制就不压缩)
153
154 对应源码: compact.rs:32-35
155 """
156 has_enough_messages = len(session.messages) > config.preserve_recent_messages
157 exceeds_token_limit = estimate_session_tokens(session) >= config.max_estimated_tokens
158 return has_enough_messages and exceeds_token_limit
159
160
161# ============================================================

Callers 2

compact_sessionFunction · 0.70
mainFunction · 0.70

Calls 1

estimate_session_tokensFunction · 0.70

Tested by

no test coverage detected