Skip to main content

oxi_agent/
compaction.rs

1/// Context compaction events
2use oxi_ai::CompactedContext as AiCompactedContext;
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6/// CompactionEvent.
7pub enum CompactionEvent {
8    /// Variant.
9    Triggered {
10        /// context_tokens.
11        context_tokens: usize,
12        /// iteration.
13        iteration: usize,
14    },
15    /// Variant.
16    Started {
17        /// message_count.
18        message_count: usize,
19    },
20    /// Variant.
21    Completed {
22        /// result.
23        result: CompactedContext,
24        /// duration_ms.
25        duration_ms: u64,
26    },
27    /// Variant.
28    Skipped {
29        /// reason.
30        reason: String,
31    },
32    /// Variant.
33    Failed {
34        /// error.
35        error: String,
36    },
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
40/// CompactedContext.
41pub struct CompactedContext {
42    /// pub.
43    pub summary: String,
44    /// pub.
45    pub kept_messages: Vec<oxi_ai::Message>,
46    /// pub.
47    pub compacted_count: usize,
48}
49
50impl From<AiCompactedContext> for CompactedContext {
51    fn from(ctx: AiCompactedContext) -> Self {
52        Self {
53            summary: ctx.summary,
54            kept_messages: ctx.kept_messages,
55            compacted_count: ctx.compacted_count,
56        }
57    }
58}