use serde::{Deserialize, Serialize};
use serde_json::Value;
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum TraceCallKind {
Llm,
Tool,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct TraceCall {
pub kind: TraceCallKind,
pub name: String,
pub input: Value,
pub output: Value,
}
impl TraceCall {
pub fn llm(name: impl Into<String>, input: Value, output: Value) -> Self {
Self {
kind: TraceCallKind::Llm,
name: name.into(),
input,
output,
}
}
pub fn tool(name: impl Into<String>, input: Value, output: Value) -> Self {
Self {
kind: TraceCallKind::Tool,
name: name.into(),
input,
output,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Trace {
pub name: String,
pub calls: Vec<TraceCall>,
}
impl Trace {
pub fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
calls: Vec::new(),
}
}
pub fn push(&mut self, call: TraceCall) {
self.calls.push(call);
}
pub fn len(&self) -> usize {
self.calls.len()
}
pub fn is_empty(&self) -> bool {
self.calls.is_empty()
}
}