Skip to content

interlens.context.summarize_policy

interlens.context.summarize_policy

SummarizePolicy

SummarizePolicy(keep_last: int = 4, summarizer=None)

Bases: ContextPolicy

Compress older turns into a single summary segment instead of dropping them outright (the heaviest policy).

Keeps the preserved framing (system / moderator / private_context) and the most recent keep_last turns verbatim, and replaces the older middle turns with one summary segment produced by summarizer — a callable list[str] -> str over the dropped turns' contents. With no summarizer it inserts a neutral placeholder, so it degrades to a labelled drop rather than silently losing content.

summarizer is a live callable and so is not serialized; a loaded template gets summarizer=None and the caller re-injects one if needed.

Source code in src/interlens/context/summarize_policy.py
def __init__(self, keep_last: int = 4, summarizer=None):
	self.keep_last = keep_last
	self.summarizer = summarizer