use crate::{content::Content, duration::DurationMs, effect::Scope, id::*};
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
#[non_exhaustive]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum BudgetEvent {
CostIncurred {
operator: OperatorId,
cost: Decimal,
cumulative: Decimal,
},
BudgetWarning {
workflow: WorkflowId,
spent: Decimal,
limit: Decimal,
},
BudgetAction {
workflow: WorkflowId,
action: BudgetDecision,
},
StepLimitApproaching {
operator: OperatorId,
current: u32,
max: u32,
},
StepLimitReached {
operator: OperatorId,
#[serde(alias = "total_tool_calls")]
total_sub_dispatches: u32,
},
LoopDetected {
operator: OperatorId,
#[serde(alias = "tool_name")]
operator_name: String,
consecutive_count: u32,
max: u32,
},
TimeoutApproaching {
operator: OperatorId,
elapsed: DurationMs,
max_duration: DurationMs,
},
TimeoutReached {
operator: OperatorId,
elapsed: DurationMs,
},
}
#[non_exhaustive]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum BudgetDecision {
Continue,
DowngradeModel {
from: String,
to: String,
},
HaltWorkflow,
RequestIncrease {
amount: Decimal,
},
}
#[non_exhaustive]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum CompactionEvent {
ContextPressure {
operator: OperatorId,
fill_percent: f64,
tokens_used: u64,
tokens_available: u64,
},
PreCompactionFlush {
operator: OperatorId,
scope: Scope,
},
CompactionComplete {
operator: OperatorId,
strategy: String,
tokens_freed: u64,
},
ProviderManaged {
operator: OperatorId,
provider: String,
tokens_before: u64,
tokens_after: u64,
summary: Option<Content>,
},
CompactionFailed {
operator: OperatorId,
error: String,
strategy: String,
},
CompactionSkipped {
operator: OperatorId,
reason: String,
},
FlushFailed {
operator: OperatorId,
scope: Scope,
key: String,
error: String,
},
CompactionQuality {
operator: OperatorId,
tokens_before: u64,
tokens_after: u64,
items_preserved: u32,
items_lost: u32,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum CompactionPolicy {
Pinned,
#[default]
Normal,
CompressFirst,
DiscardWhenDone,
}