telos_agent/agent/compaction/
mod.rs1pub mod history_summary;
10pub mod message_truncation;
11
12use crate::model::message::{ContentBlock, Message};
13use crate::model::provider::ModelProvider;
14
15pub use history_summary::{HistoryCompactionStrategy, SummaryHistoryCompaction};
16pub use message_truncation::{
17 ContentCompressor, MessageTruncationConfig, MessageTruncationResult, TruncationCompressor,
18 truncate_message,
19};
20
21pub(crate) fn estimate_message_tokens(messages: &[Message], provider: &dyn ModelProvider) -> usize {
23 messages
24 .iter()
25 .flat_map(|message| message.blocks.iter())
26 .map(|block| match block {
27 ContentBlock::Text(text) => provider.estimate_tokens(&text.text),
28 ContentBlock::Thinking(thinking) => provider.estimate_tokens(&thinking.text),
29 ContentBlock::ToolCall(call) => {
30 provider.estimate_tokens(&call.name)
31 + provider.estimate_tokens(&call.arguments.to_string())
32 }
33 ContentBlock::ToolResult(result) => {
34 provider.estimate_tokens(&result.content.to_string())
35 }
36 })
37 .sum()
38}