#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum InventionStep {
EssayScalar,
EssayVector,
InputSchemaScalar,
InputSchemaVector,
EssayTasksScalar,
EssayTasksVector,
TasksScalarLeaf,
TasksScalarBranch,
TasksVectorLeaf,
TasksVectorBranch,
DescriptionScalarLeaf,
DescriptionScalarBranch,
DescriptionVectorLeaf,
DescriptionVectorBranch,
}
impl InventionStep {
pub fn discover(tool_names: &[String], prompt: &str) -> Option<Self> {
let has = |name: &str| tool_names.iter().any(|t| t == name);
if has("oaifi_WriteEssay")
&& !has("oaifi_WriteInputSchema")
{
return Some(if prompt.contains("Scalar Function") {
Self::EssayScalar
} else {
Self::EssayVector
});
}
if has("oaifi_WriteInputSchema") {
return Some(
if has("oaifi_Readfunctions_alpha_vector_expression_VectorFunctionInputSchemaSchema") {
Self::InputSchemaVector
} else {
Self::InputSchemaScalar
},
);
}
if has("oaifi_WriteEssayTasks")
&& !has("oaifi_AppendTask")
{
return Some(Self::EssayTasksScalar);
}
if has("oaifi_AppendTask") {
return Some(if has("oaifi_Readagent_completions_message_MessageExpressionSchema") {
if tool_names.iter().any(|t| t.contains("alpha_scalar")) {
Self::TasksScalarLeaf
} else {
Self::TasksVectorLeaf
}
} else if has("oaifi_Readfunctions_expression_InputValueSchema") {
if tool_names.iter().any(|t| t.contains("alpha_scalar_Placeholder")) {
Self::TasksScalarBranch
} else {
Self::TasksVectorBranch
}
} else {
panic!("AppendTask present but neither leaf nor branch schema tools found. Tool names: {:?}", tool_names);
});
}
if has("oaifi_WriteDescription") {
return Some(Self::DescriptionScalarLeaf);
}
None
}
pub fn refine_with_input_schema(self, input_schema_json: &str) -> Self {
let is_vector = serde_json::from_str::<serde_json::Value>(input_schema_json)
.ok()
.and_then(|v| v.get("items").cloned())
.is_some();
match self {
Self::EssayTasksScalar if is_vector => Self::EssayTasksVector,
Self::DescriptionScalarLeaf if is_vector => Self::DescriptionVectorLeaf,
Self::DescriptionScalarBranch if is_vector => Self::DescriptionVectorBranch,
other => other,
}
}
pub fn refine_with_task(self, task_json: &str) -> Self {
let is_branch = task_json.contains("placeholder");
match self {
Self::DescriptionScalarLeaf if is_branch => Self::DescriptionScalarBranch,
Self::DescriptionVectorLeaf if is_branch => Self::DescriptionVectorBranch,
other => other,
}
}
pub fn needs_input_schema(self) -> bool {
matches!(
self,
Self::EssayTasksScalar
| Self::EssayTasksVector
| Self::TasksScalarLeaf
| Self::TasksScalarBranch
| Self::TasksVectorLeaf
| Self::TasksVectorBranch
| Self::DescriptionScalarLeaf
| Self::DescriptionScalarBranch
| Self::DescriptionVectorLeaf
| Self::DescriptionVectorBranch
)
}
}