mirror of
https://github.com/aaif-goose/goose.git
synced 2026-07-03 14:10:03 +02:00
subagent cleanup
This commit is contained in:
@@ -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?;
|
||||
|
||||
@@ -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<std::sync::Weak<crate::agents::extension_manager::ExtensionManager>>,
|
||||
pub tool_route_manager:
|
||||
Option<std::sync::Weak<crate::agents::tool_route_manager::ToolRouteManager>>,
|
||||
pub session_type: Option<SessionType>,
|
||||
pub working_dir: Option<PathBuf>,
|
||||
pub sub_recipes: Option<Arc<RwLock<HashMap<String, SubRecipe>>>>,
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}),
|
||||
|
||||
@@ -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<std::sync::Arc<dyn crate::providers::base::Provider>> {
|
||||
let em = self.context.extension_manager.as_ref()?.upgrade()?;
|
||||
em.get_provider().await
|
||||
}
|
||||
|
||||
async fn get_extensions(&self) -> Vec<crate::agents::ExtensionConfig> {
|
||||
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<String, crate::recipe::SubRecipe> {
|
||||
match &self.context.sub_recipes {
|
||||
Some(recipes) => recipes.read().await.clone(),
|
||||
@@ -109,13 +117,6 @@ impl McpClientTrait for SubagentClient {
|
||||
_next_cursor: Option<String>,
|
||||
_cancellation_token: CancellationToken,
|
||||
) -> Result<ListToolsResult, Error> {
|
||||
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)
|
||||
|
||||
@@ -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<dyn Provider>,
|
||||
pub parent_session_id: String,
|
||||
pub parent_working_dir: PathBuf,
|
||||
pub extensions: Vec<ExtensionConfig>,
|
||||
pub max_turns: Option<usize>,
|
||||
}
|
||||
@@ -25,8 +18,6 @@ impl fmt::Debug for TaskConfig {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("TaskConfig")
|
||||
.field("provider", &"<dyn 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<dyn Provider>,
|
||||
parent_session_id: &str,
|
||||
parent_working_dir: &Path,
|
||||
extensions: Vec<ExtensionConfig>,
|
||||
) -> Self {
|
||||
pub fn new(provider: Arc<dyn Provider>, extensions: Vec<ExtensionConfig>) -> 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::<usize>().ok())
|
||||
.unwrap_or(DEFAULT_SUBAGENT_MAX_TURNS),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_minimal(provider: Arc<dyn Provider>, extensions: Vec<ExtensionConfig>) -> 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)
|
||||
|
||||
@@ -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()),
|
||||
})
|
||||
|
||||
@@ -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()),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user