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