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 {
agent: AgentId,
cost: Decimal,
cumulative: Decimal,
},
BudgetWarning {
workflow: WorkflowId,
spent: Decimal,
limit: Decimal,
},
BudgetAction {
workflow: WorkflowId,
action: BudgetDecision,
},
}
#[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 {
agent: AgentId,
fill_percent: f64,
tokens_used: u64,
tokens_available: u64,
},
PreCompactionFlush {
agent: AgentId,
scope: Scope,
},
CompactionComplete {
agent: AgentId,
strategy: String,
tokens_freed: u64,
},
ProviderManaged {
agent: AgentId,
provider: String,
tokens_before: u64,
tokens_after: u64,
summary: Option<Content>,
},
}
#[non_exhaustive]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ObservableEvent {
pub source: EventSource,
pub event_type: String,
pub timestamp: DurationMs,
pub data: serde_json::Value,
pub trace_id: Option<String>,
pub workflow_id: Option<WorkflowId>,
pub agent_id: Option<AgentId>,
}
#[non_exhaustive]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum EventSource {
Turn,
Orchestration,
State,
Environment,
Hook,
}
impl ObservableEvent {
pub fn new(
source: EventSource,
event_type: impl Into<String>,
timestamp: DurationMs,
data: serde_json::Value,
) -> Self {
Self {
source,
event_type: event_type.into(),
timestamp,
data,
trace_id: None,
workflow_id: None,
agent_id: None,
}
}
}