use crate::model::HistoryEntry;
use crabllm_core::{FinishReason, Message, ToolCall, Usage};
#[derive(Debug, Clone)]
pub enum AgentEvent {
TextStart,
TextDelta(String),
TextEnd,
ThinkingStart,
ThinkingDelta(String),
ThinkingEnd,
ToolCallsBegin(Vec<ToolCall>),
ToolCallsStart(Vec<ToolCall>),
ToolResult {
call_id: String,
output: Result<String, String>,
duration_ms: u64,
},
ToolCallsComplete,
UserSteered { content: String },
Compact { summary: String },
Done(AgentResponse),
}
#[derive(Debug, Clone)]
pub struct AgentStep {
pub message: Message,
pub usage: Usage,
pub finish_reason: Option<FinishReason>,
pub tool_calls: Vec<ToolCall>,
pub tool_results: Vec<HistoryEntry>,
}
#[derive(Debug, Clone)]
pub struct AgentResponse {
pub steps: Vec<AgentStep>,
pub final_response: Option<String>,
pub iterations: usize,
pub stop_reason: AgentStopReason,
pub model: String,
}
impl AgentResponse {
pub fn error(msg: impl Into<String>) -> Self {
Self {
steps: vec![],
final_response: None,
iterations: 0,
stop_reason: AgentStopReason::Error(msg.into()),
model: String::new(),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum AgentStopReason {
TextResponse,
MaxIterations,
NoAction,
Error(String),
}
impl std::fmt::Display for AgentStopReason {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::TextResponse => write!(f, "text_response"),
Self::MaxIterations => write!(f, "max_iterations"),
Self::NoAction => write!(f, "no_action"),
Self::Error(msg) => write!(f, "error: {msg}"),
}
}
}