diff --git a/crates/goose/src/agents/subagent_handler.rs b/crates/goose/src/agents/subagent_handler.rs index 98e87a524f58..b54d747db199 100644 --- a/crates/goose/src/agents/subagent_handler.rs +++ b/crates/goose/src/agents/subagent_handler.rs @@ -117,11 +117,11 @@ fn get_agent_messages( cancellation_token: Option, ) -> AgentMessagesFuture { Box::pin(async move { - let text_instruction = recipe - .instructions + let system_instructions = recipe.instructions.clone().unwrap_or_default(); + let user_task = recipe + .prompt .clone() - .or(recipe.prompt.clone()) - .ok_or_else(|| anyhow!("Recipe has no instructions or prompt"))?; + .unwrap_or_else(|| "Begin.".to_string()); let agent_manager = AgentManager::instance() .await @@ -160,7 +160,7 @@ fn get_agent_messages( .max_turns .expect("TaskConfig always sets max_turns"), subagent_id: session_id.clone(), - task_instructions: text_instruction.clone(), + task_instructions: system_instructions, tool_count: tools.len(), available_tools: tools .iter() @@ -172,7 +172,7 @@ fn get_agent_messages( .map_err(|e| anyhow!("Failed to render subagent system prompt: {}", e))?; agent.override_system_prompt(subagent_prompt).await; - let user_message = Message::user().with_text(text_instruction); + let user_message = Message::user().with_text(user_task); let mut conversation = Conversation::new_unvalidated(vec![user_message.clone()]); if let Some(activities) = recipe.activities { diff --git a/crates/goose/src/agents/subagent_tool.rs b/crates/goose/src/agents/subagent_tool.rs index c775c070bc15..d5babc333eca 100644 --- a/crates/goose/src/agents/subagent_tool.rs +++ b/crates/goose/src/agents/subagent_tool.rs @@ -348,31 +348,13 @@ fn build_subrecipe( ) .map_err(|e| anyhow!("Failed to build subrecipe: {}", e))?; - // Merge prompt into instructions so the subagent gets the actual task. - // The subagent handler uses `instructions` as the user message. - let mut combined = String::new(); - - if let Some(instructions) = &recipe.instructions { - combined.push_str(instructions); - } - - if let Some(prompt) = &recipe.prompt { - if !combined.is_empty() { - combined.push_str("\n\n"); - } - combined.push_str(prompt); - } - - if let Some(extra_instructions) = ¶ms.instructions { - if !combined.is_empty() { - combined.push_str("\n\n"); + if let Some(extra) = ¶ms.instructions { + let mut current = recipe.instructions.take().unwrap_or_default(); + if !current.is_empty() { + current.push_str("\n\n"); } - combined.push_str("Additional context from parent agent:\n"); - combined.push_str(extra_instructions); - } - - if !combined.is_empty() { - recipe.instructions = Some(combined); + current.push_str(extra); + recipe.instructions = Some(current); } Ok(recipe) diff --git a/crates/goose/src/prompts/subagent_system.md b/crates/goose/src/prompts/subagent_system.md index 35ab938e1be4..2ff619c2cf3e 100644 --- a/crates/goose/src/prompts/subagent_system.md +++ b/crates/goose/src/prompts/subagent_system.md @@ -13,8 +13,10 @@ The maximum number of turns to respond is {{max_turns}}. **Subagent ID**: {{subagent_id}} {% endif %} +{% if task_instructions %} # Task Instructions {{task_instructions}} +{% endif %} # Tool Usage Guidelines **CRITICAL**: Be efficient with tool usage. Use tools only when absolutely necessary to complete your task. Here are the available tools you have access to: