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.

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.
truncate_output
Truncate tool output based on line count and byte limits.