Skip to main content

ag_runtime/
reasoning.rs

1use std::str::FromStr;
2
3/// Supported reasoning-effort levels for task execution.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
5pub enum ReasoningLevel {
6    /// Low reasoning effort for faster responses.
7    Low,
8    /// Medium reasoning effort.
9    Medium,
10    /// High reasoning effort for deeper reasoning.
11    #[default]
12    High,
13    /// Extra-high reasoning effort for deeper analysis.
14    XHigh,
15    /// Maximum reasoning effort for the hardest tasks.
16    Max,
17}
18
19impl ReasoningLevel {
20    /// All selectable reasoning-effort levels in UI display order.
21    pub const ALL: [Self; 5] = [Self::Low, Self::Medium, Self::High, Self::XHigh, Self::Max];
22
23    /// Returns the stable persisted identifier for this level.
24    ///
25    /// This value is stored in the database and remains independent from any
26    /// provider-specific transport string changes.
27    pub fn as_str(self) -> &'static str {
28        match self {
29            Self::Low => "low",
30            Self::Medium => "medium",
31            Self::High => "high",
32            Self::XHigh => "xhigh",
33            Self::Max => "max",
34        }
35    }
36
37    /// Returns a short UI description for this reasoning level.
38    pub fn description(self) -> &'static str {
39        match self {
40            Self::Low => "Fastest responses with lighter reasoning.",
41            Self::Medium => "Balanced speed and reasoning depth.",
42            Self::High => "Deeper reasoning for tougher tasks.",
43            Self::XHigh => "Extra-high reasoning for complex tasks.",
44            Self::Max => "Maximum reasoning effort for the hardest tasks.",
45        }
46    }
47}
48
49impl FromStr for ReasoningLevel {
50    type Err = String;
51
52    fn from_str(value: &str) -> Result<Self, Self::Err> {
53        match value {
54            "low" => Ok(Self::Low),
55            "medium" => Ok(Self::Medium),
56            "high" => Ok(Self::High),
57            "xhigh" => Ok(Self::XHigh),
58            "max" => Ok(Self::Max),
59            other => Err(format!("unknown reasoning level: {other}")),
60        }
61    }
62}
63
64#[cfg(test)]
65#[path = "reasoning_test.rs"]
66mod tests;