Skip to main content

objectiveai_sdk/functions/
profile.rs

1//! Profile types for Function execution.
2//!
3//! A Profile contains the learned weights and configuration needed to execute
4//! a Function. Profiles are typically trained on example data to optimize
5//! scoring behavior.
6
7use schemars::JsonSchema;
8use serde::{Deserialize, Serialize};
9
10/// A profile specification that is either an inline profile definition
11/// or a remote path reference.
12#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
13#[serde(untagged)]
14#[schemars(rename = "functions.InlineProfileOrRemoteCommitOptional")]
15pub enum InlineProfileOrRemoteCommitOptional {
16    #[schemars(title = "Inline")]
17    Inline(InlineProfile),
18    #[schemars(title = "Remote")]
19    Remote(crate::RemotePathCommitOptional),
20}
21
22/// A Profile definition, either remote or inline.
23///
24/// Profiles contain the weights and nested configurations needed to execute
25/// a Function. They correspond to a Function's task structure.
26#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
27#[serde(untagged)]
28#[schemars(rename = "functions.Profile")]
29pub enum Profile {
30    /// A remote profile with metadata.
31    #[schemars(title = "Remote")]
32    Remote(RemoteProfile),
33    /// An inline profile definition.
34    #[schemars(title = "Inline")]
35    Inline(InlineProfile),
36}
37
38/// A remote profile, either tasks-based or auto.
39#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
40#[serde(untagged)]
41#[schemars(rename = "functions.RemoteProfile")]
42pub enum RemoteProfile {
43    /// Tasks-based profile with per-task configuration.
44    #[schemars(title = "Tasks")]
45    Tasks(RemoteTasksProfile),
46    /// Auto profile that applies a single swarm+weights to all vector completion tasks.
47    #[schemars(title = "Auto")]
48    Auto(crate::swarm::RemoteSwarmBase),
49}
50
51/// An inline profile, either tasks-based or auto.
52#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
53#[serde(untagged)]
54#[schemars(rename = "functions.InlineProfile")]
55pub enum InlineProfile {
56    /// Tasks-based profile with per-task configuration.
57    #[schemars(title = "Tasks")]
58    Tasks(InlineTasksProfile),
59    /// Auto profile that applies a single swarm+weights to all vector completion tasks.
60    #[schemars(title = "Auto")]
61    Auto(crate::swarm::InlineSwarmBase),
62}
63
64impl<'a> arbitrary::Arbitrary<'a> for InlineProfile {
65    fn arbitrary(
66        u: &mut arbitrary::Unstructured<'a>,
67    ) -> arbitrary::Result<Self> {
68        // Only generate Tasks variant since Auto requires SwarmBaseWithProfile
69        // which has complex dependencies.
70        Ok(InlineProfile::Tasks(u.arbitrary()?))
71    }
72}
73
74/// An inline tasks-based profile definition without metadata.
75#[derive(
76    Debug,
77    Clone,
78    PartialEq,
79    Serialize,
80    Deserialize,
81    JsonSchema,
82    arbitrary::Arbitrary,
83)]
84#[schemars(rename = "functions.InlineTasksProfile")]
85pub struct InlineTasksProfile {
86    /// Configuration for each task in the corresponding Function.
87    pub tasks: Vec<TaskProfile>,
88    /// Optional weights for each Task in the corresponding Function.
89    /// If `None`, uniform weights are used.
90    #[serde(skip_serializing_if = "Option::is_none")]
91    #[schemars(extend("omitempty" = true))]
92    pub weights: Option<crate::Weights>,
93}
94
95/// A remote tasks-based profile with full metadata.
96///
97/// Stored as `profile.json` in repositories and referenced by
98/// `remote/owner/repository`.
99#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
100#[schemars(rename = "functions.RemoteTasksProfile")]
101pub struct RemoteTasksProfile {
102    /// Human-readable description of the profile.
103    pub description: String,
104    #[serde(flatten)]
105    #[schemars(schema_with = "crate::flatten_schema::<InlineTasksProfile>")]
106    pub inner: InlineTasksProfile,
107}
108
109/// Configuration for a single task within a Profile.
110///
111/// Each variant corresponds to a task type in the Function definition.
112#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
113#[serde(untagged)]
114#[schemars(rename = "functions.TaskProfile")]
115pub enum TaskProfile {
116    /// Profile for a nested function task (references another profile).
117    #[schemars(title = "Remote")]
118    Remote(crate::RemotePath),
119    /// Inline profile for a task (tasks-based or auto).
120    #[schemars(title = "Inline")]
121    Inline(InlineProfile),
122    /// Placeholder task — no configuration needed, output is fixed.
123    #[schemars(title = "Placeholder")]
124    Placeholder {},
125}
126
127impl<'a> arbitrary::Arbitrary<'a> for TaskProfile {
128    fn arbitrary(
129        u: &mut arbitrary::Unstructured<'a>,
130    ) -> arbitrary::Result<Self> {
131        // Inline variant is recursive (InlineProfile → InlineTasksProfile → Vec<TaskProfile>),
132        // so use go-deep bool to make recursion exponentially rare.
133        if u.arbitrary().unwrap_or(false) {
134            Ok(TaskProfile::Inline(u.arbitrary()?))
135        } else if u.arbitrary().unwrap_or(false) {
136            Ok(TaskProfile::Remote(u.arbitrary()?))
137        } else {
138            Ok(TaskProfile::Placeholder {})
139        }
140    }
141}