Expand description
Semantic context compaction: token estimation, compaction markers, and oldest-first message removal that preserves the system prompt and a recent token window.
Structs§
- Compaction
Config - Configuration for
compact_messages. - Compaction
Result - Result of a
compact_messagescall.
Enums§
- Compaction
Marker - Semantic markers attached to compacted content. Each variant carries a
Severitythat guides what the compactor tries to preserve. - Severity
- Severity of a
CompactionMarker: critical markers must survive compaction, important markers should survive when possible, and informational markers may be dropped freely.
Constants§
- IMAGE_
TOKEN_ COST - Fixed token cost attributed to a single image attachment.
Functions§
- apply_
compaction - Apply compaction in-place: keep system prefix, insert a summary system note, and retain the recent tail window. No-op when under the trigger threshold.
- compact_
messages - Compact a message slice by removing the oldest messages first,
preserving the leading system prompt and a trailing window of
keep_recenttokens. - estimate_
image_ tokens - estimate_
messages - Estimate the token cost of a message slice using zero-allocation JSON byte counting where possible.
- estimate_
tokens - Heuristic token estimate: ~3 characters per token.