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
//! Error types for the token optimization engine
use thiserror::Error;
/// Errors that can occur during token optimization.
///
/// These errors are non-fatal — the optimizer falls through to unoptimized
/// passthrough on any failure, so callers never see these directly.
#[derive(Debug, Error)]
pub enum TokenOptError {
/// Token estimation produced an invalid result
#[error("token estimation failed: {0}")]
EstimationFailed(String),
/// History compaction could not reduce tokens sufficiently
#[error("compaction failed: {0}")]
CompactionFailed(String),
/// Extractive or LLM-based summarization failed
#[error("summarization failed: {0}")]
SummarizationFailed(String),
/// Tool schema compression failed
#[error("tool compression failed: {0}")]
ToolCompressionFailed(String),
/// An underlying inference call (for LLM-based summarization) failed
#[error("inference error during optimization: {0}")]
InferenceError(String),
/// Configuration or initialization error
#[error("configuration error: {0}")]
Configuration(String),
}
#[cfg(feature = "pisovereign")]
impl From<application::error::ApplicationError> for TokenOptError {
fn from(err: application::error::ApplicationError) -> Self {
Self::InferenceError(err.to_string())
}
}