Skip to main content

lc_callbacks/
run_type.rs

1// lc-callbacks/src/run_type.rs
2//! Run type enumeration for tracing
3
4use serde::{Deserialize, Serialize};
5
6/// Run type for tracing
7///
8/// Each run in a trace has a type that indicates what kind of operation it represents.
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
10#[serde(rename_all = "snake_case")]
11pub enum RunType {
12    /// LLM call (e.g., OpenAI chat completion)
13    Llm,
14    /// Chain execution (e.g., LLMChain, SequentialChain)
15    Chain,
16    /// Tool invocation (e.g., Calculator, DateTime)
17    Tool,
18    /// Retriever query (e.g., vector search)
19    Retriever,
20    /// Embedding generation
21    Embedding,
22    /// Prompt template formatting
23    Prompt,
24    /// Output parsing
25    Parser,
26}
27
28impl RunType {
29    /// Get string representation for API
30    pub fn as_str(&self) -> &'static str {
31        match self {
32            Self::Llm => "llm",
33            Self::Chain => "chain",
34            Self::Tool => "tool",
35            Self::Retriever => "retriever",
36            Self::Embedding => "embedding",
37            Self::Prompt => "prompt",
38            Self::Parser => "parser",
39        }
40    }
41
42    /// Get display emoji for console output
43    pub fn emoji(&self) -> &'static str {
44        match self {
45            Self::Llm => "🤖",
46            Self::Chain => "🔗",
47            Self::Tool => "🔧",
48            Self::Retriever => "📚",
49            Self::Embedding => "📊",
50            Self::Prompt => "📝",
51            Self::Parser => "📄",
52        }
53    }
54}
55
56impl std::fmt::Display for RunType {
57    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
58        write!(f, "{}", self.as_str())
59    }
60}