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