use chrono::{DateTime, Utc};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TurnPhase {
ReceiveInput,
Recall,
Think,
Act,
Finalize,
}
impl TurnPhase {
pub fn name(&self) -> &str {
match self {
Self::ReceiveInput => "receive_input",
Self::Recall => "recall",
Self::Think => "think",
Self::Act => "act",
Self::Finalize => "finalize",
}
}
pub fn is_checkpoint(&self) -> bool {
matches!(self, Self::Think | Self::Act | Self::Finalize)
}
}
#[derive(Debug, Clone)]
pub struct AgentTurn {
pub turn_id: String,
pub input: String,
pub phase: TurnPhase,
pub iteration_count: usize,
pub started_at: DateTime<Utc>,
}
impl AgentTurn {
pub fn new(input: &str) -> Self {
Self {
turn_id: format!("turn_{}", uuid::Uuid::new_v4()),
input: input.to_string(),
phase: TurnPhase::ReceiveInput,
iteration_count: 0,
started_at: Utc::now(),
}
}
pub fn advance(&mut self, phase: TurnPhase) {
self.phase = phase;
}
pub fn record_iteration(&mut self) {
self.iteration_count += 1;
}
pub fn elapsed(&self) -> chrono::Duration {
Utc::now() - self.started_at
}
}