按上下文预算比例触发,挂多档压缩器
阈值是「有效上下文预算 × trigger_context_ratio」,即按比例而非绝对 token 数,所以换模型时不必改配置。压缩器不止一个:round_level(轮级)、current_round(当轮)、micro_compact(工具结果微压缩)、full_compact(整体压缩)、dialogue(对话压缩)各自实现 trigger 判断,组成一条处理器链。
def _trigger_token_threshold(self, context: ModelContext) -> int:
budget = effective_context_budget(context, model_config=self._round_config.model)
return max(int(budget * self._trigger_context_ratio), 1)
# —— 调用处(同文件 222-228 行)——
trigger_threshold = self._trigger_token_threshold(context)
if total_tokens >= trigger_threshold:
logger.info(
f"[{self.processor_type()} triggered] estimated context window tokens {total_tokens} "
f"reaches trigger_context_ratio {self._trigger_context_ratio} threshold {trigger_threshold}"
)
return True