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_tokens
Estimate token count for a string. Uses a simple heuristic: ~4 chars per English token, ~2 chars per Chinese token. For mixed content, we use ~3 chars per token as a rough estimate.
truncate_output
Truncate tool output based on line count and byte limits.