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 serde::{Deserialize, Serialize};
8use schemars::JsonSchema;
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(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
66        // Only generate Tasks variant since Auto requires SwarmBaseWithProfile
67        // which has complex dependencies.
68        Ok(InlineProfile::Tasks(u.arbitrary()?))
69    }
70}
71
72/// An inline tasks-based profile definition without metadata.
73#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, arbitrary::Arbitrary)]
74#[schemars(rename = "functions.InlineTasksProfile")]
75pub struct InlineTasksProfile {
76    /// Configuration for each task in the corresponding Function.
77    pub tasks: Vec<TaskProfile>,
78    /// Optional weights for each Task in the corresponding Function.
79    /// If `None`, uniform weights are used.
80    #[serde(skip_serializing_if = "Option::is_none")]
81    #[schemars(extend("omitempty" = true))]
82    pub weights: Option<crate::Weights>,
83}
84
85/// A remote tasks-based profile with full metadata.
86///
87/// Stored as `profile.json` in repositories and referenced by
88/// `remote/owner/repository`.
89#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
90#[schemars(rename = "functions.RemoteTasksProfile")]
91pub struct RemoteTasksProfile {
92    /// Human-readable description of the profile.
93    pub description: String,
94    #[serde(flatten)]
95    #[schemars(schema_with = "crate::flatten_schema::<InlineTasksProfile>")]
96    pub inner: InlineTasksProfile,
97}
98
99/// Configuration for a single task within a Profile.
100///
101/// Each variant corresponds to a task type in the Function definition.
102#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
103#[serde(untagged)]
104#[schemars(rename = "functions.TaskProfile")]
105pub enum TaskProfile {
106    /// Profile for a nested function task (references another profile).
107    #[schemars(title = "Remote")]
108    Remote(crate::RemotePath),
109    /// Inline profile for a task (tasks-based or auto).
110    #[schemars(title = "Inline")]
111    Inline(InlineProfile),
112    /// Placeholder task — no configuration needed, output is fixed.
113    #[schemars(title = "Placeholder")]
114    Placeholder {},
115}
116
117impl<'a> arbitrary::Arbitrary<'a> for TaskProfile {
118    fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
119        // Inline variant is recursive (InlineProfile → InlineTasksProfile → Vec<TaskProfile>),
120        // so use go-deep bool to make recursion exponentially rare.
121        if u.arbitrary().unwrap_or(false) {
122            Ok(TaskProfile::Inline(u.arbitrary()?))
123        } else if u.arbitrary().unwrap_or(false) {
124            Ok(TaskProfile::Remote(u.arbitrary()?))
125        } else {
126            Ok(TaskProfile::Placeholder {})
127        }
128    }
129}