Skip to main content

Module context

Module context 

Source
Expand description

Context management — output truncation and history window management.

Structs§

ContextManager
Manages the context window, truncating history when approaching token limits.
TruncationResult
Result of context truncation, used for async compression.

Enums§

TruncationAction
Type of truncation action, determines how the caller should handle the result.

Functions§

estimate_messages_tokens
Estimate tokens for a list of messages.
estimate_messages_tokens_with_margin
Estimate tokens for messages, applying the configured safety margin.
estimate_tokens
Estimate token count for a string.
format_removed_messages_as_transcript
Format removed messages into a compact transcript for summary generation. Extracts user messages, assistant text, and tool call names only. Truncates each message to keep the transcript concise.
get_merge_level
Get the merge level (number of times this segment has been merged). 0 = fresh segment, 1 = merged once, etc.
is_summary_segment
Check whether a message is a summary segment (any merge level, including legacy notice).
truncate_output
Truncate tool output based on line count and byte limits.