Skip to main content

ag_contracts/
reasoning.rs

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