Skip to main content

Module compaction

Module compaction 

Source
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§

CompactionConfig
Configuration for compact_messages.
CompactionResult
Result of a compact_messages call.

Enums§

CompactionMarker
Semantic markers attached to compacted content. Each variant carries a Severity that 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_recent tokens.
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.