Skip to main content

artifactize_core/config/
profile.rs

1//! Execution profiles and reasoning controls declared by Evals.
2
3use super::{
4    Backend, ModelId,
5    validation::{self, positive_integer, present, script, text, timeout},
6};
7use serde::{Deserialize, Serialize};
8
9/// Declared effort is exact: unsupported backend efforts fail rather than remap.
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
11#[serde(rename_all = "lowercase")]
12pub enum Reasoning {
13    None,
14    Minimal,
15    Low,
16    Medium,
17    High,
18    Xhigh,
19    Max,
20}
21impl Reasoning {
22    pub fn as_str(self) -> &'static str {
23        match self {
24            Self::None => "none",
25            Self::Minimal => "minimal",
26            Self::Low => "low",
27            Self::Medium => "medium",
28            Self::High => "high",
29            Self::Xhigh => "xhigh",
30            Self::Max => "max",
31        }
32    }
33}
34impl std::fmt::Display for Reasoning {
35    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36        formatter.write_str(self.as_str())
37    }
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(tag = "kind", rename_all = "lowercase", deny_unknown_fields)]
42pub enum Profile {
43    Agent {
44        backend: Backend,
45        model: ModelId,
46        #[serde(default, deserialize_with = "present")]
47        reasoning: Option<Reasoning>,
48        #[serde(
49            rename(serialize = "timeoutMs", deserialize = "timeout_ms"),
50            default,
51            deserialize_with = "timeout",
52            serialize_with = "validation::milliseconds::serialize"
53        )]
54        timeout_ms: Option<std::time::Duration>,
55        #[serde(
56            rename(serialize = "maxToolCalls", deserialize = "max_tool_calls"),
57            default,
58            deserialize_with = "positive_integer"
59        )]
60        max_tool_calls: Option<u64>,
61        #[serde(
62            rename(serialize = "maxTokens", deserialize = "max_tokens"),
63            default,
64            deserialize_with = "positive_integer"
65        )]
66        max_tokens: Option<u64>,
67    },
68    Human {},
69    Runtime {
70        #[serde(serialize_with = "crate::platform::serialize_program")]
71        command: String,
72        args: Vec<crate::scope::Argument>,
73        #[serde(
74            rename(serialize = "timeoutMs", deserialize = "timeout_ms"),
75            default,
76            deserialize_with = "timeout",
77            serialize_with = "validation::milliseconds::serialize"
78        )]
79        timeout_ms: Option<std::time::Duration>,
80    },
81}
82
83impl Profile {
84    /// What a profile must hold beyond its types: a nonblank model, an eval backend, an effort
85    /// the backend's API accepts, and a runtime command without control characters.
86    pub(crate) fn check(&self) -> Result<(), String> {
87        match self {
88            Self::Agent {
89                backend,
90                model,
91                reasoning,
92                ..
93            } => {
94                text(model, "Agent profile model")?;
95                backend.validate_eval()?;
96                // A custom provider's API is known only where it runs, so its effort is
97                // checked there.
98                if let (Some(reasoning), Some(provider)) = (reasoning, backend.builtin()) {
99                    crate::llm::Api::from(provider).validate_reasoning(reasoning.as_str())?;
100                }
101                Ok(())
102            }
103            Self::Human {} => Ok(()),
104            Self::Runtime { command, args, .. } => script(command, args),
105        }
106    }
107
108    pub fn kind(&self) -> ProfileKind {
109        match self {
110            Self::Agent { .. } => ProfileKind::Agent,
111            Self::Human {} => ProfileKind::Human,
112            Self::Runtime { .. } => ProfileKind::Runtime,
113        }
114    }
115}
116
117/// The kind of reviewer a profile names, without its execution options.
118#[derive(
119    Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, clap::ValueEnum,
120)]
121#[serde(rename_all = "lowercase")]
122pub enum ProfileKind {
123    /// Runtime evals: a command's exit code.
124    Runtime,
125    /// Agent evals: a model's review.
126    Agent,
127    /// Human evals: a person's sign-off.
128    Human,
129}
130
131impl ProfileKind {
132    pub fn name(self) -> &'static str {
133        match self {
134            Self::Runtime => "runtime",
135            Self::Agent => "agent",
136            Self::Human => "human",
137        }
138    }
139}