1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! Structured snapshots of the currently assembled context window.
use aither_core::llm::Message;
use serde::{Deserialize, Serialize};
/// High-level lifecycle phase of the assembled context window.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ContextWindowPhase {
/// Regular operating state.
Stable,
/// A lightweight reassembly should run before attempting compaction.
ReassemblyDue,
/// Full-window usage is high enough that compaction should be considered.
CompressionDue,
/// Usage is close enough to the hard limit that the model should hand off.
HandoffDue,
/// A handoff document is already active in the context.
HandoffActive,
}
/// Metrics describing the currently assembled context window.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ContextWindowMetrics {
/// Estimated fraction of the effective context window currently in use.
pub usage_fraction: f32,
/// Context window of the currently selected reasoning model.
pub selected_model_context_window: Option<u32>,
/// Context window of the fast model used for compaction.
pub fast_model_context_window: Option<u32>,
/// Effective window used for budgeting (minimum of selected and fast).
pub effective_context_window: usize,
/// Number of persistent system blocks in the structured context.
pub system_block_count: usize,
/// Number of ephemeral reminders currently assembled.
pub reminder_count: usize,
/// Number of recent conversation messages.
pub recent_message_count: usize,
/// Number of recent system messages that can be pruned by reassembly.
pub recent_system_message_count: usize,
/// Whether a persisted handoff document is present.
pub has_handoff: bool,
}
/// Fully assembled LLM request window plus lifecycle metadata.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ContextWindowSnapshot {
/// Lifecycle phase derived from current budgeting rules.
pub phase: ContextWindowPhase,
/// Metrics for observability and persistence.
pub metrics: ContextWindowMetrics,
/// Exact message list that would be sent to the model for the next turn.
pub messages: Vec<Message>,
}