From 23ab12dbafbc76a2ebddb463ac5bf96bad3d6991 Mon Sep 17 00:00:00 2001 From: Tyler Longwell Date: Wed, 17 Dec 2025 11:21:06 -0500 Subject: [PATCH] subagent cleanup --- crates/goose/src/agents/agent.rs | 4 ++- crates/goose/src/agents/extension.rs | 2 -- crates/goose/src/agents/extension_manager.rs | 1 - crates/goose/src/agents/subagent_client.rs | 35 ++++++++----------- .../goose/src/agents/subagent_task_config.rs | 33 +---------------- crates/goose/src/execution/manager.rs | 1 - crates/goose/tests/agent.rs | 1 - 7 files changed, 19 insertions(+), 58 deletions(-) diff --git a/crates/goose/src/agents/agent.rs b/crates/goose/src/agents/agent.rs index 616416becf..4e6afd5943 100644 --- a/crates/goose/src/agents/agent.rs +++ b/crates/goose/src/agents/agent.rs @@ -264,7 +264,9 @@ impl Agent { let initial_messages = conversation.messages().clone(); let config = Config::global(); - let _ = self.enable_subagent_extension().await; + if let Err(e) = self.enable_subagent_extension().await { + warn!("Failed to enable subagent extension: {}", e); + } let (tools, toolshim_tools, system_prompt) = self.prepare_tools_and_prompt(working_dir).await?; diff --git a/crates/goose/src/agents/extension.rs b/crates/goose/src/agents/extension.rs index 7e409f20b8..83b8a2c3dd 100644 --- a/crates/goose/src/agents/extension.rs +++ b/crates/goose/src/agents/extension.rs @@ -5,7 +5,6 @@ use crate::agents::skills_extension; use crate::agents::subagent_client; use crate::agents::todo_extension; use crate::recipe::SubRecipe; -use crate::session::session_manager::SessionType; use std::collections::HashMap; use std::path::PathBuf; use std::sync::Arc; @@ -127,7 +126,6 @@ pub struct PlatformExtensionContext { Option>, pub tool_route_manager: Option>, - pub session_type: Option, pub working_dir: Option, pub sub_recipes: Option>>>, } diff --git a/crates/goose/src/agents/extension_manager.rs b/crates/goose/src/agents/extension_manager.rs index 085daa0bfb..e061b395d8 100644 --- a/crates/goose/src/agents/extension_manager.rs +++ b/crates/goose/src/agents/extension_manager.rs @@ -262,7 +262,6 @@ impl ExtensionManager { session_id: None, extension_manager: None, tool_route_manager: None, - session_type: None, working_dir: None, sub_recipes: None, }), diff --git a/crates/goose/src/agents/subagent_client.rs b/crates/goose/src/agents/subagent_client.rs index 256e92fff3..278a23e6b5 100644 --- a/crates/goose/src/agents/subagent_client.rs +++ b/crates/goose/src/agents/subagent_client.rs @@ -5,7 +5,6 @@ use crate::agents::subagent_tool::{ create_subagent_tool, handle_subagent_tool, SUBAGENT_TOOL_NAME, }; use crate::config::get_enabled_extensions; -use crate::session::session_manager::SessionType; use anyhow::Result; use async_trait::async_trait; use rmcp::model::{ @@ -56,15 +55,24 @@ impl SubagentClient { }) } - fn is_subagent_session(&self) -> bool { - matches!(self.context.session_type, Some(SessionType::SubAgent)) - } - async fn get_provider(&self) -> Option> { let em = self.context.extension_manager.as_ref()?.upgrade()?; em.get_provider().await } + async fn get_extensions(&self) -> Vec { + if let Some(em) = self + .context + .extension_manager + .as_ref() + .and_then(|w| w.upgrade()) + { + em.get_extension_configs().await + } else { + get_enabled_extensions() + } + } + async fn get_sub_recipes(&self) -> std::collections::HashMap { match &self.context.sub_recipes { Some(recipes) => recipes.read().await.clone(), @@ -109,13 +117,6 @@ impl McpClientTrait for SubagentClient { _next_cursor: Option, _cancellation_token: CancellationToken, ) -> Result { - if self.is_subagent_session() { - return Ok(ListToolsResult { - tools: Vec::new(), - next_cursor: None, - }); - } - Ok(ListToolsResult { tools: vec![self.build_tool().await], next_cursor: None, @@ -135,22 +136,16 @@ impl McpClientTrait for SubagentClient { ))])); } - if self.is_subagent_session() { - return Ok(CallToolResult::error(vec![Content::text( - "Subagents cannot spawn other subagents", - )])); - } - let Some(provider) = self.get_provider().await else { return Ok(CallToolResult::error(vec![Content::text( "No provider configured", )])); }; - let extensions = get_enabled_extensions(); + let extensions = self.get_extensions().await; let working_dir = self.get_working_dir(); let sub_recipes = self.get_sub_recipes().await; - let task_config = TaskConfig::new_minimal(provider, extensions); + let task_config = TaskConfig::new(provider, extensions); let arguments_value = arguments .map(Value::Object) diff --git a/crates/goose/src/agents/subagent_task_config.rs b/crates/goose/src/agents/subagent_task_config.rs index 6437500600..7cdb541458 100644 --- a/crates/goose/src/agents/subagent_task_config.rs +++ b/crates/goose/src/agents/subagent_task_config.rs @@ -2,21 +2,14 @@ use crate::agents::ExtensionConfig; use crate::providers::base::Provider; use std::env; use std::fmt; -use std::path::{Path, PathBuf}; use std::sync::Arc; -/// Default maximum number of turns for task execution pub const DEFAULT_SUBAGENT_MAX_TURNS: usize = 25; - -/// Environment variable name for configuring max turns pub const GOOSE_SUBAGENT_MAX_TURNS_ENV_VAR: &str = "GOOSE_SUBAGENT_MAX_TURNS"; -/// Configuration for task execution with all necessary dependencies #[derive(Clone)] pub struct TaskConfig { pub provider: Arc, - pub parent_session_id: String, - pub parent_working_dir: PathBuf, pub extensions: Vec, pub max_turns: Option, } @@ -25,8 +18,6 @@ impl fmt::Debug for TaskConfig { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("TaskConfig") .field("provider", &"") - .field("parent_session_id", &self.parent_session_id) - .field("parent_working_dir", &self.parent_working_dir) .field("max_turns", &self.max_turns) .field("extensions", &self.extensions) .finish() @@ -34,31 +25,9 @@ impl fmt::Debug for TaskConfig { } impl TaskConfig { - pub fn new( - provider: Arc, - parent_session_id: &str, - parent_working_dir: &Path, - extensions: Vec, - ) -> Self { + pub fn new(provider: Arc, extensions: Vec) -> Self { Self { provider, - parent_session_id: parent_session_id.to_owned(), - parent_working_dir: parent_working_dir.to_owned(), - extensions, - max_turns: Some( - env::var(GOOSE_SUBAGENT_MAX_TURNS_ENV_VAR) - .ok() - .and_then(|val| val.parse::().ok()) - .unwrap_or(DEFAULT_SUBAGENT_MAX_TURNS), - ), - } - } - - pub fn new_minimal(provider: Arc, extensions: Vec) -> Self { - Self { - provider, - parent_session_id: String::new(), - parent_working_dir: PathBuf::new(), extensions, max_turns: Some( env::var(GOOSE_SUBAGENT_MAX_TURNS_ENV_VAR) diff --git a/crates/goose/src/execution/manager.rs b/crates/goose/src/execution/manager.rs index 368ca6ed8e..08ea38aad2 100644 --- a/crates/goose/src/execution/manager.rs +++ b/crates/goose/src/execution/manager.rs @@ -88,7 +88,6 @@ impl AgentManager { session_id: Some(session_id.clone()), extension_manager: Some(Arc::downgrade(&agent.extension_manager)), tool_route_manager: Some(Arc::downgrade(&agent.tool_route_manager)), - session_type: None, working_dir: None, sub_recipes: Some(agent.sub_recipes()), }) diff --git a/crates/goose/tests/agent.rs b/crates/goose/tests/agent.rs index ca68a5c706..285c1dc7d9 100644 --- a/crates/goose/tests/agent.rs +++ b/crates/goose/tests/agent.rs @@ -474,7 +474,6 @@ mod tests { session_id: Some("test_session".to_string()), extension_manager: Some(Arc::downgrade(&agent.extension_manager)), tool_route_manager: Some(Arc::downgrade(&agent.tool_route_manager)), - session_type: None, working_dir: None, sub_recipes: Some(agent.sub_recipes()), })