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
12 changes: 6 additions & 6 deletions crates/goose/src/agents/subagent_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ fn get_agent_messages(
cancellation_token: Option<CancellationToken>,
) -> 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
Expand Down Expand Up @@ -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()
Expand All @@ -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 {
Expand Down
30 changes: 6 additions & 24 deletions crates/goose/src/agents/subagent_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) = &params.instructions {
if !combined.is_empty() {
combined.push_str("\n\n");
if let Some(extra) = &params.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)
Expand Down
2 changes: 2 additions & 0 deletions crates/goose/src/prompts/subagent_system.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down