From eef0d0fe06c7294934252dd28c74083d947ceea5 Mon Sep 17 00:00:00 2001 From: Tyler Longwell Date: Thu, 18 Dec 2025 14:52:51 -0500 Subject: [PATCH] need to enable the subagent tool whenever subrecipes are specified --- crates/goose-cli/src/session/builder.rs | 2 ++ crates/goose-server/src/routes/recipe_utils.rs | 2 ++ crates/goose/src/agents/agent.rs | 13 +++++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/goose-cli/src/session/builder.rs b/crates/goose-cli/src/session/builder.rs index 01985bdb07..62a9a524ce 100644 --- a/crates/goose-cli/src/session/builder.rs +++ b/crates/goose-cli/src/session/builder.rs @@ -497,6 +497,8 @@ pub async fn build_session(session_config: SessionBuilderConfig) -> CliSession { } } + agent_ptr.ensure_subagent_for_recipes().await; + // Determine editor mode let edit_mode = config .get_param::("EDIT_MODE") diff --git a/crates/goose-server/src/routes/recipe_utils.rs b/crates/goose-server/src/routes/recipe_utils.rs index c1c7f45ca6..a352e4cb43 100644 --- a/crates/goose-server/src/routes/recipe_utils.rs +++ b/crates/goose-server/src/routes/recipe_utils.rs @@ -170,6 +170,8 @@ pub async fn apply_recipe_to_agent( ) .await; + agent.ensure_subagent_for_recipes().await; + recipe.instructions.as_ref().map(|instructions| { let mut context: HashMap<&str, Value> = HashMap::new(); context.insert("recipe_instructions", Value::String(instructions.clone())); diff --git a/crates/goose/src/agents/agent.rs b/crates/goose/src/agents/agent.rs index 58f075cd67..77b86345f9 100644 --- a/crates/goose/src/agents/agent.rs +++ b/crates/goose/src/agents/agent.rs @@ -407,8 +407,8 @@ impl Agent { response: Option, include_final_output: bool, ) { - if let Some(sub_recipes) = sub_recipes { - self.add_sub_recipes(sub_recipes).await; + if let Some(ref sub_recipes) = sub_recipes { + self.add_sub_recipes(sub_recipes.clone()).await; } if include_final_output { @@ -418,6 +418,15 @@ impl Agent { } } + pub async fn ensure_subagent_for_recipes(&self) { + let has_sub_recipes = !self.sub_recipes.read().await.is_empty(); + if has_sub_recipes { + if let Err(e) = self.enable_subagent_extension().await { + warn!("Failed to enable subagent extension for recipe: {}", e); + } + } + } + /// Dispatch a single tool call to the appropriate client #[instrument(skip(self, tool_call, request_id), fields(input, output))] pub async fn dispatch_tool_call(