Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion crates/goose/src/agents/recipe_tools/sub_recipe_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,15 @@ fn create_tasks_from_params(
}

fn create_task_execution_payload(tasks: &[Task], sub_recipe: &SubRecipe) -> Value {
let execution_mode = if tasks.len() == 1 || sub_recipe.sequential_when_repeated {
ExecutionMode::Sequential
} else {
ExecutionMode::Parallel
};
let task_ids: Vec<String> = tasks.iter().map(|task| task.id.clone()).collect();
json!({
"task_ids": task_ids,
"execution_mode": if sub_recipe.sequential_when_repeated { ExecutionMode::Sequential } else { ExecutionMode::Parallel },
"execution_mode": execution_mode,
})
}

Expand Down
13 changes: 1 addition & 12 deletions crates/goose/src/agents/subagent_execution_tool/lib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,7 @@ pub async fn execute_tasks(
)
.map_err(|e| format!("Failed to parse task_ids: {}", e))?;

let mut tasks = Vec::new();
for task_id in &task_ids {
match tasks_manager.get_task(task_id).await {
Some(task) => tasks.push(task),
None => {
return Err(format!(
"Task with ID '{}' not found in TasksManager",
task_id
))
}
}
}
let tasks = tasks_manager.get_tasks(&task_ids).await?;

let task_count = tasks.len();
match execution_mode {
Expand Down
17 changes: 17 additions & 0 deletions crates/goose/src/agents/subagent_execution_tool/tasks_manager.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use anyhow::Result;
use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::RwLock;
Expand Down Expand Up @@ -33,6 +34,22 @@ impl TasksManager {
let tasks = self.tasks.read().await;
tasks.get(task_id).cloned()
}

pub async fn get_tasks(&self, task_ids: &[String]) -> Result<Vec<Task>, String> {
let mut tasks = Vec::new();
for task_id in task_ids {
match self.get_task(task_id).await {
Some(task) => tasks.push(task),
None => {
return Err(format!(
"Task with ID '{}' not found in TasksManager",
task_id
))
}
}
}
Ok(tasks)
}
}

#[cfg(test)]
Expand Down
Loading